我有一个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>
答案 0 :(得分: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"));
}
}
}
}