本文介绍了是否可以在 Eclipse (3.6) 中隐藏/删除任意上下文菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题可以分为三个:

My question can be split into three:

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

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

  1. 标准用户界面?
  2. 一些现有的插件?
  3. 自定义插件?

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

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

推荐答案

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

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

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

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

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

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.

您也可以通过插件(参见还有菜单贡献)

第一步是在 Eclipse 中使用扩展的标准步骤.

  • 打开 plugin.xml 文件并添加 org.eclipse.ui.activities 扩展.
  • 然后创建一个活动节点并给它一个唯一的 ID.
  • 然后创建一个 activityPatternBinding 节点,并使用 Activity 的唯一 ID 找到该 Activity 节点的模式节点.
    activityPatternBinding 节点要求您为要隐藏的 UI 元素的 ID 字符串提供正则表达式.
  • 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.

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

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

  • 第一种方法是通过较新的命令/菜单扩展.
  • 第二种方法是通过旧的 ActionSets 扩展.
  • 还有其他 UI 元素似乎是硬编码到 Workbench 中的,没有 ID 字符串,无法使用活动扩展隐藏.幸运的是,这种第三种类型的 UI 元素很少.
  • 考虑到你说的是最新的Eclipse,我只复制第一种方式:

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

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

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

    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.

    这篇关于是否可以在 Eclipse (3.6) 中隐藏/删除任意上下文菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 19:45
查看更多