|
|
Re: Getting Current Cursor Location [message #765579 is a reply to message #765509] |
Wed, 14 December 2011 05:29   |
Eclipse User |
|
|
|
Hi Dani,
Though this partly provides what I need, I cannot get the changes done on the cursor (i.e., exact movement path of the cursor on the screen) with this. After adding a listener to a file, I only get if something is selected on that particular file.
I realized that my initial question might be misleading. My problem is following. Let's say that I have a file open in Eclipse and the cursor is on offset 10. I want to be able to get all changes on the cursor (i.e., its new location) as user changes it on the screen.
e.g.,
User moves the cursor by mouse to offset 45 (without selecting any text), I want to get offset = 45
User hits down key, I want to get: offset = 20 (assuming that one line is 10 characters long), etc.
Is there an API (listener) for this?
Thanks,
|
|
|
Re: Getting Current Cursor Location [message #765590 is a reply to message #765579] |
Wed, 14 December 2011 05:54   |
Eclipse User |
|
|
|
On 14.12.2011 11:29, Kivanc Muslu wrote:
> Hi Dani,
> Though this partly provides what I need, I cannot get the changes done
> on the cursor (i.e., exact movement path of the cursor on the screen)
> with this. After adding a listener to a file, I only get if something
> is selected on that particular file.
>
> I realized that my initial question might be misleading. My problem is
> following. Let's say that I have a file open in Eclipse and the cursor
> is on offset 10. I want to be able to get all changes on the cursor
> (i.e., its new location) as user changes it on the screen.
Add a post selection listener. Either add it on the (post) selection
provider you get from the editor or ask the editor site for the
selection service and add it there. See org.eclipse.ui.ISelectionService
for details.
Dani
>
> e.g., User moves the cursor by mouse to offset 45 (without selecting
> any text), I want to get offset = 45
> User hits down key, I want to get: offset = 20 (assuming that one line
> is 10 characters long), etc.
>
> Is there an API (listener) for this?
>
> Thanks,
|
|
|
Re: Getting Current Cursor Location [message #765636 is a reply to message #765590] |
Wed, 14 December 2011 07:30  |
Eclipse User |
|
|
|
Hi Dani,
It works beautifully, thanks a lot for the help.
For people who have the same problem (or might have the same problem), here is some more detailed code:
Adding the listener:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
window.getSelectionService().addPostSelectionListener(new SynchronizerCursorListener());
where the listener is implemented as:
public class SynchronizerCursorListener implements ISelectionListener
{
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection)
{
if (selection instanceof TextSelection)
{
TextSelection textSelection = (TextSelection) selection;
int offset = textSelection.getOffset();
// Do something with offset
}
// Not a text selection event, ignore.
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.05364 seconds