Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get contents of editor

I am trying to develop a simple Eclipse plugin to understand how it works.

I have two questions about this:

How can I get the content of the active editor?

Do you have a good documentation about life cycle plugin and co? I can't find real good documentation on Google.

like image 638
Kiva Avatar asked Jul 12 '11 08:07

Kiva


People also ask

How do you get content on TinyMCE editor?

The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

How do I get the content of TinyMCE editor in jQuery?

You can use the activeEditor for that, or if (for some reason) you have the original element that created the editor in a jQuery object, you can use that jQuery object to get the id of the original element and use that in order to get the content of the TinyMCE (using the TinyMCE editor).


Video Answer


1 Answers

Tonny Madsen's answer is fine, but perhaps a little more transparent (getAdapter() is very opaque) is something like:

public String getCurrentEditorContent() {
    final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
        .getActiveEditor();
    if (!(editor instanceof ITextEditor)) return null;
    ITextEditor ite = (ITextEditor)editor;
    IDocument doc = ite.getDocumentProvider().getDocument(ite.getEditorInput());
    return doc.get();
}
like image 53
John Tang Boyland Avatar answered Oct 15 '22 23:10

John Tang Boyland