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

1

22

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

Sil answered 14/8, 2010 at 6:35 Comment(0)
G
24

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.

Garrek answered 14/8, 2010 at 6:54 Comment(7)
"You can hide menus or menu entries through the standard GUI" I tried this. Even after unchecking all items in the perspective customizer, my context menus remain unchanged. Only the main menu seems to be affected. I also tried unchecking command groups but even that didn't help. I'll give the other method a try tonight.Sil
Seeing the same as Vilius - nothing affects the context menus. alt-shift-f2 doesn't seem to do anything... not sure if I need to do something to enable the "Plugin Spy"? Would really like to customize these huge context menus.Storybook
To run Plugin-Spy you needs to add the plugin "org.eclipse.pde.runtime" to your target platformValdis
@sosiouxme: Which version of Eclipse are you using? I checked in both my Eclipse EE and Eclipse SDK and they both have Plugin Spy out of the box (despite what cornz mentioned). To use Plugin Spy, you must select a menubar or context menu item after pressing alt-shift-f2. When hovering in a menu, you will see your cursor change to a magnifying glass and a white box. When you click on an object with this cursor, then, and only then does the Plugin Spy window pop up. Until you click or hover on a menu item, there is no obvious indication that you are in "Plugin Spy mode."Araroba
How can I disable the Rename context menu? I used activities and the pattern I provided is org.eclipse.ui.edit.rename but I can still see Rename under File menuNitride
@wearybands nine years later, my recollection of that mechanism is a bit hazy. That would be better addressed in a new separate question.Garrek
I want to disable eclipse Rename command "org.eclipse.ui.edit.rename" which is under File MenuNitride

© 2022 - 2024 — McMap. All rights reserved.