我的Eclipse IDE中有一个菜单项,如果编辑器当前没有打开,则需要禁用/不可见。
在plugin.xml
我可以使用visibleWhen
代码实现这一点,但我不知道如何检查编辑器当前是否打开。
This thread讨论了一个跟踪编辑器的监听器。但是应该有一种更简单的方法来查找编辑器。例如page.getEditorReferences()
。但是我似乎无法将所有这些放在一起。
那么如何从plugin.xml
开启编辑器?
答案 0 :(得分:3)
这是Ant编辑器使用的。
首先是org.eclipse.core.expressions.definitions
定义:
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="org.eclipse.ant.ui.activeAntEditor">
<with
variable="activeEditorId">
<equals
value="org.eclipse.ant.ui.internal.editor.AntEditor">
</equals>
</with>
</definition>
</extension>
定义了一个名为org.eclipse.ant.ui.activeAntEditor
的表达式,用于测试活动编辑器是否为Ant编辑器。
然后,当编辑器处于活动状态时,希望显示的每个菜单command
条目都使用:
<command
commandId="org.eclipse.ant.ui.open.declaration.command"
style="push">
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.ant.ui.activeAntEditor">
</reference>
</visibleWhen>
</command>
引用org.eclipse.ant.ui.activeAntEditor
表达式进行可见性测试。