如何在 Eclipse 中扩展源菜单?(或:它的 locationURI 是什么?)
我正在开发一个 Eclipse 插件并尝试在 Eclipse 3.7 中扩展源菜单(mainMenubar/Source - 在 java-editor 中编辑时可见).
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.
documentation 表示依赖于 org.eclipse.ui.menus
-extension 点,因为旧的扩展点已被弃用.对我来说,在哪里获得可靠的 locationURI 是一个完全的秘密,但我终于设法通过 Plugin Spy 找到了一些似是而非的 URI(遵循建议 这里).所以下面的应该是plugin.xml的扩展片段:
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>
不幸的是,在为我的开发 IDE 运行插件时,没有出现任何命令,也没有错误消息.只是什么都没有发生.当我将 locationURI 设置为menu:help"时,新命令出现在帮助菜单中,所以问题似乎真的是 locationURI.
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.
推荐答案
我遇到了同样的问题.我终于发现使用(推荐的)扩展点 org.eclipse.ui.menus
扩展源菜单是不可能的.
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.
原因是在处理 org.eclipse.ui.menus
-extensions 之后创建了一个旧样式 actionSet
中定义的菜单(类似于 Source 菜单).事实上,这些扩展只能对现有菜单做出贡献.
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.
因此,在 jdt
插件迁移到新方法之前,坚持使用旧 API(如 VonC 所建议)可能是最佳选择...
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...
相关文章