Reputation: 9353
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.
Upvotes: 5
Views: 3796
Reputation: 1088
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();
}
Upvotes: 11
Reputation: 12718
Regarding the content of the current editor, there are several ways to do this. The following code is not tested:
public String getCurrentEditorContent() {
final IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (activeEditor == null)
return null;
final IDocument doc = (IDocument) activeEditor.getAdapter(IDocument.class);
if (doc == null) return null;
return doc.get();
}
Upvotes: 8
Reputation: 51445
I'm assuming you're already familiar with using Eclipse as an IDE.
If you're serious about writing Eclipse plug-ins, the book, "Eclipse Plug-ins" by Eric Clayberg and Dan Rubel is invaluable. I couldn't make sense of the eclipse.org write-ups until after I read the book.
Upvotes: 2