混合菜单“操作”的顺序和“命令”; Eclipse RCP 中的菜单项

发布于 2024-12-26 07:09:21 字数 1476 浏览 1 评论 0原文

目前我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伏妖词 2025-01-02 07:09:21

啊,通过简单地在 File 菜单的 ApplicationActionBarAdvisor 中添加一个 MenuManager 就解决了这个问题:

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

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

更新:

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

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

谢谢!

Ah, solved this by simply adding a MenuManager in the ApplicationActionBarAdvisor for the File menu:

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 ;).

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文