Search code examples
javapluginseclipse-plugineclipse-rcpmenuitem

How to make my plugin contributes adding a menu-item into an existing sub-menu from an existing menu in Eclipse platform?


Currently I'm working in an Eclipse plug-in project where I have created a View which could be displayed by clicking on main menu Window->Show view->Other..., then clicking on my View from the Other category.

Currently I'm trying this in my plugin.xml file:

<extension
     point="org.eclipse.ui.menus">
  <menuContribution
        locationURI="menu:window?after=additions">

     <menu 
           id="com.kwantec.helloworld.menus.sampleMenu"
           label="Sample Menu"
           mnemonic="M">
        <command
              commandId="com.kwantec.helloworld.commands.sampleCommand"
              id="com.kwantec.helloworld.menus.sampleCommand"
              mnemonic="S">
        </command>
     </menu>
  </menuContribution>
</extension>

..that causes a new sub-menu Sample Menu appears into the existing Window menu of Eclipse. Then I can open my View by clicking on Window->Sample Menu->Sample Command. But now, what I need it's to directly add that Sample Command into menu-items of sub-menu Show View from existing Window menu of Eclipse. Something like Window->Show View->Sample Command.

I have spent several days looking into Eclipse Platform documentation without significant advance. Does anybody knows how to do this?

Thanks in advance.


Solution

  • Views shown directly in 'Window > Show Views' are known as 'view shortcuts'. You add these for a particular perspective using the org.eclipse.ui.perspectiveExtensions extension point.

    Something like:

    <extension point="org.eclipse.ui.perspectiveExtensions"> 
        <perspectiveExtension 
            targetID="org.eclipse.ui.resourcePerspective"> 
            <viewShortcut id="your.view.id"/> 
        </perspectiveExtension> 
    </extension> 
    

    Herer targetID defines the perspective you are updating and the id of viewShortcut is the id of your view.

    You may need to reset the perspective to get your addition to show (Window > Perspective > Reset Perspective).