funap / npp-explorer-plugin

Explorer plugin for Notepad++ x64/x86
GNU General Public License v2.0
86 stars 10 forks source link

FEATURE REQUEST: Keyboard shortcut for context menu #70

Closed vinsworldcom closed 10 months ago

vinsworldcom commented 11 months ago

Is your feature request related to a problem? Please describe. Currently, pressing the Enter key in the Explorer view will open a folder or open the file selected in Notepad++. It would be nice to add a modifier (CTRL or ALT) when pressing the Enter key to get the context menu to popup. This would allow mouse-free navigation of most all of the plugin features.

Describe the solution you'd like I'd like to use CTRL+Enter or ALT+Enter on a folder or file in the Explorer dockable to activate the popup context menu and let the existing Enter key by itself still function how it normally does.

Describe alternatives you've considered I tried pressing the menu key on a 101-key keyboard but that does not seem to function in the Explorer view.

Cheers.

funap commented 11 months ago

Thanks for the suggestion. : ) I like too your suggested CTRL+Enter because it is easy to type. I'd also like to include support for general key bindings like VK_APPS and Shift+F10. (My keyboard doesn't have a menu key... I think VK_APPS is notified when the menu key is pressed.)

funap commented 11 months ago

The method of handling it with VK_APPS seems straightforward. Please give me some time to consider the others.

    case WM_KEYDOWN:
   {
            if (VK_APPS == wParam) {
                HTREEITEM hItem = TreeView_GetSelection(_hTreeCtrl);
                if (hItem != nullptr) {
                    RECT rect;
                    TreeView_GetItemRect(_hTreeCtrl, hItem, &rect, TRUE);
                    ClientToScreen(_hTreeCtrl, &rect);
                    POINT pt{
                        .x = rect.right,
                        .y = rect.top,
                    };

                    ContextMenu cm;
                    auto strPathName = GetFolderPathName(hItem);
                    cm.SetObjects(strPathName);
                    cm.ShowContextMenu(_hInst, _hParent, _hSelf, pt);
                }
                return TRUE;
            }
            :
vinsworldcom commented 11 months ago

Yes, certainly - take you time. Also happy to do some testing for you if needed.

My hope is that using something like CTRL+Enter would not interfere with having Notepad++ bind that key to something else. Hopefully, you can just detect keypresses when the Explorer dockable is the active focus window - like with those WM_KEYDOWN notifications.

Cheers.

funap commented 11 months ago

This is a test app. Please try it if you feel like it. Explorer_x64.zip Explorer_x86.zip

vinsworldcom commented 11 months ago

Nicely done! The menu key (VK_APPS) now works if Explorer has the focus. If Notepad++ has focus menu key (VK_APPS) still works as expected pulling up Notepad++ context menu!

The Shift+F10 works too, but I think only because I don't have it mapped as a Notepad++ shortcut. If I map it to a Notepad++ shortcut, then the Notepad++ shortcut triggers instead. I tried this because I already have CTRL+Enter mapped to a Notepad++ shortcut and pressing CTRL+Enter even when Explorer dockable has the focus triggers the Notepad++ shortcut, not the Explorer context menu.

Not sure if that's something you can fix or if Notepad++ is adding it's shortcuts with some keyboard hook that intercepts them before the plugins get them. I've had this type of issue in some of my plugins - trying to set a "hotkey combo" that is already mapped as a Notepad++ shortcut and Notepad++ "intercepts" it.

In any case, the menu key (VK_APPS) works for me - so that is some keyboard control (no mouse required) - so I'm happy!

Cheers.