RCP:为指定的导航器添加上下文菜单

可以参考Eclipse的Help->Help Content下的:

Platform Plug-in Developer Guide > Programmer's Guide > Plugging into the workbench > Basic workbench extension points using actions
 
为了给Project Explorer的上下文菜单的new子菜单中添加一个新项目,我们使用到了org.eclipse.ui.popupMenus扩展点。
 
定义如下:
<extension
         point="org.eclipse.ui.popupMenus">
      <viewerContribution
            id="org.eclipse.ui.navigator.ProjectExplorer"
            targetID="org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
         <action
               class="editor.test.TestAction"
               definitionId="editor.test.TestAction"
               id="editor.test.action1"
               label="myLabel"
               menubarPath="common.new.menu/additions"
               overrideActionId="galaxy.ide.application.test.action1">
         </action>
      </viewerContribution>
   </extension>

需要注意的项目有:

1、viewerContribution,指定需要添加上下文菜单内容的视图id以及菜单id,这两个id可以在对应导航器上按下shift+alt+F1来获取,如图所示:

2、action下的menubarPath,指定要添加的位置,这个位置我们可以通过快捷键shift+alt+F2来获取,如图所示:

additions表示“附加”,即是action会出现在指定path的子菜单里。

以上就实现了要求的效果。

如下图所示:

原文地址:https://www.cnblogs.com/anrainie/p/3592278.html