Eclipse RCP: how to customize the perspective menu?

I need to have full control over the perspective menu.

I have already hacked 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 to also control the default content for the VISUAL MENU . There is one parameter that is always present, which gives access to the Outlook list shell. I need to remove this option from the menu.

It's a shame that the perspective menu is not completely controlled by the user. I just need to add perspectives to the menu, and nothing more!

Thanks.

enter image description here

+4
source share
2 answers

There are 3 possible options to get rid of Other:

  • Set org.eclipse.ui.IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU to false in your RCP application. You can do this by including the plugin_customization.ini file with your product definition.

  • Replace the workbench in your RCP application. Take a look at org.eclipse.ui.internal.PerspectiveBarNewContributionItem as well as org.eclipse.ui.actions.ContributionItemFactory.PERSPECTIVES_SHORTLIST

  • Do not include the default value in your RCP application. Instead, create a perspective panel using the org.eclipse.ui.menus toolbar and openPerspective command.
+2
source

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

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

  org.eclipse.ui.IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU=false 

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

  org.eclipse.ui/SHOW_OTHER_IN_PERSPECTIVE_MENU=false 

Thus, the name of an interface or class that defines a property is not part of the notation!

+1
source

Source: https://habr.com/ru/post/1344021/


All Articles