如何使用 org.eclipse.ui.menus 向 Eclipse Package Explorer 上下文菜单项添加子菜单条目?

How to add a submenu entry to Eclipse Package Explorer context menu item using org.eclipse.ui.menus?(如何使用 org.eclipse.ui.menus 向 Eclipse Package Explorer 上下文菜单项添加子菜单条目?)

本文介绍了如何使用 org.eclipse.ui.menus 向 Eclipse Package Explorer 上下文菜单项添加子菜单条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Eclipse 包资源管理器的上下文菜单中向项目添加子菜单条目.

I am trying to add a submenu entry to an item from the context menu of the Eclipse Package Explorer.

菜单项已经通过 org.eclipse.ui.popupMenus 在另一个插件中定义,而不是在我正在使用的插件中.(该插件已添加到我的插件的依赖项列表中).它的子菜单中也添加了一些项目,但也使用了 org.eclipse.ui.popupMenus,我正在尝试通过 org.eclipse.ui.menus 来做到这一点.

The menu entry is already defined via org.eclipse.ui.popupMenus in another plugin, not in the one that I am working at. (That plugin is added to the dependencies list of my plugin). There are also items added in its submenu, but also using org.eclipse.ui.popupMenus, and I am trying to do this via org.eclipse.ui.menus.

首先,我做了以下事情:

To begin with, I did the following:

  • 我添加了 org.eclipse.ui.commands 和 org.eclipse.ui.menus 扩展.
  • 我定义了一个命令,分别是这样的 menuContribution:

这会在任何上下文菜单中添加该项目...所以我必须将 locationURI 中的org.eclipse.ui.popup.any?after=additions"替换为我希望我的项目出现的子菜单的 ID在.

This adds the item in any context menu... So I would have to replace "org.eclipse.ui.popup.any?after=additions" from the locationURI with the id of the submenu I want my item to appear in.

我的问题是:如何确定一个正确的locationURI?我使用了菜单间谍 (ALT+SHIFT+F2) 并检查了我想要贡献的子菜单,我收到了以下 URI:

My problem is: how to determine a correct locationURI? I used the menu spy (ALT+SHIFT+F2) and inspected the submenu I want to contribute to, and I received the following URI:

菜单:YYY?after=ZZZ,其中:

menu:YYY?after=ZZZ, where:

YYY 是已经定义的菜单的 ID,我想在其中添加子菜单项ZZZ 是子菜单中操作的 ID,我点击了(使用间谍)

YYY is the id of the menu that is already defined and to which I want to add the submenu item ZZZ is the id of the action from the submenu, that I clicked upon (using the spy)

我尝试了以下,但子菜单项没有出现:

I tryied the following, but the submenu item does not appear:

  • 菜单:YYY[?after=additions]
  • popup:YYY[?after=additions]

请帮忙:)

推荐答案

我设法通过定义一个新的菜单贡献和一个与已经定义的菜单具有相同 id 和标签的菜单来使其工作.最终解决方案如下所示:

I managed to make it work by defining a new menu contribution and a menu having the same id and label as the menu already defined. The final solution looks like this:

<extension point="org.eclipse.ui.menus">
  <menuContribution
        locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
     <menu
           id="YYY"
           label="%YYYs_label">
     </menu>
  </menuContribution>
  <menuContribution
        locationURI="popup:YYY?after=additions">
     <command
           commandId="example.MyCommandHandlerID"
           icon="icons/somePhoto.gif"
           label="MyLabel"
           style="push">
     </command>
  </menuContribution>
</extension>

这篇关于如何使用 org.eclipse.ui.menus 向 Eclipse Package Explorer 上下文菜单项添加子菜单条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使用 org.eclipse.ui.menus 向 Eclipse Package Explorer 上下文菜单项添加子菜单条目?

基础教程推荐