Eclipse plugin Eclipse插件:切换菜单命令无法找到处理程序
我试图使用切换菜单选项,但可能做了一些错误。以下代码创建了“切换”菜单项,当我在加载后第一次单击此选项时,它工作正常,但当我再次单击以将其切换回旧状态时,会出现以下错误:Eclipse plugin Eclipse插件:切换菜单命令无法找到处理程序,eclipse-plugin,eclipse-rcp,Eclipse Plugin,Eclipse Rcp,我试图使用切换菜单选项,但可能做了一些错误。以下代码创建了“切换”菜单项,当我在加载后第一次单击此选项时,它工作正常,但当我再次单击以将其切换回旧状态时,会出现以下错误: org.eclipse.core.commands.NotHandledException: There is no handler to execute for command my.commands.compileAutomatically at org.eclipse.core.commands.Command.
org.eclipse.core.commands.NotHandledException: There is no handler to execute for command my.commands.compileAutomatically
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:485)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
....
菜单:
有人能帮我理解我的代码有什么问题,不管当前菜单状态如何,它只会找到一次处理程序吗?谢谢尝试在CompileAutomaticalyHandler中重写isHandled()并返回false
<command
commandId="my.commands.compileAutomatically"
label="Compile Automatically"
style="toggle">
</command>
<command
defaultHandler="my.handlers.CompileAutomaticallyHandler"
id="my.commands.compileAutomatically"
name="Compile Automatically">
<state
class="org.eclipse.ui.handlers.RegistryToggleState:true"
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
public class CompileAutomaticallyHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Command command = event.getCommand();
boolean oldValue = HandlerUtil.toggleCommandState(command);
System.out.println(oldValue);
return null;
}
}