Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » how insert piece of code into the opend editor page(how insert piece of code into the opend editor page)
icon4.gif  how insert piece of code into the opend editor page [message #430270] Thu, 30 July 2009 15:34 Go to next message
stanimir  is currently offline stanimir
Messages: 2
Registered: July 2009
Junior Member
Hi
I am developing an custom developer studio on the base of eclipse platform.
I need to insert piece of code into the current opend page editor(the current opend file for editing).

I fond this but i don't know how to use it. Also it may be wrong. Can anyone help?

IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
IEditorInput input = editor.getEditorInput();

Thanks
Re: how insert piece of code into the opend editor page [message #452781 is a reply to message #430270] Sat, 01 August 2009 14:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

It really depends on the kind of editor. But if it is the default text editor, there is API for working with it (TextEditor, ITextEditor, IDocumentProvider, IDocument).

If you mean the Java editor, that extends from the TextEditor to provide java specific APIs.

PW


Re: how insert piece of code into the opend editor page [message #467892 is a reply to message #452781] Mon, 03 August 2009 10:14 Go to previous message
stanimir  is currently offline stanimir
Messages: 2
Registered: July 2009
Junior Member
I figure it out Smile
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IEditorPart editor = page.getActiveEditor();
if (!(editor instanceof AbstractTextEditor)) {
return;
}
IEditorInput input = editor.getEditorInput();

ITextEditor texteditor = (ITextEditor) editor;
IDocument document =
texteditor.getDocumentProvider().getDocument(input);
try {
ISelection selection =
texteditor.getSelectionProvider().getSelection();
int cursorOffset = ((ITextSelection) selection).getOffset();
// int line = ((ITextSelection) selection).getEndLine();
document.replace(cursorOffset, 0, key + "=" + keyCodes.get(key));
} catch (BadLocationException e) {
e.printStackTrace();
}
Previous Topic:Reload ipreferences without restarting workspace
Next Topic:How do I wrap jars in a plugin?
Goto Forum:
  


Current Time: Tue Sep 16 01:03:43 GMT 2014

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

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