Explorer上下文菜单项

Explorer上下文菜单项

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

问题描述

我正在尝试从Eclipse Package Explorer的上下文菜单中添加一个子菜单条目。

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.

首先,我做了以下:


  • 我添加了org.eclipse.ui.commands和org.eclipse.ui.menus扩展

  • 我定义了一个命令,分别是一个这样的menuContribution:

这个项目会在任何上下文菜单中添加。 ..所以我必须从locationURI替换org.eclipse.ui.popup.any?after = addedions,其中我想要我的项目出现在子菜单的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.

我的问题是:如何确定正确的位置URI?
我使用菜单间谍(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 itemZZZ 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 = addedions]

  • 弹出:YYY [?after = addedions]

请帮助:)

推荐答案

我设法通过定义一个新的菜单贡献和与已定义的菜单具有相同的标识和标签的菜单来实现。最终解决方案如下所示:

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上下文菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:31