Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
#1 Posted : Thursday, October 17, 2019 5:42:58 PM(UTC)

Rank: Administration


Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,372
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 425 time(s) in 360 post(s)
This script will create a popup menu containing all active global actions, and all applications and their actions.

You can then click the menu item to execute the action's script.

This script is a good example of some of the things you can do with the internal configuration of, plus is handy if you often forget which gesture/modifier combination is assigned to an infrequently used action. It lists the action's name followed by the gesture name and any modifiers in brackets - For example: "Maximize or Restore - / Up [C]" where "/ Up" is the gesture name and "[C]" means it uses the Control key as a modifier. If the action is tied to the secondary stroke button, "{S}" will be appended before the gesture name. You can customize the formatting of these extra text descriptions as you like, but they're included here as a starting point.

This script requires or greater.

It should be noted that any actions which reference the "action" object may not work correctly, since the selected menu item's script is executed in a script engine pool. So if it doesn't run in the same engine which created the menu, the "action" object may either not exist, or be whatever the previous action object contained in the retrieved script engine. Most of the time, this should not be an issue since the menu's action has completed and released the engine and the next script will probably get the same engine again; but I wanted to mention it.

var popupMenuInfoEx = new PopupMenuInfoEx(sp.GetCurrentMousePoint());

var applications = sp_config.Applications.Where(a => a.Active).OrderBy("Description").ToList();
applications.Insert(0, sp_config.GlobalApplication); //Insert Global app at the top of the app list
//applications[0].Description = "Global Actions"; //Rename Global app if naming conflict with defined app having name "Global"
for (var i = 0; i < applications.Count;i++) {
    //Get the active actions for the current app, sorted by Category, then Description
    var appActions = applications.Where(x => x.Description == applications[i].Description).First().Actions.Where(a => a.Active).OrderByMultiple("Category|0,Description|0").ToList();
    if(appActions.Count > 0) {
        var catCount = appActions.Distinct("Category").Count();
        var mnuApp = new PopupMenuItem(applications[i].Description);
        currentCategory = "";
        for (var j = 0; j < appActions.Count; j++) {
            var desc = appActions[j].Description;
            //Build out the gesture name, button, and modifiers
            desc += ' - ' 
                    + (appActions[j].UseSecondaryStrokeButton ? '{S} ' : '')
                    + appActions[j].GestureName 
                    + (appActions[j].Left ? ' [L]' : '')  + (appActions[j].Middle ? ' [M]' : '') + (appActions[j].Right ? ' [R]' : '')
                    + (appActions[j].Control ? ' [C]' : '') + (appActions[j].Alt ? ' [A]' : '') + (appActions[j].Shift ? ' [S]' : '')
                    + (appActions[j].WheelDown ? ' [WD]' : '') + (appActions[j].WheelUp ? ' [WU]' : '');
            var script = appActions[j].Script;

            if(catCount > 1) {
                //more than one category exists, so use submenus for each category
                if(currentCategory != appActions[j].Category) {
                    //New category (or first time through loop)
                    if(currentCategory != "") {
                        //If this isn't the first pass through the loop, add the submenu to the app's menu
                        //This would be the complete submenu from the previous category
                    currentCategory = appActions[j].Category; 
                    //Create a new submenu for this category
                    categoryMenu = new PopupMenuItem(currentCategory);
                //Add the menu item for the action
                categoryMenu.SubMenuItems.Add(new PopupMenuItem(desc, script));

                //If this is the last action in the loop, consider the category menu complete and add to app's menu
                if(j == appActions.Count - 1) {
            } else {
                //Only one category exists, so just put them all in the app's menu
                mnuApp.SubMenuItems.Add(new PopupMenuItem(desc, script));
        //Add the app's menu to the popup menu
//Add spacer and close menu option
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("-"));
popupMenuInfoEx.MenuItems.Add(new PopupMenuItem("Close Menu", ""));

Example Output:

Edited by user Thursday, October 17, 2019 8:01:23 PM(UTC)  | Reason: Not specified

thanks 5 users thanked Rob for this useful post.
liuchina on 10/18/2019(UTC), Yuichi on 10/18/2019(UTC), james200410 on 10/27/2019(UTC), Ola Boga on 12/4/2021(UTC), enfantreble on 5/28/2022(UTC)
#2 Posted : Thursday, October 15, 2020 10:24:20 PM(UTC)

Rank: Member


Groups: Approved
Joined: 8/8/2020(UTC)
Posts: 12

Thanks: 1 times
Very useful, thank you.
#3 Posted : Tuesday, December 26, 2023 4:57:56 AM(UTC)

Rank: Newbie


Groups: Approved
Joined: 2/11/2023(UTC)
Posts: 7

There is a problem, when I execute this script and pop up the menu, I press the ESC key or click another place, this menu will not automatically exit, must select a command or close the menu to exit, can you improve, press the ESC key or click other places this menu automatically exit
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.