I'm currently developing an eclipse plugin which conains (among others) an "upload" command and a projectNature "myNature"
This command should be visible at the following places:
- In the context menu of the package explorer (if the surrounding project is of "myNature")
- In the context menu of an opened file in the JavaScript editor if (and only if) the currently opened file is a JavaScript file (can be assumed because its only displayed in JavaScript Editor) AND if this file is contained in a project of "myNature".
So the first part (Project Explorer context menu is working fine).
For the second part i added a menuContribution like this:
<menuContribution
allPopups="false"
locationURI="popup:#JavaScriptEditorContext">
<menu
icon="resources/icons/documents_klein.png"
id="de.test.eclipse.menus.documentsInEditor"
label="Documents">
<command
commandId="de.test.eclipse.portalscripting.commands.uploadCommand"
style="push">
</command>
<visibleWhen
<!-- a good solution is missing here -->
</visibleWhen>
</menu>
</menuContribution>
and a command like this:
<extension
point="org.eclipse.ui.handlers">
<handler
class="de.test.eclipse.portalscripting.handlers.UploadHandler"
commandId="de.test.eclipse.portalscripting.commands.uploadCommand">
<enabledWhen><!-- this works -->
<or>
<reference
definitionId="de.test.eclipse.portalscripting.hasProjectNature">
</reference>
<!-- make the context menu in javascript editor case working -->
</or>
</enabledWhen>
</handler>
</extension>
What i can't figure out is how i can test the currently opened file in the enabledWhen or visbleWhen elements. I'd like to add an element to enabledWhen section of the command so that it is also enabled when the currentFile is contained in a "myNature" project. The "hasProjectnature" definition only works if there are selected elements in the Project Explorer view.
Can anyone help?