【问题标题】:Order of mixed menu 'action' and 'command' menu items in Eclipse RCPEclipse RCP 中混合菜单“操作”和“命令”菜单项的顺序
【发布时间】:2012-01-10 19:48:22
【问题描述】:

目前,我的 RCP 应用程序中有两个菜单: 文件和帮助。

文件菜单是通过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>

帮助菜单(只有关于菜单项)是通过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);
}

现在,帮助菜单位于菜单栏中的文件菜单之前。这显然不是它应该的样子。如何更改菜单的顺序?

非常感谢!

【问题讨论】:

    标签: java menu eclipse-rcp


    【解决方案1】:

    啊,只需在 文件 菜单的 ApplicationActionBarAdvisor 中添加 MenuManager 即可解决此问题:

    MenuManager helpMenu = new MenuManager("&Help", "helpMenu");
    MenuManager fileMenu = new MenuManager("&File", "fileMenu");
    ...
    menuBar.add(fileMenu);
    menuBar.add(helpMenu);
    

    我能听到你说“d'uh!”吗?因为这就是我所做的;)。

    更新:

    这真的应该怎么做吗?这意味着对于我在扩展向导中创建的每个新菜单,我都必须在 ApplicationActionBarAdvisor 中添加一个新行...

    也许您可以分享您对此的想法,或者这是否只是一个可以避免的黑客攻击。

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-09
      • 2023-03-17
      • 1970-01-01
      • 2011-06-11
      • 2011-08-12
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      相关资源
      最近更新 更多