Eclipse RCP:如何配置透视菜单?

4

我需要完全控制透视菜单。

我已经入侵了平台,禁用了上下文菜单:

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);
            }
        }
    }
}

但是我还需要控制PERSPECTIVE MENU的默认内容。总有一个选项始终存在,可以访问Perspective List Shell。我需要从菜单中删除该选项。
遗憾的是,透视菜单完全不受用户控制。我只需要将透视图添加到菜单中,仅此而已!
谢谢。

2
我在几周前在Eclipse网站上提出了一个“功能请求”,关于PerspectiveBar缺乏控制的问题。https://bugs.eclipse.org/bugs/show_bug.cgi?id=341030 - marcolopes
2个回答

2
有三种可能的方法来消除“其他”选项:
  1. 在您的RCP应用中将org.eclipse.ui.IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU偏好设置为false。可以通过在产品定义中包含plugin_customization.ini文件来完成此操作。
  2. 在您的RCP应用程序中修补工作台。查看org.eclipse.ui.internal.PerspectiveBarNewContributionItemorg.eclipse.ui.actions.ContributionItemFactory.PERSPECTIVES_SHORTLIST
  3. 不要在您的RCP应用程序中包含默认的透视图栏。相反,使用org.eclipse.ui.menus、一个工具栏和openPerspective命令创建一个透视图栏。

谢谢!我无法通过plugin_customization.ini使其工作。但是我将其添加到了我的其他初始化中:PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU, false); - marcolopes

2
我做了一些研究,但解决方案并没有像我预期的那样有效。最终,我找到了我的错误。
为了在 plugin_customization.ini 中设置属性,我尝试了以下方法:
    org.eclipse.ui.IWorkbenchPreferenceConstants.SHOW_OTHER_IN_PERSPECTIVE_MENU=false

但这并不是正确的标记!!! 请看我最终添加到plugin_customization.xml的正确解决方案。
    org.eclipse.ui/SHOW_OTHER_IN_PERSPECTIVE_MENU=false

因此,指定属性的接口或类的名称不是符号的一部分!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接