Reputation: 3284
I have made a eclipse RCP application, everything is working fine but i recently noticed the Refractor option in menu. I would like to get rid of it. I have the following in ActionBarAdvisor.java:
@Override
protected void fillMenuBar(IMenuManager menu) {
menu.add(createFile());
menu.add(createEdit());
menu.add(createNavigate());
menu.add(createProject());
menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(createWindow());
menu.add(createHelp());
}
The above functions add actions to menu as:
edit.add(undoAct);
and also undoAct is defined as:
private IWorkbenchAction undoAction
makeActions function has contents as:
@Override
protected void makeActions(IWorkbenchWindow window) {
undoAction = ActionFactory.UNDO.create(window);
undoAction.setText("Undo Menu");
register(undoAction);
}
I found a suggestion which said to use hideActionSets to hide the menu. But I could not hide the entire menu but just its actions!
Remove "File, edit,...etc" menus from Eclipse RCP application
How to remove Refractor option now?
Thank you.
Upvotes: 1
Views: 6111
Reputation: 170713
You can use activities, as described here. First, you will need to find the ID of the menu:
- 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.
- Use the Plug-In Registry and plugin.xml files
The second way is to use the Plug-In Registry. You can open this view by going to:
Window/Show View.../Other/Plug-in Development/Plug-In Registry
What you would like to do is to try to get a couple pieces of information:
a) the plugin that is contributing the UI element b) information about what kind of extension the plugin is using to create the UI element
If there is a very unique word associated with the UI element or its tool tip then you can use this in the Plug-In Registry's filter field to try to nail down which plug-in is contributing the UI element. The filter field is not a very powerful tool so it can be a bit frustrating to use. It does not allow wildcards and does not match space characters.
When you track down which plug-in is contributing the UI element then you open the the plug-in in question from the Plug-Ins view which is found grouped with the Package Explorer in the Plug-in Development perspective. Then go to the Extensions tab and search for the ID string which can usually be found in either a usage of the Command or ActionSet extension. If the UI element is added using an ActionSet then you prefix the plug-in ID to UI ID in the pattern argument given to the Activities Extension. For example org.eclipse.ui.actionsets.foo becomes the pattern org.eclipse.ui/org.eclipse.ui.actionsets.foo.
Then create a new Activity
which will never be activated and a corresponding activityPatternBinding
with the id
you found in the last step. It will look like this in your plugin.xml
:
<extension point="org.eclipse.ui.activities">
<activity id="myActivity" name="MenuHidingActivity">
<enabledWhen>
<with variable="activePartId">
<equals value="nonExistentPartId"></equals>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="myActivity" pattern="menuItemID">
</activityPatternBinding>
</extension>
Upvotes: 3