[英]Order of mixed menu 'action' and 'command' menu items in Eclipse RCP
At the moment I have two menus in my RCP application: File and Help. 目前,我的RCP应用程序中有两个菜单:“文件”和“帮助”。
The File menu is created via a command
: 通过以下
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
: 通过
ApplicationActionBarAdvisor
的相应action
来创建“ 帮助”菜单(仅具有“关于”菜单项):
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! 非常感谢!
Ah, solved this by simply adding a MenuManager
in the ApplicationActionBarAdvisor
for the File menu: 嗯,只需在
ApplicationActionBarAdvisor
为File菜单添加一个MenuManager
即可解决此问题:
MenuManager helpMenu = new MenuManager("&Help", "helpMenu");
MenuManager fileMenu = new MenuManager("&File", "fileMenu");
...
menuBar.add(fileMenu);
menuBar.add(helpMenu);
Can I hear you go "d'uh!"? 我能听见你去吗? Cos that's what I did ;).
因为我就是这样做的;)。
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
... 这意味着对于我在扩展向导中创建的每个新菜单,都必须向
ApplicationActionBarAdvisor
添加新行...
Perhaps you could share your thoughts on this, or whether it's just an avoidable hack. 也许您可以对此发表自己的看法,或者这是否可以避免。
Thanks! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.