Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 858
Vilius Normantas Avatar asked Aug 14 '10 06:08

Vilius Normantas


1 Answers

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.

like image 54
VonC Avatar answered Nov 15 '22 08:11

VonC