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.
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.
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
.
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>
<!-- (...) -->
精彩评论