Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 314647

Summary: [Commands] Not able to fetch the text selected through the textselection object
Product: [Eclipse Project] Platform Reporter: archanakravi
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: RESOLVED WORKSFORME QA Contact: Paul Webster <pwebster>
Severity: normal    
Priority: P3 CC: darin.eclipse, per.mildner
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Hello project I used none

Description archanakravi CLA 2010-05-27 09:10:34 EDT
Build Identifier:  I20090611-1540

Hi,
Please have a look at the below code. While debugging, i find that the selection is an instance of TextSelection but it is just failing while checking if it is an instance of TextSelection. Not sure about the reason. Please help me out. 

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection != null)
{
    if (selection instanceof TextSelection)
    {
        ITextSelection textSelection = (ITextSelection) selection;
        MessageDialog.openInformation(window.getShell(), "Auto Logging", textSelection.getText());
    }
}

Reproducible: Always

Steps to Reproduce:
1.Put the above mentioned code in the execute method of the handler of a hello World command plugin.
2.Run the eclipse application.
3.Write a piece of code and select a text and perform the action.
4.Nothing happens :(. The window will not be opened with the text. :(
Comment 1 Paul Webster CLA 2010-05-27 10:27:27 EDT
This works fine for me on 3.6 RC2 and 3.5.2 (M20100211-1343).  I generates the Hello World Command plugin and added your code in.  I selected text in a java editor and used both the keybinding CTRL+6 and the toolbar button.

I get a dialog with my text every time.  Do you have anything other than Eclipse Classic installed (PDE,JDT,Platform, and Equinox)?  Try downloading one of the above builds from http://download.eclipse.org/eclipse/downloads/ and put your test plugin into it.  Does the test work?

PW
Comment 2 Paul Webster CLA 2010-05-27 10:32:32 EDT
Created attachment 170192 [details]
Hello project I used

Import existing project into workspace
PW
Comment 3 archanakravi CLA 2010-05-28 07:59:41 EDT
(In reply to comment #2)
> Created an attachment (id=170192) [details]
> Hello project I used
> Import existing project into workspace
> PW

Thanks a lot for your help. I had missed out the inclusion of the bundle org.eclipse.jface.text in the manifest file.

Regards
Archana
Comment 4 Per Mildner CLA 2010-09-02 17:28:09 EDT
Bug 282969 makes HandlerUtil.getCurrentSelection(event) useless for text selections.
Comment 5 Paul Webster CLA 2010-09-07 08:01:29 EDT
Works per attached project
PW