Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 7750 - [ActionSets] New action enablement doesn't work for text selections
Summary: [ActionSets] New action enablement doesn't work for text selections
Status: RESOLVED DUPLICATE of bug 7761
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 major (vote)
Target Milestone: ---   Edit
Assignee: Simon Arsenault CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 7383
  Show dependency tree
 
Reported: 2002-01-16 10:50 EST by Dirk Baeumer CLA
Modified: 2002-09-05 11:01 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2002-01-16 10:50:23 EST
I extended one of our actions using the new enablement functionality but I 
didn't get it to work. Here is what I did:

<action id="ExtractMethodAction"
menubarPath="org.eclipse.jdt.ui.RefactoringMenu/codingGroup"
			label="%Refactoring.extractMethodAction.label"
		
	class="org.eclipse.jdt.internal.ui.refactoring.actions.ExtractMethodActi
on"
			enablesFor="1">
		</action>
Comment 1 Dirk Baeumer CLA 2002-01-16 11:06:02 EST
Sorry, pressed commit...

So lets start again. Here is what I did. I changed one of our existing action

<action id="ExtractMethodAction"
  menubarPath="org.eclipse.jdt.ui.RefactoringMenu/codingGroup"
  label="%Refactoring.extractMethodAction.label"
  class="org.eclipse.jdt.internal.ui.refactoring.actions.ExtractMethodAction"
  enablesFor="1">   <== added this line
</action>

As a result the action is now disabled as soon as I activate an editor, even if 
the editor as a selection. Debugging it reveal that the SelectionEnabler 
assumes that the selection implements IAdaptable. This makes sense for elements 
of a structured selection but not for the selection itself.

No I tried to use the new <selection class=""/> stuff. I changed my declaration 
as follows:

<action id="ExtractMethodAction"
  menubarPath="org.eclipse.jdt.ui.RefactoringMenu/codingGroup"
  label="%Refactoring.extractMethodAction.label"
  class="org.eclipse.jdt.internal.ui.refactoring.actions.ExtractMethodAction"/>
  <selection class="xxxx"/>   <== this class doesn't exist
</action>

The action was enabled all the time also I specified a totally bogus class 
name. Debugging this one revealed that the <selection ...> element is only 
considered when their is an enabledFor element.

Have you every tested this stuff ?

And another issue: ITextSelection is specified in a way that isEmpty never 
returns false. This was done (as far as I can recall a discussion with KUM) 
since a text selection must also mark the cursor (empty selection). So for text 
selection I want the possibility to only enable it when the length of an 
selection is > 0. Any idea how to specify this.
Comment 2 Eduardo Pereira CLA 2002-01-28 15:50:11 EST
Support for ITextSelection was added in SelectionEnabler.
Here is a action declaration that works for a ITextSelection or a 
StructuredSelection where the elements are IFiles:

 <action
    label="Menu Option"
    class="org.eclipse.ui.selectionTest.SetAction1Delegate"
    menubarPath="org.eclipse.selectionTest.TextSelectionMenu/group1"
    enablesFor="+"
    id="org.eclipse.ui.tests.internal.as_122">
    <enablement>
 	<or>
         	<objectClass name="org.eclipse.jface.text.ITextSelection"/>
            	<objectClass name="org.eclipse.core.resources.IFile"/>
        </or>
    </enablement>
  </action>
Comment 3 Dirk Baeumer CLA 2002-02-08 11:06:26 EST
This solution is somehow strange. One test is used to test the selection class 
whereas the other tests the elements of an selection. But both tests use the 
property objectClass. In my opinion there should be a new property 
selectionClass. 
Comment 4 Eduardo Pereira CLA 2002-05-28 16:48:17 EDT
Not going to fix this for 2.0. 
Comment 5 Randy Giffen CLA 2002-08-09 10:41:47 EDT
Reopened for investigation
Comment 6 Simon Arsenault CLA 2002-09-03 14:21:23 EDT

*** This bug has been marked as a duplicate of 7761 ***