如何在Eclipse中扩展源菜单? (或者:它的 locationURI 是什么?)
我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此帖子报告已在主“源”菜单中添加了一个条目:
This thread reports having added an entry in the main Source menu:
我遇到了同样的问题。我最终发现使用(推荐的)扩展点 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 oforg.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...您可以使用
popup:
空格代替menu:
空格。这是一个工作示例:You can use the
popup:
space instead of themenu:
space. Here is a working example: