Reputation: 110
I created a new command inside a popup menu but it's disabled (not clickable). What tags should I add to my code in order to enable it on specific files (e.g, xml files) ?
Here is my code :
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<command
commandId= "test.popup.actions.NewAction"
label="Run mycommand"
mnemonic="newAction1"
tooltip="Do something with this project">
</command>
</menuContribution>
</extension
>
P.S, I get this warning : "Referenced identifier 'test.popup.actions.NewAction' in attribute 'commandId' cannot be found"
Upvotes: 0
Views: 707
Reputation: 111142
You must define the command id using the org.eclipse.ui.commands
extension point. Something like:
<extension
point="org.eclipse.ui.commands">
<command
id="test.popup.actions.NewAction"
description="Command description"
name="Command name">
</command>
You must then define at least one handler for the command using the org.eclipse.ui.handlers
extension point:
<extension
point="org.eclipse.ui.handlers">
<handler
class="my.package.NewActionHandler"
commandId="test.popup.actions.NewAction">
</handler>
To make the menu item visible only when XML is selected using the <visibleWhen>
element of the menu contribution command. Something like:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<command
commandId= "test.popup.actions.NewAction"
label="Run mycommand"
mnemonic="newAction1"
tooltip="Do something with this project">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.core.resources.name"
value="*.xml">
</test>
</iterate>
</visibleWhen>
</command>
Lots more information in the Eclipse help (and many other places).
Upvotes: 1