Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » enabledWhen selection not being honored(Attempting to enable copy when there's a selection in a SourceViewer)
enabledWhen selection not being honored [message #550574] Fri, 30 July 2010 21:05 Go to next message
Alan is currently offline AlanFriend
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" >
         	<with variable="selection">
         		<count value="+" />
         	<with variable="activePartId">
         		<equals value="my.test.views.aview" />

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.

Re: enabledWhen selection not being honored [message #553156 is a reply to message #550574] Mon, 16 August 2010 14:58 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Is this for a context menu? Does your view register your JFace viewer
as its ISelectionProvider? Do you register it for your context menu?


Paul Webster .platform.doc.isv/guide/workbench.htm

Previous Topic:[CNF] Link with editor / lazy tree & auto-expanding the tree
Next Topic:SWT Sleak Problem
Goto Forum:

Current Time: Mon Aug 15 20:07:09 GMT 2022

Powered by FUDForum. Page generated in 0.01904 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top