Question

I need to have total control of the perspective menu.

I already hacked into the platform to disable the CONTEXT menu:

private void disablePerspectiveToolbarMenu() {
    PerspectiveBarManager perspectiveBarManager =
        ((WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow()).getPerspectiveBar();
    if (perspectiveBarManager!=null){
        ToolBar toolBar = perspectiveBarManager.getControl();
        Listener[] listeners = toolBar.getListeners(SWT.MenuDetect);
        if (listeners != null){
            for (Listener listener : listeners){
                toolBar.removeListener(SWT.MenuDetect, listener);
            }
        }
    }
}

But i need also to control the default contents of the PERSPECTIVE MENU. There is one option that is always present that gives access to a Perspective List Shell. I need to remove that option from the menu.

It's a shame that the perspective menu is totally out of user control. I just need to have the perspectives added to the menu, and nothing more!

Thanks.

enter image description here

Was it helpful?

Solution

There are 3 potential options to get rid of Other:

  1. Set the org.eclipse.ui.IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU preference to false in your RCP app. This can be done by including a plugin_customization.ini file with your product definition.

  2. Patch the workbench in your RCP app. Have a look at org.eclipse.ui.internal.PerspectiveBarNewContributionItem and org.eclipse.ui.actions.ContributionItemFactory.PERSPECTIVES_SHORTLIST

  3. Don't include the default perspective bar in your RCP app. Instead, create a perspective bar using org.eclipse.ui.menus, a toolbar, and the openPerspective command.

OTHER TIPS

I did some research and the solution did not work as I expected it. Finally I found my mistake.

To set the property in the plugin_customization.ini I tried:

    org.eclipse.ui.IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU=false

but this is not the correct notation!!! Please see the correct solution I added finally to the plugin_customization.xml

    org.eclipse.ui/SHOW_OTHER_IN_PERSPECTIVE_MENU=false

So the name of the interface or the class specifying the property ist not part of the notation!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top