Eclipse RCP:禁止persective栏的上下文菜单

时间:2022-05-27 22:46:24

I would like to suppress the context menu that shows when right clicking on the perspective tool bar in an rcp application. To clarify, I do want the perspective bar and shortcuts to show, but I do not want the context menu to pop up. All perspective tool bar api seems to be internal.

我想取消右键单击rcp应用程序中的透视工具栏时显示的上下文菜单。为了澄清,我确实希望透视栏和快捷方式显示,但我不希望弹出上下文菜单。所有透视工具栏api似乎都是内部的。

Thanks.

2 个解决方案

#1


You can try this

你可以试试这个

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

#2


The context menu of the PerspectiveSwitcher is created deeply in the internal classes of the workbench framework, as you mentioned. You cannot prevent it from beeing created, neither can you get a reference to the PerspectiveSwitcher to suppress the menu somehow, without heavy use of internal classes and a lot of reimplementing existing functionality.

正如您所提到的,PerspectiveSwitcher的上下文菜单深深地创建在工作台框架的内部类中。你不能阻止它被创建,你也不能获得对PerspectiveSwitcher的引用以某种方式抑制菜单,而不需要大量使用内部类和大量重新实现现有功能。

So, to put it simple, IMHO it seems the context menu is not meant to be suppressed.

所以,简单来说,恕我直言,似乎上下文菜单并不意味着被压制。

The easiest and cleanest way to solve your problem would be to suppress the whole perspective bar, and implement your own. There is public API for querying the existing perspectives (IWorkbench.getPerspectiveRegistry) and switching perspectives (IWorkbenchPage.setPerspective), all you need to code is the UI.

解决问题最简单,最干净的方法是压制整个透视栏,并实现自己的视角。有用于查询现有透视图(IWorkbench.getPerspectiveRegistry)和切换透视图(IWorkbenchPage.setPerspective)的公共API,您需要编写的所有代码都是UI。

#1


You can try this

你可以试试这个

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

#2


The context menu of the PerspectiveSwitcher is created deeply in the internal classes of the workbench framework, as you mentioned. You cannot prevent it from beeing created, neither can you get a reference to the PerspectiveSwitcher to suppress the menu somehow, without heavy use of internal classes and a lot of reimplementing existing functionality.

正如您所提到的,PerspectiveSwitcher的上下文菜单深深地创建在工作台框架的内部类中。你不能阻止它被创建,你也不能获得对PerspectiveSwitcher的引用以某种方式抑制菜单,而不需要大量使用内部类和大量重新实现现有功能。

So, to put it simple, IMHO it seems the context menu is not meant to be suppressed.

所以,简单来说,恕我直言,似乎上下文菜单并不意味着被压制。

The easiest and cleanest way to solve your problem would be to suppress the whole perspective bar, and implement your own. There is public API for querying the existing perspectives (IWorkbench.getPerspectiveRegistry) and switching perspectives (IWorkbenchPage.setPerspective), all you need to code is the UI.

解决问题最简单,最干净的方法是压制整个透视栏,并实现自己的视角。有用于查询现有透视图(IWorkbench.getPerspectiveRegistry)和切换透视图(IWorkbenchPage.setPerspective)的公共API,您需要编写的所有代码都是UI。