Is it possible to extend Eclipse Search Menu

2019-02-18 02:16发布

问题:

right now in eclipse it is not possible to extend Menu defined by Other plugins by using eclipse extension: org.eclipse.ui.menus.

I want to add one menu item in Search but not a search page. since the Menu Search is defined by org.eclipse.search, I cannot add it.

but I see JDT and CDT do add some menu item under search. does any body know how they make it work?

any hint is appreciated.

回答1:

You can extend menus from other plugins using org.eclipse.ui.actionSets extension point

This is how the JDT does to extend the search menu with its own action. In order to have the action in a given menu you'll have to fill the menubarPath value. For example the JDT for the Java search action filled it with:

org.eclipse.search.menu/dialogGroup

I suggest to import the JDT UI sources and to look at the JDT plugin.xml file. FOr that you will need a classic Eclipse SDK and then in the plugins view right click on the org.eclipse.jdt.ui plugin and select import as source.



回答2:

As long as you know the ID of the menu or toolbar, you can extend these using the org.eclipse.ui.menus extension point. For the search menu, this ID is org.eclipse.search.menu. If you want to add stuff to the dialogGroup then use org.eclipse.search.menu?after=dialogGroup.



回答3:

Update August 2012, as commented by reprogrammer, org.eclipse.ui.actionSets is deprecated:

Instead, use the extension point org.eclipse.ui.commands.


Original answer (August 2011)

The actionSet (extension point="org.eclipse.ui.actionSets") with an action on 'menubarPath="org.eclipse.search.menu/dialogGroup"' recommended by Manuel Selva is the official solution, in line with general menu contribution.

But beware of some issue that might still lingering for Search menu contribution, as illustrated by this thread around the (supposedly fixed) bug 15684:
(it was in 2009, hopefully the issue has been addressed since)

What actually does work is redefining the whole Search Menu as in the workaround that is still currently used in JDT 3.6:

   <extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            label="%JavaSearchActionSet.label"
            description="%JavaSearchActionSet.description"
            visible="false"
            id="org.eclipse.jdt.ui.SearchActionSet">
<!-- see http://bugs.eclipse.org/bugs/show_bug.cgi?id=15684    -->
<!-- Note: The menu (re-) definition has to be here due to bug: -->
<!-- =================================================================== -->
<!-- Search Menu                                                         -->
<!-- =================================================================== -->
         <menu
               label="%searchMenu.label"
               path="navigate"
               id="org.eclipse.search.menu">
                <groupMarker name="internalDialogGroup"/>   <!-- not to be used by clients  -->
                <groupMarker name="dialogGroup"/>           <!-- to be used by clients      -->
                <separator name="fileSearchContextMenuActionsGroup"/> <!-- to be used by clients      -->
                <separator name="contextMenuActionsGroup"/> <!-- to be used by clients -->
                <separator name="occurencesActionsGroup"/> <!-- to be used by clients -->
                <separator name="extraSearchGroup"/> <!-- to be used by clients -->
         </menu>
<!-- (...) -->