Removing "Show In" menu items in Eclipse RCP application - eclipse

I am developing an Eclipse RCP application, and would like to remove some of the items displayed in the "Show In" context menu. The items are placed in this menu by various plug-ins, and I would prefer to not have them there.
Adding a new entry to this menu is well documented: https://wiki.eclipse.org/FAQ_How_do_I_make_my_view_appear_in_the_Show_In_menu%3F
However, removing an existing entry seems problematic, since Views are listed in the "Show In" menu by virtue of them implementing the IShowInTarget interface. The resulting menu items do not have unique IDs that could be used to disable them via an Activity.
It seems to me like the only way to avoid listing a View defined by an existing plug-in in the "Show In" menu is to extend the plug-in class implementing this View.

The source code for the 'Show In' menu is org.eclipse.ui.internal.ShowInMenu.
This gets contributions from a number of places but I don't see anything that could be used to filter them.
'Extending the plug-in class implementing the view' is not really possible.

Related

Different menu item types in Eclipse 4

When I right click on a menu and select Add child, I am presented with several options:
Handled Menu Item
Menu
Direct Menu Item
Dynamic Menu Contribution
VisibleWhen Core Expression
What is the difference between each of these choices?
Handled Menu Item
This is a menu item that uses a command id (and therefore one or more handlers).
Direct Menu Item
This is a menu item where you specify the class to handle the item directly without using a command id.
Menu
This adds a new sub-menu.
Dynamic Menu Contribution
This lets you specify a class that can add multiple menu items dynamically. See here
VisibleWhen Core Expression
This lets you add a 'core expression' to the current menu item to control when it is visible. See the Eclipse help for details of core expressions. Eclipse Oxygen also now supports Imperative Expressions where you can specify a Java class to control the menu visibility.

Hide Resource Management Context Menu entries from a view

I have a custom view in my eclipse RCP and want to hide some of the actions from org.eclipse.ui.navigator.resources.ResourceMgmtActions when a user right clicks on a IProject resource. I just want to display "refresh" action and hide Close, Open, Close Unrelated projects, Build option from the context menu. Is there a way to do this declaratively via plugin.xml or pro grammatically without copying the code from ResourceMgmtActionProvider.java?

Eclipse context menu items removal

I've searched on the internet about removing some of the right click context menu items such as Copy, Run as...,Show in and others and I didn't saw a certain answer about this.
Is it possible to remove these contextual menus without actually removing the plugins that add these contributions to it , a kind of filter for the contextual menu ?

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

My question can be split into three:
Is it possible to hide/remove arbitrary context menu items in Eclipse (3.6) by ...
standard UI?
some existing plug-in?
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).
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.

How to modify the "new" submenu in the Eclipse Navigator?

I am pretty new to eclipse. I notice that depending on the Perspective I am in, the new submenu lists different items in it. Is there a way to pick the items it lists (modifying the perspective) just using the eclipse interface? or am I needing to do a plugin of some sort to enable this.
Go to Window >> Customize Perspective
You should be on the Shortcuts tab and should see a dropdown called Submenus:
Make sure you have the "New" submenu selected and from there you can add New shortcuts.