enabledWhen selection not being honored [message #550574] |
Fri, 30 July 2010 21:05 |
Alan Messages: 5 Registered: July 2009 |
Junior Member |
|
|
I'm implementing a context menu for a SourceViewer in a view. However I can't figure out how to enable/disable an edit command like "copy", based on whether some text is selected, using enabledWhen. Can someone please help me to figure this out?
The problem is that the menu item for copy is never enabled. To define this command in the popup menu I reference the commandId org.eclipse.ui.edit.copy. I also define a handler class for org.eclipse.ui.edit.copy that is just an empty facade on org.eclipse.ui.internal.handlers.WidgetMethodHandler which I believe is the platform's handler for edit commands. The idea of having this facade is just to convince myself that my handler is active, which it is. My handler definition looks like this:
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.edit.copy" class="my.test.TestHandler:copy" >
<enabledWhen>
<with variable="selection">
<count value="+" />
</with>
</enabledWhen>
<activeWhen>
<with variable="activePartId">
<equals value="my.test.views.aview" />
</with>
</activeWhen>
</handler>
</extension>
I tried debugging into platform code and got as far as finding that the variable "selection" was not present in the EvaluationContext that is used to determine whether the copy menu item is enabled. Thus it seems that the enabledWhen element is being ignored for some reason.
I know how to do all this programmatically, but the declarative approach seems more elegant, if it works. Any advice would be appreciated.
Alan
Cheers
Alan
|
|
|
|
Powered by
FUDForum. Page generated in 0.45261 seconds