10

I am trying to add a submenu entry to an item from the context menu of the Eclipse Package Explorer.

The menu entry is already defined via org.eclipse.ui.popupMenus in another plugin, not in the one that I am working at. (That plugin is added to the dependencies list of my plugin). There are also items added in its submenu, but also using org.eclipse.ui.popupMenus, and I am trying to do this via org.eclipse.ui.menus.

To begin with, I did the following:

  • I added org.eclipse.ui.commands and org.eclipse.ui.menus extensions.
  • I defined a command , respectively a menuContribution like this:

enter image description here

This adds the item in any context menu... So I would have to replace "org.eclipse.ui.popup.any?after=additions" from the locationURI with the id of the submenu I want my item to appear in.

My problem is: how to determine a correct locationURI? I used the menu spy (ALT+SHIFT+F2) and inspected the submenu I want to contribute to, and I received the following URI:

menu:YYY?after=ZZZ, where:

YYY is the id of the menu that is already defined and to which I want to add the submenu item ZZZ is the id of the action from the submenu, that I clicked upon (using the spy)

I tryied the following, but the submenu item does not appear:

  • menu:YYY[?after=additions]
  • popup:YYY[?after=additions]

Please help :)

catalina
  • 223
  • 2
  • 8
  • have you tried popup:YYYY?after=ZZZ ? – mhussein Sep 27 '12 at 10:38
  • Yes, I have tried that too, and it didn't help. But I have just managed to make it work. I had to define a new menu contribution and a menu having the same id and label as the menu already defined - YYY & YYY's label, like this: With this, and replacing the locationURI with: "popup:YYY?after=additions" now it works. I don't know if this is the right way to do it, but it works. – catalina Sep 27 '12 at 13:23
  • ...and thanks a lot for your interest and for trying to help me :) – catalina Sep 27 '12 at 13:24
  • you are most welcome. I am glad you made it work. btw, you can add an answer yourself and accept it, I guess this is encouraged to make it easier for others to know the answer if they face the same problem – mhussein Sep 27 '12 at 19:14

1 Answers1

11

I managed to make it work by defining a new menu contribution and a menu having the same id and label as the menu already defined. The final solution looks like this:

<extension point="org.eclipse.ui.menus">
  <menuContribution
        locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
     <menu
           id="YYY"
           label="%YYYs_label">
     </menu>
  </menuContribution>
  <menuContribution
        locationURI="popup:YYY?after=additions">
     <command
           commandId="example.MyCommandHandlerID"
           icon="icons/somePhoto.gif"
           label="MyLabel"
           style="push">
     </command>
  </menuContribution>
</extension>
catalina
  • 223
  • 2
  • 8
  • 2
    This is the only workaround. `org.eclipse.ui.menus` contributions are applied before any of the legacy action extensions, like `org.eclipse.ui.actionSets` or `org.eclipse.ui.popupMenus`. – Paul Webster Oct 01 '12 at 14:36
  • the URI for the **Package** Explorer's context menu is `popup:org.eclipse.jdt.ui.PackageExplorer?after=additions` – Brad Mace Jul 18 '14 at 21:27