Show menus from an existing plugin in a custom Perspective

China☆狼群 提交于 2021-01-29 07:54:06

问题


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:

  1. its duplicating code.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!