问题
I'm packaging my own Eclipse product. I'm including a third party plugin, PluginA, whose menu contribution is only displayed when the active perspective is Debug. I'd like this menu to be displayed also in a perspective I've created, MyPerspective, from my own plugin, PluginB.
I can't modify PluginA, but I can see the plugin.xml manifest, shown below, which shows how it configures it's menus. Its using the menu's visibleWhen attribute and checking the activePerspective is equal to DebugPerspective.
/PluginA/plugin.xml
<plugin>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="plugina.handlers.PluginAHandler"
name="PluginA Menu Item"
id="PluginA.commands.menuitem">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="PluginA Menu">
<visibleWhen checkEnabled="false">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="org.eclipse.debug.ui.DebugPerspective"/>
</with>
</visibleWhen>
<command
commandId="PluginA.commands.menuitem"
style="push"/>
</menu>
</menuContribution>
</extension>
</plugin>
The following is the manifest from my plugin which shows how I've created my own perspective, MyPerspective.
/PluginB/plugin.xml
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="pluginb.MyPerspectiveFactory"
id="PluginB.myperspective"
name="MyPerspective">
</perspective>
</extension>
When I run the product containing the above 2 plugins I see PluginA Menu on the menu bar only when the active perspective is Debug. I can't see the menu when in MyPerspective.
What I've tried. I added a redefinition of the PluginA menu in PluginB and added in my perspective.
/PluginB/plugin.xml
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="PluginA Menu">
<visibleWhen checkEnabled="false">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="PluginB.myperspective"/>
</with>
</visibleWhen>
<command
commandId="PluginA.commands.menuitem"
style="push"/>
</menu>
</menuContribution>
</extension>
This works but is less than idea because:
- its duplicating code.
- In "Window > Perspective > Customize Perspective > Menu Visibility" the "PluginA Menu" node is duplicated.
What can I add to PluginB that will force PluginA Menu to be shown in MyPerspective and not produce duplicates in the Customize Perspective dialog? I'm happy to add declarative statements to /PluginB/plugin.xml and/or runtime code to /PluginB to achieve this.
来源:https://stackoverflow.com/questions/38568927/show-menus-from-an-existing-plugin-in-a-custom-perspective