menueclipse-rcpperspective

Eclipse RCP: How to configure the Perspective Menu?


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


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.