gpt4 book ai didi

java - 仅当处理程序存在时命令才可见

转载 作者:行者123 更新时间:2023-11-30 08:13:13 25 4
gpt4 key购买 nike

我知道我可以让命令像这样可见:

     <command commandId="org.acme.command" style="push">
<visibleWhen checkEnabled="false">
<with variable="selection">
<test property="someProperty"
value="value">
</test>
</with>
</visibleWhen>
</command>

但是如何才能使命令仅在有能够处理该命令的处理程序时才可见呢? (默认行为是命令存在,但被禁用。)

最佳答案

这感觉像是一种黑客攻击,但将此属性测试器连接到命令会有所帮助:

public class HandlerEnabledTester extends PropertyTester {

private static final String PROPERTY_HANDLER_ENABLED = "handlerEnabled";

@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
if (PROPERTY_HANDLER_ENABLED.equals(property)) {
return isHandlerEnabled((String) expectedValue);
}
return false;
}

private static boolean isHandlerEnabled(String commandId) {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = commandService.getCommand(commandId);
return command.isEnabled();
}
}

啊和:

<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.acme.HandlerEnabledTester"
id="org.acme.HandlerEnabledTester"
namespace="scope"
properties="handlerEnabled"
type="org.eclipse.jface.viewers.ISelection">
</propertyTester>
</extension>

...

<command commandId="org.acme.command" style="push">
<visibleWhen checkEnabled="false">
<with variable="selection">
<test property="scope.handlerEnabled"
value="org.acme.command">
</test>
</with>
</visibleWhen>
</command>

关于java - 仅当处理程序存在时命令才可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30053680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com