Menu

Context Menu and External Tools

2006-12-03
2012-11-13
  • Nobody/Anonymous

    Dear all,
    I am not an experienced user of Notepad++ v3.9. How can I insert a command in the context menu that runs an external tool.

    I know how to customize the context menu and I can start my external tool with a shortcut. But I cannot find the "item id" for the external tool so that I can customize the context menu accordingly. Where can I find the IDs for running my external tools?

    Thanks for help in advance,
    Sven

     
    • Nobody/Anonymous

      Although this is undocumented, it has worked for me this morning.

      In the source code file ".\npp.3.9.src\PowerEditor\src\resource.h" there is a definition:

      #define ID_USER_CMD 21000
      #define ID_USER_CMD_LIMIT 21200

      This shows where the "Item id" numbers start for the user defined shortcuts.
      I added these lines to "%APPDATA%\Notepad++\contextMenu.xml" to correspond to the first and second user-defined shortcut commands (shown below in shortcuts.xml):

      <Item id="21000"/>
      <Item id="21001"/>

      I added the following to "%APPDATA%\Notepad++\shortcuts.xml":

      <UserDefinedCommands>
      <Command name="open selected text in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;$(CURRENT_WORD)&quot;</Command>
      <Command name="search selected text in Google" Ctrl="yes" Alt="yes" Shift="yes" Key="90">firefox &quot;http://www.google.com/search?q=$(CURRENT_WORD)&quot;</Command>
      </UserDefinedCommands>

      So, when I right-click, I can see "open selected text in Firefox" and "search selected text in Google" as context menu items.  If I select some text that forms a hyperlink (like http://sourceforge.net\) and right-click/select "open selected text in Firefox," it opens Firefox to Sourceforge.  If I select some text and then right-click/select "search selected text in Google" it opens up Firefox to Google.com using the highlighted text as the search term.

      This may work for plugins and macros as well, but I haven't tried yet.  From ".\npp.3.9.src\PowerEditor\src\resource.h"

      #define ID_MACRO 20000
      #define ID_MACRO_LIMIT 20200
      ...
      #define ID_PLUGINS_CMD 22000
      #define ID_PLUGINS_CMD_LIMIT 22500

      Start with <Item id="20000"/> for macros, <Item id="21000"/> for shortcuts, and <Item id="22000"/> for plugins.

      !!!!!!!!!!
      Remember, this is completely undocumented hackery and might stop working on a future release (or cause other weird effects, I don't know).  Your mileage may vary, use with caution, etc.
      !!!!!!!!!!

       
      • Nobody/Anonymous

        A special follow-up:  Some formatting got changed by the text editor here on the forum which might make a difference in how this works.

        Above, where it shows:

        <UserDefinedCommands>
        <Command name="open selected text in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox "$(CURRENT_WORD)"</Command>
        <Command name="search selected text in Google" Ctrl="yes" Alt="yes" Shift="yes" Key="90">firefox "http://www.google.com/search?q=$(CURRENT_WORD)"</Command>
        </UserDefinedCommands>

        There is a formatting change that needs to be noticed.  It should actually show this:
        <pre><Command name="open selected text in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;$(CURRENT_WORD)&quot;</Command>
        <Command name="search selected text in Google" Ctrl="yes" Alt="yes" Shift="yes" Key="90">firefox &quot;http://www.google.com/search?q=$(CURRENT_WORD)&quot;</Command></pre>

        Hope that worked.

         
        • Nobody/Anonymous

          Anyway, one thing to note is if you highlight text that contains certain characters, like quotation marks or ampersands, the parsing will do funny things and you may not get the exact string passed that you thought you would.  For example if I try to highlight some text that says...

          Command name="search selected text in Google"

          ...{Command name=search} will be entered as the google search term and firefox will try to open selected.com, text.com, in.com and google.com.