我为eclipse打印命令添加了一个处理程序:
<handler
class="org.acme.PrintHandler"
commandId="org.eclipse.ui.file.print">
<activeWhen>
<with variable="activePart">
<test property="org.acme.printable" />
</with>
</activeWhen>
</handler>
哪个效果很好。但有时即使活动部分没有,命令的启用也会改变。所以我想强制重新评估activeWhen
部分。我该怎么做?
我试过这样的事情:
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command printCommand = service.getCommand("org.eclipse.ui.file.print");
EvaluationContext context = new EvaluationContext(null, lastEditor);
context.addVariable(ISources.ACTIVE_PART_NAME, lastEditor);
ExecutionEvent event = new ExecutionEvent(printCommand, Collections.EMPTY_MAP, null, context);
// this does nothing
printCommand.setEnabled(context);
// this does nothing as well
service.refreshElements("org.eclipse.ui.file.print", null);
// this executes the command
// (but at least re-evaluates it's enablement before)
printCommand.executeWithChecks(event);
答案 0 :(得分:0)
我认为IEvaluationService.requestEvaluation
方法可以做你想做的事情:
IEvaluationService evalService = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
evalService.requestEvaluation("org.acme.printable");
JavaDoc说
请求此服务重新评估所有已注册的核心表达式 包含给定属性名称的属性测试器。