且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Eclipse插件中启用/禁用菜单项

更新时间:2023-09-11 21:06:04

您可以添加一个使用 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>