混合菜单“操作”的顺序和“命令”; Eclipse RCP 中的菜单项
目前我的 RCP 应用程序中有两个菜单: 文件和帮助。
文件菜单是通过命令
创建的:
<extension point="org.eclipse.ui.menus">
<menuContribution allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="fileMenu"
label="File"
mnemonic="F"
tooltip="Main Menu">
<command
commandId="myPlugin.bundle.menuCommands.Exit"
label="Exit"
mnemonic="E"
style="push"
tooltip="Exits MyPlugin">
</command>
</menu>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command defaultHandler="myPlugin.bundle.commands.exit.ExitHandler"
id="myPlugin.bundle.menuCommands.Exit"
name="Exit">
</command>
</extension>
帮助菜单(仅包含“关于”菜单项)是通过相应的操作创建的
:ApplicationActionBarAdvisor
中的
protected void makeActions(IWorkbenchWindow window) {
aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager helpMenu = new MenuManager("&Help", "helpMenu");
helpMenu.add(aboutAction);
menuBar.add(helpMenu);
}
现在,菜单栏中的帮助菜单位于文件菜单之前。这显然不应该是这样的。如何更改菜单的顺序?
非常感谢!
At the moment I have two menus in my RCP application:
File and Help.
The File menu is created via a command
:
<extension point="org.eclipse.ui.menus">
<menuContribution allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="fileMenu"
label="File"
mnemonic="F"
tooltip="Main Menu">
<command
commandId="myPlugin.bundle.menuCommands.Exit"
label="Exit"
mnemonic="E"
style="push"
tooltip="Exits MyPlugin">
</command>
</menu>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command defaultHandler="myPlugin.bundle.commands.exit.ExitHandler"
id="myPlugin.bundle.menuCommands.Exit"
name="Exit">
</command>
</extension>
The Help menu (with only the About menu item) is created via the respective action
in ApplicationActionBarAdvisor
:
protected void makeActions(IWorkbenchWindow window) {
aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager helpMenu = new MenuManager("&Help", "helpMenu");
helpMenu.add(aboutAction);
menuBar.add(helpMenu);
}
Now, the Help menu comes before the File menu in the menu bar. This is obviously not how it's supposed to be. How can I change the order of the menus?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,通过简单地在 File 菜单的
ApplicationActionBarAdvisor
中添加一个MenuManager
就解决了这个问题:我能听到你“d'uh!”吗?因为这就是我所做的;)。
更新:
这真的是应该这样做吗?这意味着对于我在扩展向导中创建的每个新菜单,我都必须向
ApplicationActionBarAdvisor
添加一个新行...也许您可以分享您对此的想法,或者是否只是一个可以避免的黑客行为。
谢谢!
Ah, solved this by simply adding a
MenuManager
in theApplicationActionBarAdvisor
for the File menu:Can I hear you go "d'uh!"? Cos that's what I did ;).
UPDATE:
Is this really how it should be done though? That'd mean that for every new menu I create in the Extension Wizard, I'll have to add a new line to
ApplicationActionBarAdvisor
...Perhaps you could share your thoughts on this, or whether it's just an avoidable hack.
Thanks!