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

发布于 2024-09-14 19:15:10 字数 236 浏览 1 评论 0原文

我的问题可以分为三个:

是否可以通过...

  1. 标准 UI 隐藏/删除 Eclipse (3.6) 中的任意上下文菜单项?
  2. 一些现有的插件?
  3. 自定义插件?

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

My question can be split into three:

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

  1. standard UI?
  2. some existing plug-in?
  3. custom plug-in?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

樱娆 2024-09-21 19:15:10

您可以通过标准 GUI 隐藏菜单或菜单项: 查看帮助

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

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

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


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

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

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

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

  • 第一种方法是通过较新的命令/菜单扩展。
  • 第二种方法是通过旧的 ActionSets 扩展。
  • 还有其他 UI 元素似乎被硬编码到工作台中,并且没有 ID 字符串,并且无法使用活动扩展隐藏。幸运的是,第三种类型的 UI 元素很少。

考虑到你正在谈论最新的 Eclipse,我将仅复制第一种方式:

1/ 使用插件间谍

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

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

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

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.

But that will hide this entry from all the menus (contextual or not) in which it is present.
So it may not be as fine-grained as you want through the 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.xml file and add the org.eclipse.ui.activities extension.
  • Then create an activity node and give it a unique ID.
  • Then create an activityPatternBinding node and use the unique ID for the activity to find the pattern node to the activity node.
    The activityPatternBinding node 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.

  • 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.

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

1/ Use the Plug-In Spy

The first way is to use the Plug-In Spy.
Press alt-shift-F2 and 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.

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