I created a menu contribution for an Eclipse plugin.
I would like the menu only to be visible when the p开发者_JAVA百科lugin perspective is active.
Here is what I found, in an open source project, and it works for me:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
id="menu1"
label="Menu 1">
<visibleWhen checkEnabled="false">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="myperspective"/>
</with>
</visibleWhen>
<dynamic class="MenuPopulationClass"
id="MenuPopulation"/>
</menu>
</menuContribution>
</extension>
I suggest to use the Command Framework.
this tutorial can help you
To restrict the visibility of your commands you should check par. 5
This is a bare outline of what you need to do.
To limit the visibility of the top level menu, create an empty ActionSet
through the Extension Point Selection dialog.
Next, add a visibleWhen
expression to the top level menu item defined in the plugin.xml
. Right click on the menu item and select New -> visibleWhen. Right click on the visibleWhen
element and select New -> with
Set variable - "activeContexts"
Right click on the with element and select New -> iterate. Select the new iterate
element and modify its properties so that any matching element will cause the expression to evaluate true
.
Right click on the iterate
element and select New -> equals, then modify the value property.
value = your new ActionSet
Finally, add the top level menu item to your ActionSet.
精彩评论