How to extend the source menu in Eclipse? (or: What is its locationURI?)

孤街醉人 提交于 2019-12-18 07:04:26

问题


I am developing an eclipse plugin and trying to extend the source menu (mainMenubar/Source - visible when editing in the java-editor) in Eclipse 3.7.

The documentation says to rely on the org.eclipse.ui.menus-extension point since the older extension points are deprecated. It is a complete secret to me where to obtain reliable locationURIs, but I finally managed to find some plausible URI with the Plugin Spy (following an advice here). So the following should be the extension snippet for the plugin.xml:

<extension
 point="org.eclipse.ui.menus">
 <menuContribution
     locationURI="menu:org.eclipse.jdt.ui.source.menu">
  <command
    commandId="some.command.id"
        label="Some label"
        style="push">
  </command>
 </menuContribution>
</extension>

Unfortunately, when running the plugin for my development IDE no command appears, and also no error message. Just nothing happens. When I set the locationURI to "menu:help", the new command appears in the help menu, so the problem seems to be really the locationURI.


回答1:


I ran into the same problem. I finally figured out that extending the Source menu using the (recommended) extension point org.eclipse.ui.menus is not possible.

The reason is that a menu defined in an old style actionSet (like the Source menu) is created after the processing of org.eclipse.ui.menus-extensions. The way it is, these extensions can only contribute to already existing menus.

So sticking to the old API (as suggested by VonC) is probably the best option until the jdt plugin is migrated to the new approach...




回答2:


This thread reports having added an entry in the main Source menu:

<!-- main menu -->
<extension point="org.eclipse.ui.actionSets">
  <actionSet label="Java Coding"
             description="Action set containing coding related Java actions"
             visible="true"
             id="org.eclipse.jdt.ui.CodingActionSet2">
    <menu label="&amp;Source"
          path="edit"
          id="org.eclipse.jdt.ui.source.menu">
    </menu>
    <action class="org.gsoc.eclipse.tostringgenerator.actions.GenerateToStringActionDelegate "
            id="org.gsoc.eclipse.tostringgenerator.action"
            label="Generate to&amp;String()..."
            menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup">
    </action>
  </actionSet>
</extension>



回答3:


You can use the popup: space instead of the menu: space. Here is a working example:

    <extension point="org.eclipse.ui.commands">
    <command defaultHandler="com.igenox.plugin.dpbuilder.rcp.handler.CreateBuilderHandler"
        id="com.igenox.plugin.DPBuilder.CreateBuilderPattern" name="CreateBuilderPattern">
    </command>
</extension>
<extension point="org.eclipse.ui.menus">
    <menuContribution
        locationURI="popup:org.eclipse.jdt.ui.source.menu?after=DPSeparator">
        <command commandId="com.igenox.plugin.DPBuilder.CreateBuilderPattern"
            id="createBuilder" label="Create Builder Pattern">
        </command>
    </menuContribution>
    <menuContribution
        locationURI="popup:org.eclipse.jdt.ui.source.menu?after=additions">
        <separator name="DPSeparator" visible="true">
        </separator>
    </menuContribution>
</extension>


来源:https://stackoverflow.com/questions/7113380/how-to-extend-the-source-menu-in-eclipse-or-what-is-its-locationuri

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