Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314647 - [Commands] Not able to fetch the text selected through the textselection object
Summary: [Commands] Not able to fetch the text selected through the textselection object
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact: Paul Webster CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-27 09:10 EDT by archanakravi CLA
Modified: 2010-09-07 08:01 EDT (History)
2 users (show)

See Also:


Attachments
Hello project I used (6.19 KB, application/octet-stream)
2010-05-27 10:32 EDT, Paul Webster CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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