简体   繁体   English

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

[英]Eclipse RCP: Suppress the context menu of the persective bar

I would like to suppress the context menu that shows when right clicking on the perspective tool bar in an rcp application. 我想取消右键单击rcp应用程序中的透视工具栏时显示的上下文菜单。 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. 所有透视工具栏api似乎都是内部的。

Thanks. 谢谢。

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

The context menu of the PerspectiveSwitcher is created deeply in the internal classes of the workbench framework, as you mentioned. 正如您所提到的,PerspectiveSwitcher的上下文菜单深深地创建在工作台框架的内部类中。 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的引用以某种方式抑制菜单,而不会大量使用内部类和大量重新实现现有功能。

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。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM