Open With submenus/groups?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
WirlyWirly
Posts: 260
Joined: 21 Oct 2020 23:33
Location: Win 10 @ 100% (3440x1440)

Open With submenus/groups?

Post by WirlyWirly »

Hello, I've been trying to figure out a way to get submenus in the 'Open with...' context menu (ctrl+alt+enter), like in the screenshot below...

Image

I use a program called 'FileMenu Tools' that lets you add custom programs and shortcuts to the right-click context menu of explorer. Because these are added to the explorer registry, they appear and work as expected on xyplorer. However, because you need to add them to the registry, they're by no means portable. This is fine for a personal computers, but I'd like to take advantage of the portability xyplorer offers in order to have these options everywhere I go.

So far, the only place I've found that lets me add shortcuts in a similar manner is the 'Open with...' menu. Here's the code I have so far in 'Tools/Customize File Associations'...

Code: Select all

+|"1] GitBash"\;*><xypath>..\..\GitPortable\Wrapper-GitBashPortable.exe
+|"2] Vim"\;*><xypath>..\..\GitPortable\Wrapper-Vim.exe
+|"3] Notepad++"\;*>"<xypath>..\..\NotePad++Portable\NotePad++Portable.exe"
+|"4] OniVim"\;*><xypath>..\..\OniVim2\oni2_editor.exe
+|"5] VSCode"\;*><xypath>..\..\VisualStudioCode\Wrapper-VSCode.exe
+|"6] MPC-BE"\;*;><xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe
+|"7] MediaInfo"\;*><xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe
+|"8] BulkRename Utility"\;*><xypath>..\..\Bulk Rename Utility\Bulk Rename Utility.exe
+|"0] General"\;*>
+-
+"AutoHotKey";ahk><xypath>..\..\AutoHotkeyPortable\AutoHotkeyPortable.exe
+"PDF-XChange";pdf><xypath>..\..\PDF-XChangeEditorPortable\PDF-XChangeEditorPortable.exe
+"7-Zip";{:Archive};7z;cbz;cbr><xypath>..\..\7-ZipPortable\7-ZipPortable.exe
+"MPC-BE";{:Media}><xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe
+"Vim";{:Text}><xypath>..\..\GitPortable\Wrapper-Vim.exe
Which looks like this in the 'Open with...' menu...
Image

I don't use my mouse, and only switch focus between the two panes, so keyboard shortcuts are how I need to access this menu. Any ideas?

P.S
I'm also trying to figure out how I can launch a program using the 'Open with...' and not pass any arguments (So that the program is launched vanilla).

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open With submenus/groups?

Post by highend »

In the exact same way as in your screenshot?
Not possible.

But why don't you load a script for an entry like "0) General" that uses popupnested() to display a hierarchical menu with the necessary entries instead?

E.g. with a menu like that:

Code: Select all

    $menu = <<<>>>
        1) Scripts
            2. Script - Rename me|::load "BetterFileSelector.xys";|:rename
            3. Textmaker|::run """D:\Tools\Notepad++_x64\notepad++.exe""";|D:\Tools\Notepad++_x64\notepad++.exe

        Copy Path|#101;|:copypath
    >>>;

Which would lead to something like this:
3.png
3.png (4.39 KiB) Viewed 2523 times
1.png
1.png (4.61 KiB) Viewed 2524 times
2.png
2.png (4.81 KiB) Viewed 2524 times

Ok, this would require some additional work to parse the necessary items to proceed (or none e.g. by holding shift while clicking a context menu entry) but it's still your best option...
One of my scripts helped you out? Please donate via Paypal

WirlyWirly
Posts: 260
Joined: 21 Oct 2020 23:33
Location: Win 10 @ 100% (3440x1440)

Re: Open With submenus/groups?

Post by WirlyWirly »

Thanks for the guidance @highend! I read the docs on popupnested() and after some trial and error, I wrote a small script that fits my initial needs. I am no longer using the 'Open with...' menu, instead I'm loading this script using a keyboard shortcut...

Image

Code: Select all

/*
A customized context menu for accessing common shortcuts/programs/folders

1 space per submenu
DISPLAY;DATA;ICON;STATE

*/

       $menu = <<<MENU
F) Favorites;;
 This PC;goto "%computer%";"%computer%"
 Downloads;goto "%userreal%\Downloads\";"%userreal%\Downloads\"
 PortableApps;goto "<xypath>..\..\";"<xypath>..\..\"
 User;goto "%user%";"%user%"
 GitBash;goto "<xypath>..\..\GitPortable\data\home\";"<xypath>..\..\GitPortable\data\home\"
 Rainmeter;goto "<xypath>..\..\Rainmeter\skins\";"<xypath>..\..\Rainmeter\skins\"
 Vim-Like;goto "<xypath>..\..\_programs_\AutoHotKey\Vim-Like\";"<xypath>..\..\_programs_\AutoHotKey\Vim-Like\"

1) Open in GitBash;run "<xypath>..\..\GitPortable\Wrapper-GitBashPortable.exe" <selitems>;"<xypath>..\..\GitPortable\Wrapper-GitBashPortable.exe"
2) Open in Vim;run "<xypath>..\..\GitPortable\Wrapper-Vim.exe" <selitems>;"<xypath>..\..\GitPortable\Wrapper-Vim.exe"
3) Open in Notepad++;run "<xypath>..\..\Notepad++Portable\Notepad++Portable.exe" <selitems>;"<xypath>..\..\Notepad++Portable\Notepad++Portable.exe"
4) Open in OniVim;run "<xypath>..\..\OniVim2\Oni2_editor.exe" <selitems>;"<xypath>..\..\OniVim2\Oni2_editor.exe"
5) Open in VSCode;run "<xypath>..\..\VisualStudioCode\Wrapper-VSCode.exe" <selitems>;"<xypath>..\..\VisualStudioCode\Wrapper-VSCode.exe"
6) Open in MPC-BE;run "<xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe" <selitems>;"<xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe"
7) Open in MediaInfo;run "<xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe" <selitems>;"<xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe"
8) Open in BulkRename Utility;run "<xypath>..\..\Bulk Rename Utility\Bulk Rename Utility.exe" <selitems>;"<xypath>..\..\Bulk Rename Utility\Bulk Rename Utility.exe"
0) General;;"<xypath>\data\icons\general.ico"
 1) Scripts;;"<xypath>\data\icons\scripts.ico"
  MangaAI: Organize;run "<xypath>..\..\_programs_\Command\WinPython\WinPython Interpreter.exe" "<xypath>..\..\_programs_\Command\MangAI\organize.py" <selitems>;"<xypath>\data\icons\python.ico"
  MangaAI: Kobo;run "<xypath>..\..\_programs_\Command\WinPython\WinPython Interpreter.exe" "<xypath>..\..\_programs_\Command\MangAI\kobo.py" <selitems>;"<xypath>\data\icons\python.ico"
 2) PortableApps;run "<xypath>..\..\..\Start.exe";"<xypath>..\..\..\Start.exe"
MENU;

       $command = popupnested($menu);
       if ($command != '') {$command};
After getting what I wanted to work, I decided to try taking it a step further and also add my favorite folders to the menu (So that I have access to everything in a single place). Right now I'm just trying to work out 2 issues...

1) Getting a variable to run as a literal command: popupnested() returns the data as a string (I believe), so I'm looking for some kind of execute_string_as_command($command) function that will perform the string as a literal command. Before trying to add my favorite folders, I could simply use run $command and it would work fine. However, because folders require the goto command, I need to be able to differentiate which command should be used. If I can't run a string as a literal command, I think my best bet is to put a placeholder in the front of the data, parse that placeholder, and then run the appropriate command based on the results (either 'run' or 'goto') .

2) Getting the menu to pop-up above the selected item or alternatively at the corner of the window, NOT under the cursor: My cursor is usually hidden along the edge of my screen, a not very practical location, so having to scan for it is a little annoying. The docs say popupnested() is nearly identical to popupmenu() (which accepts x/y arguments), but I can't get it to work. I would definitely prefer the menu appearing above the selected item, but a fixed location in the window is fine too.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open With submenus/groups?

Post by highend »

Instead of:
if ($command != '') {$command};
if ($command != '') { load $command, , "s"; }
(which accepts x/y arguments), but I can't get it to work.
There are different options, e.g. controlposition()
to open it at a specific gui element (after splitting the return value)...

Btw, you should not split your parts in each line of your menu entries via ";", if any of your paths or selected files contains one ";", everything would break...
One of my scripts helped you out? Please donate via Paypal

WirlyWirly
Posts: 260
Joined: 21 Oct 2020 23:33
Location: Win 10 @ 100% (3440x1440)

Re: Open With submenus/groups?

Post by WirlyWirly »

Thanks again @highend, looks like I got just about everything working how I had visioned; A custom menu that is easily accessed (hotkey), organized, and flexible...

Image

Code: Select all

/*
A customized context menu for accessing common shortcuts/programs/folders

1 space per submenu
DISPLAY|DATA (return value)|ICON|STATE

*/

       $menu = <<<MENU
0) Favorites||<xypath>\data\icons\favorite_folders.ico
 1) This PC|goto '"%computer%"'|"%computer%"
 2) Downloads|goto '"%userreal%\Downloads\"'|"%userreal%\Downloads\"
 3) PortableApps|goto '"<xypath>..\..\"'|"<xypath>..\..\"
 4) User|goto '"%user%"'|"%user%"
 5) GitBash|goto '"<xypath>..\..\GitPortable\data\home\"'|"<xypath>..\..\GitPortable\data\home\"
 6) Rainmeter|goto '"<xypath>..\..\Rainmeter\skins\"'|"<xypath>..\..\Rainmeter\skins\"
 7) Vim-Like|goto '"<xypath>..\..\_programs_\AutoHotKey\Vim-Like\"'|"<xypath>..\..\_programs_\AutoHotKey\Vim-Like\"

1) Open in GitBash|run '"<xypath>..\..\GitPortable\Wrapper-GitBashPortable.exe" <selitems>'|"<xypath>..\..\GitPortable\Wrapper-GitBashPortable.exe"
2) Open in Vim|run '"<xypath>..\..\GitPortable\Wrapper-Vim.exe" <selitems>'|"<xypath>..\..\GitPortable\Wrapper-Vim.exe"
3) Open in Notepad++|run '"<xypath>..\..\Notepad++Portable\Notepad++Portable.exe" <selitems>'|"<xypath>..\..\Notepad++Portable\Notepad++Portable.exe"
4) Open in OniVim|run '"<xypath>..\..\OniVim2\Oni2_editor.exe" <selitems>'|"<xypath>..\..\OniVim2\Oni2_editor.exe"
5) Open in VSCode|run '"<xypath>..\..\VisualStudioCode\Wrapper-VSCode.exe" <selitems>'|"<xypath>..\..\VisualStudioCode\Wrapper-VSCode.exe"
6) Open in MPC-BE|run '"<xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe" <selitems>'|"<xypath>..\..\MPC-BEPortable\MPC-BEPortable.exe"
7) Open in MediaInfo|run '"<xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe" <selitems>'|"<xypath>..\..\MediaInfoPortable\MediaInfoPortable.exe"
8) Open in BulkRename Utility|run '"<xypath>..\..\Bulk Rename Utility\Bulk Rename Utility.exe" <selitems>'|"<xypath>..\..\Bulk Rename Utility\Bulk Rename Utility.exe"
9) General||"<xypath>\data\icons\general.ico"
 0) Scripts||"<xypath>\data\icons\scripts.ico"
  MangaAI: Organize|run '"<xypath>..\..\_programs_\Command\WinPython\WinPython Interpreter.exe" "<xypath>..\..\_programs_\Command\MangAI\organize.py" <selitems>'|"<xypath>\data\icons\python.ico"
  MangaAI: Kobo|run '"<xypath>..\..\_programs_\Command\WinPython\WinPython Interpreter.exe" "<xypath>..\..\_programs_\Command\MangAI\kobo.py" <selitems>'|"<xypath>\data\icons\python.ico"
 1) PortableApps|run '"<xypath>..\..\..\Start.exe"'|"<xypath>..\..\..\Start.exe"
 2) ShareX|run '"<xypath>..\..\Sharex\Sharex.exe"'|"<xypath>..\..\Sharex\Sharex.exe"
 3) IcoFX|run '"<xypath>..\..\IcoFXPortable\IcoFXPortable.exe"'|"<xypath>..\..\IcoFXPortable\IcoFXPortable.exe"
 4) Rainmeter|run '"<xypath>..\..\Rainmeter\Rainmeter.exe"'|"<xypath>..\..\Rainmeter\Rainmeter.exe"
Start Vim-Like|run '"<xypath>..\..\AutoHotkeyPortable\AutoHotkeyPortable.exe" "<xypath>..\..\_programs_\AutoHotKey\Vim-Like\Vim-Like.ahk"'|"<xypath>..\..\_programs_\AutoHotKey\Vim-Like\icon_active.ico"
MENU;

       /* Get X/Y position of a control */
       $position = controlposition('T', 0);
       $x_pos = gettoken($position, 1, '|');
       $y_pos = gettoken($position, 2, '|');

       /* Display the context menu */
       $command = popupnested($menu, $x_pos, $y_pos,,,,,|);

       /* Run the selected command */
       if ($command != '') { load $command,, s; }
I didn't get the menu to appear under the currently selected item in the list, however the tree will do for now. Thanks again for the help, and if anyone is interested in doing something similar in the future I hope this helps!

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Open With submenus/groups?

Post by highend »

To add additional functionality (start entries like defined on normal left click but start them without <selitems> when the shift key is hold when clicked):

Code: Select all

    $command = trim(popupnested($menu, 7:="|"));
    if ($command) {
        // Remove <selitems> when holding the shift key
        if (get("trigger", "menushift") == 1 && strpos($command, '" "') != -1) {
            $remove  = gettoken($command, 2, '" "', "t", 2);
            $command = regexreplace(replace($command, $remove), "[ ]+?[""]$", chr(39));
        }
        load $command, , "s";
    }
Btw, regarding your icon parts for each line: You don't need surrounding double quotes there (even if they contain spaces), XY resolves that for you...
One of my scripts helped you out? Please donate via Paypal

Post Reply