如何在Eclipse中扩展源菜单? (或者:它的 locationURI 是什么?)

发布于 2024-11-30 11:00:15 字数 1002 浏览 1 评论 0原文

我正在开发一个 Eclipse 插件并尝试扩展 Eclipse 3.7 中的源菜单(mainMenubar/Source - 在 java 编辑器中编辑时可见)。

文档说要依赖org.eclipse.ui.menus扩展点,因为旧的扩展点已被弃用。对我来说,在哪里获取可靠的 locationURI 是一个完全的秘密,但我最终设法使用 Plugin Spy 找到了一些看似合理的 URI(遵循建议 此处)。 因此,以下应该是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>

不幸的是,当为我的开发IDE 运行插件时,没有出现命令,也没有错误消息。只是什么也没发生。当我将 locationURI 设置为“menu:help”时,新命令出现在帮助菜单中,因此问题似乎确实是 locationURI。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肤浅与狂妄 2024-12-07 11:00:15

此帖子报告已在主“源”菜单中添加了一个条目:

<!-- 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="&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&String()..."
            menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup">
    </action>
  </actionSet>
</extension>

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="&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&String()..."
            menubarPath="org.eclipse.jdt.ui.source.menu/generateGroup">
    </action>
  </actionSet>
</extension>
只是一片海 2024-12-07 11:00:15

我遇到了同样的问题。我最终发现使用(推荐的)扩展点 org.eclipse.ui.menus 来扩展源菜单是不可能的。

原因是旧式 actionSet 中定义的菜单(如源菜单)是在处理 org.eclipse.ui.menus-extensions 之后创建的。事实上,这些扩展只能对已经存在的菜单做出贡献。

因此,在 jdt 插件迁移到新方法之前,坚持使用旧 API(如 VonC 建议)可能是最好的选择......

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

ぶ宁プ宁ぶ 2024-12-07 11:00:15

您可以使用 popup: 空格代替 menu: 空格。这是一个工作示例:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文