【发布时间】:2017-01-31 18:39:38
【问题描述】:
我正在处理一个项目,在该项目中,我需要为仅具有特定扩展名的文件以及从编辑器窗口和项目资源管理器的弹出窗口显示一个弹出菜单。
以下是我制作的plugin.xml文件:
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any">
<command
commandId="abc.contextMenu"
label="Open"
mnemonic="P"
style="push">
<visibleWhen
checkEnabled="false">
<or>
<with
variable="selection">
<iterate
ifEmpty="false">
<reference
definitionId="com.varun.ease.ui.sign.definition.testType">
</reference>
</iterate>
</with>
<with
variable="activeEditorInput">
<and>
<test
property="org.eclipse.ui.IWorkbenchPart"
value="true">
</test>
<reference
definitionId="com.varun.ease.ui.sign.definition.testType">
</reference>
</and>
</with>
</or>
</visibleWhen>
</command>
</menuContribution>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="com.varun.ease.ui.sign.definition.testType">
<adapt
type="org.eclipse.core.resources.IFile">
<or>
<test
property="org.eclipse.core.resources.name"
value="*.py">
</test>
<test
property="org.eclipse.core.resources.name"
value="*.js">
</test>
</or>
</adapt>
</definition>
我只想在编辑器处于活动状态时显示命令,即它在窗口中具有焦点或在从项目资源管理器中选择项目期间。
我应该怎么做才能检查编辑器是否处于活动状态,即它是否在窗口中具有焦点?
目前我正在使用带有org.eclipse.ui.IWorkbenchPart 属性的<test/>,但命令在编辑器窗口的弹出窗口中根本不可见。
在没有该属性的情况下运行,当适当的文件在编辑器中打开但未处于活动状态并且从项目资源管理器而不是从适当的文件打开弹出窗口时,甚至会显示命令。
感谢您的帮助
编辑
按照@greg-449 的指示成功运行编辑器命令后更新了代码。但是现在,当尝试限制特定文件类型时,命令不可见。
<visibleWhen
checkEnabled="false">
<or>
<with
variable="selection">
<iterate
ifEmpty="false">
<reference
definitionId="com.varun.ease.ui.sign.definition.testType">
</reference>
</iterate>
</with>
<with
variable="activePart">
<and>
<reference
definitionId="com.varun.ease.ui.sign.definition.testType">
</reference>
<instanceof
value="org.eclipse.ui.IEditorPart">
</instanceof>
</and>
</with>
</or>
</visibleWhen>
【问题讨论】:
-
我尽量使用这个答案
标签: eclipse eclipse-plugin popup eclipse-rcp