Skip to main content



      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 17:05 Go to next message
Eclipse UserFriend
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
Re: enabledWhen selection not being honored [message #553156 is a reply to message #550574] Mon, 16 August 2010 10:58 Go to previous message
Eclipse UserFriend
Is this for a context menu? Does your view register your JFace viewer
as its ISelectionProvider? Do you register it for your context menu?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
Previous Topic:Step to create object contribution
Next Topic:SWT Sleak Problem
Goto Forum:
  


Current Time: Tue Jul 08 05:53:48 EDT 2025

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

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

Back to the top