在Eclipse插件中启用/禁用菜单项 [英] Enable/disable menu item in Eclipse plugin

查看:259
本文介绍了在Eclipse插件中启用/禁用菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个弹出式菜单,其中有一个菜单项,只有当我右键单击某个类的树项目时才启用它,否则禁用它。

I've made a pop-up menu with one menu item, I want to enable it only when I do a right click on a tree item of a certain class type otherwise disable it.

如何实现?

推荐答案

您可以添加一个使用 activeWhen 并将其与该菜单的命令id相关联。

You can add a handler that uses activeWhen and associate it with that menu's command id.

这是一个处理程序,只有当当前选择不为空时,才使命令有效,并且选择是可以适应类型为 Widget 的对象的项目:

Here is a handler that makes a command active only when the current selection is not empty, and the selection is an item that can be adapted to an object of type Widget:

<extension point="org.eclipse.ui.handlers">
  <handler class="com.myproject.handlers.ExportWidgetHandler"
           commandId="com.myproject.commands.exportWidget">
     <activeWhen>
        <with variable="selection">
           <iterate ifEmpty="false" operator="and">
              <adapt type="com.myproject.objects.Widget"/>
           </iterate>
        </with>
     </activeWhen>
  </handler>
</extension>

这篇关于在Eclipse插件中启用/禁用菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆