是否可以在 Eclipse (3.6) 中隐藏/删除任意上下文菜单项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3482312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:59:58  来源:igfitidea点击:

Is it possible to hide/remove arbitrary context menu items in Eclipse (3.6)

eclipseeclipse-plugincontextmenueclipse-3.6

提问by Vilius Normantas

My question can be split into three:

我的问题可以分为三个:

Is it possible to hide/remove arbitrary context menu items in Eclipse (3.6) by ...

是否可以通过以下方式隐藏/删除 Eclipse (3.6) 中的任意上下文菜单项...

  1. standard UI?
  2. some existing plug-in?
  3. custom plug-in?
  1. 标准界面?
  2. 一些现有的插件?
  3. 自定义插件?

I failed to find ways to do this by methods 1 and 2. If the only option is creating custom plug-in, could anyone push me towards the right direction where to start (I have some experience in Java, but not in Eclipse plug-ins).

我没有找到通过方法 1 和 2 来做到这一点的方法。如果唯一的选择是创建自定义插件,那么任何人都可以将我推向正确的方向(我在 Java 方面有一些经验,但在 Eclipse 插件方面没有经验-插入)。

采纳答案by VonC

You can hide menus or menu entries through the standard GUI: see help

您可以通过标准 GUI 隐藏菜单或菜单项:请参阅帮助

To hide a menu item or toolbar button:

  • Switch to the perspective that you want to configure.
  • Select Window > Customize Perspective....
  • Open the Menu Visibility or Tool Bar Visibility tab.
  • Find the item you want to hide.
  • Uncheck the check box next to the item. Uncheck a menu to hide all its children.
  • Click OK to cause the changes to take effect.

隐藏菜单项或工具栏按钮:

  • 切换到要配置的透视图。
  • 选择 Window > Customize Perspective....
  • 打开菜单可见性或工具栏可见性选项卡。
  • 找到要隐藏的项目。
  • 取消选中项目旁边的复选框。取消选中菜单以隐藏其所有子项。
  • 单击“确定”以使更改生效。

But that will hide this entry from allthe menus (contextual or not) in which it is present.
So it may not be as fine-grained as you want through the GUI.

但这将从它所在的所有菜单(上下文或非上下文)中隐藏此条目。
因此,它可能不像您希望通过 GUI 那样细粒度。



You can also try it through a plugin(see also Menu contribution)

您也可以通过插件进行尝试(另请参阅菜单贡献

The first steps are pretty standard for using extensions in Eclipse.

  • Open the plugin.xmlfile and add the org.eclipse.ui.activities extension.
  • Then create an activity node and give it a unique ID.
  • Then create an activityPatternBindingnode and use the unique ID for the activity to find the pattern node to the activity node.
    The activityPatternBindingnode requires that you supply a regular expression for the ID string of the UI element that you wish to hide.

The problem is that there appears to be at least 3 ways that menu items and toolbar buttons are added to the UI.

在 Eclipse 中使用扩展的第一步是非常标准的。

  • 打开plugin.xml文件并添加org.eclipse.ui.activities extension.
  • 然后创建一个活动节点并给它一个唯一的 ID。
  • 然后创建一个activityPatternBinding节点并使用该活动的唯一 ID 来查找该活动节点的模式节点。
    activityPatternBinding节点要求您为要隐藏的 UI 元素的 ID 字符串提供正则表达式。

问题是似乎至少有 3 种方法可以将菜单项和工具栏按钮添加到 UI 中。

  • The first way is through the newer Command/Menu Extensions.
  • The second way is through the older ActionSets Extension.
  • Then there are other UI elements that appear to be hard coded into the Workbench and do not have ID strings and cannot be hidden using the Activities Extension. Luckily there are few of this third type of UI element.
  • 第一种方法是通过较新的命令/菜单扩展。
  • 第二种方法是通过旧的 ActionSets 扩展。
  • 然后还有其他 UI 元素似乎是硬编码到 Workbench 中的,没有 ID 字符串,不能使用活动扩展隐藏。幸运的是,这种第三种类型的 UI 元素很少。

Considering you are talking about the latest Eclipse, I will copy only the first way:

考虑到你说的是最新的Eclipse,我只复制第一种方式:

1/ Use the Plug-In Spy

The first way is to use the Plug-In Spy.
Press alt-shift-F2and click on a menu item or toolbar button that you want to be hidden.
If there is an ID string under the heading "active action definition identifier" then you are in luck.
This item has been added using the Command Extension and you can use this ID as the pattern argument for the Activities Extension.
But not all items that have been added using the Command Extension present their ID string to the plug-in spy.

As a side note, the ID strings are period separated.
For instance the ID for a button might be "org.eclipse.ui.navigate.backwardHistory".
Regular expressions use the period to stand for any character. Luckily the period used as a wild card matches with actual period characters so you don't need to escape them if you don't want to. I find it makes it a bit easier to read if they are not escaped and it is highly unlikely it will cause any ambiguous matches.

1/ 使用插件间谍

第一种方法是使用 Plug-In Spy。
alt- shift-F2并单击要隐藏的菜单项或工具栏按钮。
如果标题“活动操作定义标识符”下有一个 ID 字符串,那么您很幸运。
此项已使用命令扩展添加,您可以使用此 ID 作为活动扩展的模式参数。
但并非所有使用命令扩展添加的项目都会向插件间谍显示其 ID 字符串。

作为旁注,ID 字符串以句点分隔。
例如,按钮的 ID 可能是“ org.eclipse.ui.navigate.backwardHistory”。
正则表达式使用句点来代表任何字符。幸运的是,用作通配符的句点与实际的句点字符匹配,因此如果您不想转义,则无需转义它们。我发现如果它们没有被转义,它会更容易阅读,并且它极不可能导致任何模棱两可的匹配。