How to restore edit location of recently closed editor? [message #636972] |
Wed, 03 November 2010 15:44 |
Max Mising name Messages: 54 Registered: September 2010 |
Member |
|
|
I have an editor input which is of type IURIEditorInput which I use to open different types of packaged editors (java,python,xml,text,etc) or system editor. I need the ability to save and restore the edit position of the files opened in these editors and am having a bit of trouble figuring out how to. I am thinking that IMarker is the way to go by getting a marker before they are closed, store it in my editor input, then after they are opened, use IDE.gotoMarker(part,marker) to restore my state. The problem I'm having is creating the marker before they editors are actually closed. Any ideas how to do this? I want to restore the editor as if it was never actually closed.
Thanks,
Max
|
|
|
|
|
|
|
|
Re: How to restore edit location of recently closed editor? [message #637023 is a reply to message #637016] |
Wed, 03 November 2010 19:29 |
|
You can restore the cursor position for text editor instances with the help of a part listener. Here is the code which might help you
private Map<Object, Point> restoreLocations = new HashMap<Object, Point>();
@Override
public void partClosed(IWorkbenchPart part) {
if (part instanceof ITextEditor && part instanceof IEditorPart) {
IEditorInput editorInput = ((IEditorPart)part).getEditorInput();
if (editorInput instanceof IURIEditorInput) {
ITextSelection selection = (ITextSelection) ((ITextEditor)part).getSelectionProvider().getSelection();
restoreLocations.put(((IURIEditorInput) editorInput).getURI(), new Point(selection.getOffset(), selection.getLength()));
}
}
}
@Override
public void partOpened(IWorkbenchPart part) {
if (part instanceof ITextEditor && part instanceof IEditorPart) {
IEditorInput editorInput = ((IEditorPart)part).getEditorInput();
if (editorInput instanceof IURIEditorInput) {
ITextEditor textEditor = (ITextEditor)part;
Point point = restoreLocations.get(((IURIEditorInput) editorInput).getURI());
if (point != null) {
textEditor.selectAndReveal(point.x, point.y);
}
}
}
}
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
|
|
Powered by
FUDForum. Page generated in 0.39332 seconds