My question can be split into three:
Is it possible to hide/remove arbitrary context menu items in Eclipse (3.6) by ...
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).
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 theorg.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.
TheactivityPatternBinding
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With