views:

659

answers:

3

I try to show popup dialog at text cursor position in editor. How can I get text cursor position of active editor (Point) and show popup dialog at this point?

A: 

You can use the getCursorPosition() method of AbstractTextEditor

Alexandre Pauzies
A: 

Hi,

I have to do the same thing (get text cursor position of active Multipage editor) ... but don't manage to get it working.

I have a MultiPageEditor- and MultiPageEditorContributor class. Should I code the getCursorPosition method in one of these classes ? ... if so, how ? (please if possible some lines of code).

Thanks.

Kitesurfer
A: 

I'm not exactly sure what do you mean under "show popup dialog at this point", but do something like this:

IEditorPart editor =  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor instanceof ITextEditor) {
  ISelectionProvider selectionProvider = ((ITextEditor)editor).getSelectionProvider();
  ISelection selection = selectionProvider.getSelection();
  if (selection instanceof ITextSelection) {
    ITextSelection textSelection = (ITextSelection)selection;
    int offset = textSelection.getOffset(); // etc.
  }
}

Of course, in production code do null checks etc.

thSoft
I need (X,Y) point (in pixels) to show a popup dialog and I want to show it under the text cursor like the code completion popup. In your code you get text offset in symbols, how to convert this offset to point in pixels. Or may be exists another way to show popup under the text cursor?