0

我有一个 Eclipse 插件,我在其中使用 actionSets 创建了菜单。

<extension point="org.eclipse.ui.actionSets">
    <actionSet description="My Sample"
   id="MySample.actionSet"
  label="My Sample"
 visible="true">
<menu
 id="mysample.actionset.menu1"
 label="My Sample">
 <groupMarker
   name="mysample.groupCreatesimilar">
 </groupMarker>
</menu>
<action
  class="org.mysample.actions.create.MyCreateCodeAction"
  definitionId="MySample.myCreateCode.command"
  id="MySample.myCreateCode.command"
  label="Create Sample Code"
  menubarPath="mysample.actionset.menu1/mysample.groupMarker2">
</action>
</actionSet>
</extension>

我需要根据偏好值启用或禁用其中一个菜单。当我使用如下命令时,我能够实现这一点。但我不应该这样做。我必须让它使用上面的代码(actionSet)。请建议如何做到这一点。

<extension
     point="org.eclipse.ui.menus">
  <menuContribution
        locationURI="menu:org.eclipse.ui.main.menu?after=additions">
     <menu
           label="my label"
           id="myMenu.menu1">
        <command
              commandId="MySample.myCreateCode.command"
              mnemonic="S"
              id="MySample.myCreateCode.command">
        </command>
     </menu>
  </menuContribution>

    </extension>
4

1 回答 1

0

整个actionSet应该出现在可以打开/关闭的Window / Customize Perspective对话框选项卡中。Command Groups Availability

要启用/禁用单个操作,您可能需要Action.setEnabled()在操作代码中调用 - 例如:

public class MyCodeCreateAction extends Action
{
  MyCodeCreateAction()
  {
    super();

    IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();

    setEnabled(prefs.getBoolean("preference"));

    prefs.addPropertyChangeListener(new PropertyChangeListener());
  }


  private class PropertyChangeListener implements IPropertyChangeListener
  {
    @Override
    public void propertyChange(final PropertyChangeEvent event)
    {
      if ("preference".equals(event.getProperty()))
       {
         final IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();

         setEnabled(prefs.getBoolean("preference"));
       }
    }
  }
}
于 2013-09-01T17:36:10.500 回答