Klaus Schulz
Klaus Schulz

Reputation: 547

Context Menu visible for specific files

I add a custom context menu item to a texteditor with

<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
     <menu label="Sample Menu">
        <command commandId="HelloPlugin2.commands.sampleCommand"/> 
     </menu>        
 </menuContribution>

Is it possible to enable this entry only when a .java file is opened? My naive attempt was

<visibleWhen checkEnabled="false">
           <with variable="extension">
              <equals value="java"/>
           </with>
</visibleWhen>

but clearly this does not work...

Any suggestions? Thank you!

Upvotes: 1

Views: 181

Answers (1)

greg-449
greg-449

Reputation: 111142

Try something like this:

<visibleWhen checkEnabled="false">
    <adapt type="org.eclipse.core.resources.IFile">
         <test property="org.eclipse.core.resources.contentTypeId"
            value="org.eclipse.jdt.core.javaSource"/>
    </adapt>
</visibleWhen>

This requires the object to be adaptable to a file and that the file content type is Java Source.

Upvotes: 2

Related Questions