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

前端 未结 3 1371
时光取名叫无心
时光取名叫无心 2020-12-19 20:27

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 documentati

相关标签:
3条回答
  • 2020-12-19 21:09

    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>
    
    0 讨论(0)
  • 2020-12-19 21:16

    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...

    0 讨论(0)
  • 2020-12-19 21:31

    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>
    
    0 讨论(0)
提交回复
热议问题