How to I add an item to *all* Source-menus in an Eclipse-plugin?

385 Views Asked by At

I am developing a plugin for Eclipse Luna using the SDK version 4.4.2. I would like to add a command to all instances of the Source menu (on the menu bar, in the context-menu, and in the popup resulting from Alt-Shift-S. The following code successfully adds the item to the context-menu:

 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
    <extension point="org.eclipse.ui.commands">
        <command id="org.foobar.runMyCommand"
             name="Run My Command...">
         </command>
     </extension>

     <extension point="org.eclipse.ui.menus">
        <menuContribution locationURI="popup:org.eclipse.jdt.ui.source.menu?endof=codeGroup">
            <command commandId="org.foobar.runMyCommand" label="Run My Command...">
            </command>
        </menuContribution>
     </extension>

     <extension point="org.eclipse.ui.handlers">
         <handler commandId="org.foobar.runMyCommand"
             class="org.foobar.MyPlugin">
         </handler>
     </extension>
 </plugin>

The item is, however, missing from both the Source-menu from the menu-bar and the Source-popup which one gets with Alt-Shift-S. How does one add this item to the remaining two menus?

1

There are 1 best solutions below

1
On

You can either use org.eclipse.popupmenus by creating an object contribution, then an action where the id of the source menu is passed to the menubarPath property of the action.

You can also refer to this:

Trying to put new "Generate" option under Source menu in Eclipse

If you want to avoid org.eclipse.popupmenus which is a depreciated extension in new Luna update.