我正在打包自己的Eclipse产品。我包含了第三方插件PluginA,其菜单贡献仅在活动透视图为Debug时显示。我希望这个菜单也可以在我创建的透视图中显示,MyPerspective,来自我自己的插件,PluginB。
我无法修改PluginA,但我可以看到plugin.xml清单,如下所示,它显示了它如何配置菜单。它使用菜单的visibleWhen属性并检查activePerspective等于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>
以下是我的插件中的清单,它显示了我如何创建自己的观点,MyPerspective。
/PluginB/plugin.xml
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="pluginb.MyPerspectiveFactory"
id="PluginB.myperspective"
name="MyPerspective">
</perspective>
</extension>
当我运行包含上述2个插件的产品时,只有当活动透视图为Debug时,才会在菜单栏上看到PluginA Menu。在MyPerspective中我看不到菜单。
我尝试过的。我在PluginB中添加了PluginA菜单的重新定义,并在我的视角中添加。
/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>
这可行,但不如想法,因为:
我可以添加什么来强制PluginA菜单显示在MyPerspective中而不会在Customize Perspective对话框中产生重复项?我很乐意将/PluginB/plugin.xml和/或运行时代码的声明性语句添加到/ PluginB来实现此目的。