java - 如何删除 eclipse rcp 应用程序中不需要的菜单贡献?

标签 java eclipse eclipse-plugin eclipse-rcp

我制作了一个 eclipse RCP 应用程序,一切正常,但我最近注意到菜单中的 Refractor 选项。我想摆脱它。我在 ActionBarAdvisor.java 中有以下内容:

@Override
    protected void fillMenuBar(IMenuManager menu) {

        menu.add(createFile());
        menu.add(createEdit());
        menu.add(createNavigate());
        menu.add(createProject());
        menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
        menu.add(createWindow());
        menu.add(createHelp());

    }

上述函数将操作添加到菜单:

edit.add(undoAct);

并且 undoAct 也被定义为:

private IWorkbenchAction undoAction

makeActions 函数的内容如下:

@Override
    protected void makeActions(IWorkbenchWindow window) {
        undoAction = ActionFactory.UNDO.create(window);
        undoAction.setText("Undo Menu");
        register(undoAction);
}

我发现了一个建议使用 hideActionSets 来隐藏菜单。但我无法隐藏整个菜单,只能隐藏其操作! Remove "File, edit,...etc" menus from Eclipse RCP application

现在如何删除 Refractor 选项? 谢谢。

最佳答案

您可以使用 Activity ,如所述here . 首先,您需要 find the ID of the menu :

  1. Use the Plug-In Spy

The first way is to use the Plug-In Spy. Press alt-shift-F2 and click on a menu item or toolbar button that you want to be hidden. If there is an ID string under the heading "active action definition identifier" then you are in luck. This item has been added using the Command Extension and you can use this ID as the pattern argument for the Activities Extension. But not all items that have been added using the Command Extension present their ID string to the plug-in spy.

As a side note, the ID strings are period separated. For instance the ID for a button might be "org.eclipse.ui.navigate.backwardHistory". Regular expressions use the period to stand for any character. Luckily the period used as a wild card matches with actual period characters so you don't need to escape them if you don't want to. I find it makes it a bit easier to read if they are not escaped and it is highly unlikely it will cause any ambiguous matches.

  1. Use the Plug-In Registry and plugin.xml files

The second way is to use the Plug-In Registry. You can open this view by going to:

Window/Show View.../Other/Plug-in Development/Plug-In Registry

What you would like to do is to try to get a couple pieces of information:

a) the plugin that is contributing the UI element b) information about what kind of extension the plugin is using to create the UI element

If there is a very unique word associated with the UI element or its tool tip then you can use this in the Plug-In Registry's filter field to try to nail down which plug-in is contributing the UI element. The filter field is not a very powerful tool so it can be a bit frustrating to use. It does not allow wildcards and does not match space characters.

When you track down which plug-in is contributing the UI element then you open the the plug-in in question from the Plug-Ins view which is found grouped with the Package Explorer in the Plug-in Development perspective. Then go to the Extensions tab and search for the ID string which can usually be found in either a usage of the Command or ActionSet extension. If the UI element is added using an ActionSet then you prefix the plug-in ID to UI ID in the pattern argument given to the Activities Extension. For example org.eclipse.ui.actionsets.foo becomes the pattern org.eclipse.ui/org.eclipse.ui.actionsets.foo.

然后创建一个永远不会被激活的新 Activity 和一个相应的 activityPatternBinding 以及您在上一步中找到的 id。它在您的 plugin.xml 中看起来像这样:

<extension point="org.eclipse.ui.activities">  
   <activity id="myActivity" name="MenuHidingActivity">  
      <enabledWhen>  
         <with variable="activePartId">    
            <equals value="nonExistentPartId"></equals>      
         </with>
      </enabledWhen>
   </activity>
   <activityPatternBinding activityId="myActivity" pattern="menuItemID">  
   </activityPatternBinding>
</extension>  

关于java - 如何删除 eclipse rcp 应用程序中不需要的菜单贡献?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19654245/

相关文章:

java - 使用 Eclipse 连接到网络

svn - 子剪辑替代

java - 使用 Java 通过 ssh 运行命令

java - 如何返回保证不会抛出 OnErrorNotImplementedException 的 RxJava Observable?

java - Hybris抛出uri : http://java. sun.com/jsp/jSTL/core无法解决

java - 如何从我的项目中检索所有依赖项

java - 用于在工作区更改时重新启动 osgi 包的 Eclipse 工具

java - Eclipse 指向依赖项中的错误路径

java - 多线程的新手 - 多线程的最具成本效益的方法?

eclipse - Eclipse 包中缺少类,帮助