Is it possible to extend Eclipse Search Menu
Asked Answered
L

3

4

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.

Lamppost answered 4/8, 2011 at 6:54 Comment(1)
In Eclipse everything is possible :-)Glittery
H
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.

Haroun answered 4/8, 2011 at 7:18 Comment(1)
It's been stated elsewhere, but just for clarity, org.eclipse.ui.actionSets has been deprecated.Dramatic
S
1

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>
<!-- (...) -->
Splotch answered 4/8, 2011 at 7:39 Comment(6)
great , thanks for your answer, but how I can control the visibility of my menu item like the menuitem 'C++', "Java" under Search. I try the 'visibility' element in the action , but it does not work.Lamppost
@VonC: The extension point org.eclipse.ui.actionSets is now deprecated. See help.eclipse.org/juno/…Dissertation
@VonC: Using the org.eclipse.ui.menu extension point for adding an item to an old menu that is contributed via actionSets is not straightforward. See my comments at #6937822 and #7941778 If you know how to use the new extension points for adding an item to an old menu like JDT Refactor or Search, please update your answer.Dissertation
@Dissertation I have seen your comment and had no direct solution. That would be best addressed in a new question.Splotch
@VonC: Fortunately, someone else has already asked the question: https://mcmap.net/q/1381340/-adding-menu-item-in-eclipse/130224Dissertation
@reprogrammer: Unfortunately, the only answer is currently sitting at -1 and it isn't clear what the proper course of action is.Dramatic
S
1

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.

Sharmainesharman answered 4/8, 2011 at 9:28 Comment(2)
thanks, I redefine the Search menu following the JDT solution, now my menu item is shown under the Search .Lamppost
@Tonny Madsen: I like the idea of using the extension point org.eclipse.ui.menus as opposed to org.eclipse.ui.actionSets because the latter is deprecated (help.eclipse.org/juno/…). However, adding a menu item to a menu defined using actionSets seems a bit a different and the standard method that you suggested doesn't work for this purpose.Dissertation

© 2022 - 2024 — McMap. All rights reserved.