Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Context Menu Trigger
#1
I want to implement a context menu trigger that appears in File Explorer. Specifically: when I select two folders and right-click, a specific menu item should be displayed. Clicking this menu item will pass the paths of the two folders as parameters to a specified LA script file.
(Note: this menu item should not be shown when only one folder is selected.)
Is there a simple and reliable way to achieve this?
Thanks in advance for any suggestions and help.
#2
In file `Window triggers`

Code:
Copy      Help
        Triggers.Window[TWEvent.Visible, "", "#32768", "explorer.exe"] = t => {
            if (wnd.findAll("", "#32768", "explorer.exe").Length > 1) return; //submenu
            
            var m = new popupMenu("d914e490-6ce6-4319-b979-cf0de0322f43");
            
            var wExplorer = wnd.active;
            if (ExplorerFolder.Of(wExplorer) is { } e && e.GetSelectedItems() is { Length: 2 } sel && filesystem.exists(sel[0]).Directory && filesystem.exists(sel[1]).Directory) {
                m["2 folders"] = o => {
                    keys.send("Esc"); //close the Explorer's menu
                    script.run("2 folders", sel[0], sel[1]);
                };
            }

            
            if (!m.Items.Any()) return;
            
            var wMenu = t.Window;
            m.Show(PMFlags.AlignRight, excludeRect: wMenu.Rect, owner: wMenu);
        };
#3
Thanks for your help!
This approach is truly elegant and doesn’t require modifying the shell menu.

 How can the following code be made compatible with selecting the folders on the desktop?
 
Code:
Copy      Help
// class "Window triggers.cs"
using Au.Triggers;

partial class Program
{
    [
Triggers]
    void WindowTriggers()
    {

        Triggers.Options.ThreadNew();
        
        if (true)
        {

            Triggers.Window[TWEvent.Visible, "", "#32768", "explorer.exe"] = t =>
            {
                if (wnd.findAll("", "#32768", "explorer.exe").Length > 1) return; //submenu
                
                var m = new popupMenu("d914e490-6ce6-4319-b979-cf0de0322f43");
                
                var wExplorer = wnd.active;
                if (ExplorerFolder.Of(wExplorer) is { } e && e.GetSelectedItems() is { Length: 2 } sel && filesystem.exists(sel[0]).Directory && filesystem.exists(sel[1]).Directory)
                {

                    m["2 folders"] = o =>
                    {
                        keys.send("Esc"); //close the Explorer's menu
                        script.run("2 folders", sel[0], sel[1]);
                    };
                }

                
                if (!m.Items.Any()) return;
                
                var wMenu = t.Window;
                m.Show(PMFlags.AlignRight, excludeRect: wMenu.Rect, owner: wMenu);
            };
        }
        
    }
}


How can the menu be displayed as close as possible to the mouse cursor (next to the original right-click menu)?
In many cases, the new menu appears on the left side of the original right-click menu, far away from the mouse cursor and requiring extra mouse movement, as shown in the image below.
https://i.ibb.co/TxDVS3G6/pic.png
#4
From desktop can't use `ExplorerFolder`. Alternative - let the script get paths via the clipboard.

---
I added the flag because in most cases the shell context menu is on the right from the mouse. If need such fast access, then maybe a hotkey would be better.


Forum Jump:


Users browsing this thread: 1 Guest(s)