RCP 学习 - Menu contribution

https://wiki.eclipse.org/Menu_Contributions

Menu URIs

For location placement we need a path and placement modifier, and to specify how the paths are built. First pass we are going to look at URIs.

  • <scheme>:<menu-id>[?<placement-modifier>]

scheme is about how to interpret the URI path. For example, menu, toolbar, popup, status (although status may be deprecated).

menu:

For menu: valid root ids will be any viewId for that view's menu, and org.eclipse.ui.main.menu for the main menu. Then specify the id of the menu this contribution applies to. The placement modifier helps position the menu contribution. ex: after=<id>, where <id> can be a separator name, menu id, or item id. An example of a path: menu:org.eclipse.search.menu?after=contextMenuActionsGroup

Since menu ids must be unique, you can specify your menu location relative to an existing id: menu:org.eclipse.search.menu?after=contextMenuActionsGroup

toolbar:

For toolbar: valid root ids will be any viewId for that view's toolbar, org.eclipse.ui.main.toolbar for the main toolbar, and any toolbar id that is contained in the main toolbar. Toolbars can support invisible separators. Toolbars in the main toolbar (technically a coolbar) can have ids as well as separators, but only one level. For example: toolbar:org.eclipse.ui.edit.text.actionSet.presentation?after=Presentation

In this example, Presentation is an invisible separator in the org.eclipse.ui.edit.text.actionSet.presentation toolbar.

The use of org.eclipse.ui.main.toolbar might change if all "main" toolbars have ids anyway, so the only options for interpretting the toolbar root is 1) the view toolbar or 2) an IDed main toolbar.

popup:

For popup: valid root ids are any registered context id (which defaults to the part id if no context menu id was given at registration time) and org.eclipse.ui.popup.any for all registered context menus. For example, to add to the default Text Editor context menu: popup:#TextEditorContext?after=additions

Popup submenus are treated like menu submenus, except the form continues to be popup:submenuId.

There will be constants defined for the ids that the eclipse workbench provides, probably in org.eclipse.ui.menus.MenuUtil.

Using Expressions in <visibleWhen/>

In 3.3M6 an org.eclipse.core.expressions.definitions extension point was added. Used to define a core expression, the definition can then be referenced from other locations.

<extension point="org.eclipse.core.expressions.definitions">
  <definition id="com.example.context">
    <with variable="activeContexts">
       <iterate operator="or">
         <equals value="org.eclipse.ui.contexts.actionSet"/>
       </iterate>
    </with>
  </definition>
</extension>

This can be called in a core expression like activeWhen, enabledWhen, visibleWhen, etc using the reference element:

<reference definitionId="com.example.context"/>

 

Contribution to Description Uri

Application menu

Displays the command in the menu of the application

menu:org.eclipse.ui.main.menu

Application toolbar

displays the command in the toolbar of the application

toolbar:org.eclipse.ui.main.toolbar

View toolbar

displays the command in the toolbar of the view

toolbar:viewId - For example to display a menu to view with the Id "View1" use "toolbar:View1".

Context menu / pop-up

Command is displayed in a context menu, e.g., right mouse click on an object

popup:ID

Status Bar  displays the command in the status bar of the applicatoin. toolbar:org.eclipse.ui.trim.status

表格取自https://blog.****.net/dz881115/article/details/83508192

 

1. 定义menu contribution

RCP 学习 - Menu contribution

 

RCP 学习 - Menu contribution

 

RCP 学习 - Menu contribution

RCP 学习 - Menu contribution

 

添加显示条件

RCP 学习 - Menu contribution

 

MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mantisrcp
Bundle-SymbolicName: mantisrcp;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.core.runtime,
 org.eclipse.ui,
 org.apache.felix.scr,
 org.eclipse.equinox.event,
  org.eclipse.core.expressions
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.inject
Automatic-Module-Name: mantisrcp
Bundle-ActivationPolicy: lazy

 

没有最后一句话, visibleWhen 不被解释