Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Modifying the editor's content
Modifying the editor's content [message #159736] Thu, 20 November 2003 16:29 Go to next message
Eclipse UserFriend
Hello !
So, my plugin is a popup menu item from the JavaEditor's popup menu. My
code is called properly. Now I am trying to find a way to insert text in
the javaeditor.

My plugin is an IEditorActionDelegate so the methods I implement are :

public void run(IAction action)
public void setActiveEditor(IAction action, IEditorPart targetEditor)

So does anyone know how I can access the content of the editor from (I
guess) the IEditorPart instance ?

To be more precise, when the user right click in the java editor and
select my menu item, I want to insert some text at current position in the
text. So I need to get the caret's position which I know how to get, and I
need access to the text, to a way to update that text.

Any ideas ?

Max.
Re: Modifying the editor's content [message #159973 is a reply to message #159736] Fri, 21 November 2003 05:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.tkilla.ch

Maxime Poulin wrote:
> Hello !
> So, my plugin is a popup menu item from the JavaEditor's popup menu. My
> code is called properly. Now I am trying to find a way to insert text in
> the javaeditor.
>
> My plugin is an IEditorActionDelegate so the methods I implement are :
>
> public void run(IAction action)
> public void setActiveEditor(IAction action, IEditorPart targetEditor)
>
> So does anyone know how I can access the content of the editor from (I
> guess) the IEditorPart instance ?

if (targetEditor instanceof ITextEditor) {
IDocumentProvider provider= ((ITextEditor)
targetEditor).getDocumentProvider();
IEditorInput input= targetEditor.getEditorInput();
IDocument document= provider.getDocument(input);

document.replace(caretPosition, length, "new text");
}


-tom
Re: Modifying the editor's content [message #160109 is a reply to message #159973] Fri, 21 November 2003 09:59 Go to previous message
Eclipse UserFriend
Cool !

Thank you Tom !
Previous Topic:CVS I/O Interrupted
Next Topic:Statusline-messages from Navigator
Goto Forum:
  


Current Time: Mon Jun 02 07:11:08 EDT 2025

Powered by FUDForum. Page generated in 0.48255 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top