Bug 44295 - [WorkbenchParts] Workbench-Shutdown/Startup: Saving/Restoring Cursor Positions in Texteditor-Windows
Summary: [WorkbenchParts] Workbench-Shutdown/Startup: Saving/Restoring Cursor Position...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 2 votes (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 28251 41471 (view as bug list)
Depends on: 168524
Blocks: 44296 124615 150907 169838 182576
  Show dependency tree
 
Reported: 2003-10-07 09:16 EDT by Karl-Heinz Damm CLA
Modified: 2007-05-01 09:11 EDT (History)
8 users (show)

See Also:


Attachments
Add persistable API for editors (20.35 KB, patch)
2006-11-09 13:53 EST, Paul Webster CLA
no flags Details | Diff
NewEditorAction v01 (9.69 KB, patch)
2006-11-10 10:51 EST, Paul Webster CLA
no flags Details | Diff
NewEditorAction v02 (9.69 KB, patch)
2006-12-13 10:04 EST, Paul Webster CLA
no flags Details | Diff
General-Editors preference v01 (12.11 KB, patch)
2007-04-04 11:57 EDT, Paul Webster CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Karl-Heinz Damm CLA 2003-10-07 09:16:05 EDT
Restoring Cursor-Positions in Texteditor-Windows after Workbench Startup
Comment 1 Dani Megert CLA 2003-10-08 04:00:11 EDT
See Nick's comment in bug 44296, comment 2.
Comment 2 Marko Schulz CLA 2003-11-06 06:34:46 EST
This bug is also part of bug 28251, but since this bug here is more focused, I
consider it the "better" report.

Over on bug 28251, comment 1 I already posted some naive thoughts on how to
tackle this in org.eclipse.ui.internal.WorkbenchPage#restoreState(IMemento
memento,IPerspectiveDescriptor activeDescritor) or
org.eclipse.ui.internalorg.eclipse.ui.internal.EditorManager#restoreState/saveState.
Alas, this didn't work as I had hoped:

It is quite easy to store the NavigationLocation in the mememento on shutdown.
One can easily add this at the end of the SafeRunnable in EditorManager.saveState:
      // Save EditorLocation
      if (editor instanceof INavigationLocationProvider) {
            IMemento locationMem =
editorMem.createChild(IWorkbenchConstants.TAG_LOCATION);
            ((INavigationLocationProvider)
editor).createNavigationLocation().saveState(locationMem);
      }
(and, of course, add the TAG_LOCATION to IWorkbenchConstants).

The problem is, how to restore the cursor position on startup. When
EditorManager.restoreState is called, the editors are created - according to the
memento - but not fully initialized yet (createPartControl is not called). Thus
one can easily read the NavigationLocations from the memento in
EditorManager.restoreState, but cannot call restoreLocation(), since the editors
are not yet ready to react on that (e.g. in a AbstractTextEditor the
SourceViewer isn't set yet). :-(

I have no idea on how to solve this.

Maybe Nick's comment in bug 44296, comment 2 may solve this, by enabling editors
to save their state themselves.

If anybody has any other ideas on how to solve this, I would be happy to hear
about it. Maybe I could even find the time to implement it myself.
Comment 3 Douglas Pollock CLA 2004-03-25 10:30:11 EST
This is not on the list for M8.  Deferring.... 
Comment 4 Nick Edgar CLA 2004-05-05 00:26:36 EDT
Sorry, not for 3.0.  Will consider post-3.0.
If Editors want to remember cursor positions, they can use other mechanisms, 
e.g. preferences, resource properties.
These mechanisms also have a longer lifetime, which may be a benefit.
Comment 5 Tod Creasey CLA 2005-08-08 13:36:32 EDT
*** Bug 28251 has been marked as a duplicate of this bug. ***
Comment 6 Dani Megert CLA 2006-03-25 10:40:19 EST
Nick, can this be reopened for 3.3 and implemented along bug 44296 comment 2? I investigated bug 124615 for 3.2 M6 i.e. restoring of the caret but hacking this into Platform Text and managing workbench start and shutdown is not something I want to do.
Comment 7 Nick Edgar CLA 2006-03-29 15:39:50 EST
OK.
Comment 8 Dani Megert CLA 2006-06-23 07:59:16 EDT
Can the priority of this be bumped up?
Comment 9 Paul Webster CLA 2006-09-28 10:59:58 EDT
There are currently no plans to work on this feature.

PW
Comment 10 Dani Megert CLA 2006-09-28 12:20:53 EDT
Paul, as you can see in comment 7 I got the OK from Nick for 3.3. I have an item that is marked for 3.3 which depends on this one. It would be great if this could be reopened.
Comment 11 Paul Webster CLA 2006-09-28 13:57:33 EDT
Reopened ... I assume we're looking at a saveState(*)/restoreState(*) type of situation?

PW
Comment 12 Dani Megert CLA 2006-10-09 04:53:05 EDT
yep, see bug 44296 comment 2.
Comment 13 Paul Webster CLA 2006-11-08 10:57:03 EST
Let's see if we can get something in by M4.

Proposal: an editor part can implement IEditorPersistable as well and get save/init called on it like a view:

IEditorPersitable extends IPersistable {
  /**
   * Extra lifecycle added to match IViewPart lifecycle.  Refer to
   * IWorkbenchPart for basic part lifecycle.
   *
   * editor.init(memento) called after editor.init(site, input) on startup
   * if a memento is available but before the editor.createPartControl(*)
   *
   * editor.saveState(memento) will be called on workbench close
   * just like it currently stores the editor input.
   *
   */
  public void init(IMemento memento);
}

IEditorPart is implementable by clients, so the new methods have to come in through a new interface.  I'll investigate adding them to the EditorPart, though.

PW
Comment 14 Paul Webster CLA 2006-11-09 13:53:10 EST
Created attachment 53564 [details]
Add persistable API for editors

First pass persistable state for editors.

PW
Comment 15 Paul Webster CLA 2006-11-10 08:52:33 EST
Released API into HEAD >20061110

PW
Comment 16 Paul Webster CLA 2006-11-10 10:51:53 EST
Created attachment 53629 [details]
NewEditorAction v01

Draft patch.

If the NewEditorAction will create a new IEditorPart, allow IEditorPersistables to pass the saveState from the existing editor to the restoreState of the new editor.

PW
Comment 17 Paul Webster CLA 2006-12-12 09:40:52 EST
I verified the IEditorPersistable is in M4, and if this is a fix that text can accept I'll release the new action patch into M5.

PW
Comment 18 Dani Megert CLA 2006-12-13 09:44:36 EST
I gave this a try and it works as expected. Thanks.

I would rename IEditorPersistable to IPersistableEditor.

What's missing is a preference in the UI (General > Editors) where users can control whether they want this feature or not (some developers expressed that they would not like this behavior). However, the 'New Editor' action should probably not respect that preference. I suggest to set the default to 'true' and see how people react.
Comment 19 Paul Webster CLA 2006-12-13 10:04:16 EST
Created attachment 55588 [details]
NewEditorAction v02

Thew new editor action patch adjusted for HEAD + IPersistableEditor.

I'll re-test this patch after M4

I've released the IPersistableEditor to HEAD, and it will be in the next platform ui build submission.

PW
Comment 20 Dani Megert CLA 2006-12-19 06:14:47 EST
Paul, I've released the restore code so that you can test. See bug 124615 for details and comments on remaining issues.
Comment 21 Paul Webster CLA 2006-12-20 10:20:00 EST
Released the New Editor action hooks into HEAD >20061220
PW
Comment 22 Paul Webster CLA 2007-02-06 09:55:43 EST
Dani, is there more to this bug to be investigated for M6 (more functionality you are waiting on), or is it fixed for M5?

PW
Comment 23 Dani Megert CLA 2007-02-06 10:05:56 EST
see comment 18: the preference is still not here and there's bug 168524.
Comment 24 Paul Webster CLA 2007-02-06 10:08:53 EST
Ah, the preference.  OK, moving to M6

PW
Comment 25 Dani Megert CLA 2007-02-15 12:30:10 EST
*** Bug 160978 has been marked as a duplicate of this bug. ***
Comment 26 Dani Megert CLA 2007-02-15 12:30:24 EST
*** Bug 41471 has been marked as a duplicate of this bug. ***
Comment 27 Paul Webster CLA 2007-03-15 20:13:00 EDT
Ah, I understand now ... add the preference to General>Editors and if set to false, I won't treat anybody as IPersistableEditor.

This doesn't sound like API, moving to M7
PW
Comment 28 Dani Megert CLA 2007-03-16 02:53:37 EDT
>This doesn't sound like API, moving to M7
Mmmh - e.g. Platform Text and JDT Text have preference constants in API classes and I know of at least IWorkbenchPreferenceConstants in Plat UI. You'd better check before M6 is over ;-)
Comment 29 Paul Webster CLA 2007-03-16 07:20:07 EDT
It should be OK.  I'm doing the work in WorkbenchPage, then I can use our internal IPreferenceConstants.

PW
Comment 30 Paul Webster CLA 2007-04-04 11:57:40 EDT
Created attachment 62948 [details]
General-Editors preference v01

This adds the preference to General>Editors.  It defaults to true.  If false, we won't ask IPersistableEditors to propogate state.

Right now it is "&Use editor state persistance" and is above "Show &multiple editor tabs".  If you have preferences about positioning or the name of the preference, I'm interested.

Maybe "Persist Editor State"?

PW
Comment 31 Dani Megert CLA 2007-04-04 12:00:39 EDT
I'd prefer the word 'restore' instead of the more technically 'persist'.
Comment 32 Paul Webster CLA 2007-04-04 12:03:45 EDT
Dani, sounds good:

The best suggestion so far was:

1) move it to just above Close Editors Automatically
2) call it "Save/restore editor state"

PW
Comment 33 Paul Webster CLA 2007-04-04 12:33:17 EDT
Released to HEAD >20070404
PW
Comment 34 Dani Megert CLA 2007-04-04 12:40:45 EDT
Paul, it should probably also mention that this only happens on starup, e.g.

Restore editor state on startup

Note sure if we could then even move it to the startup pref page.
Comment 35 Paul Webster CLA 2007-04-04 13:12:45 EDT
(In reply to comment #34)
> Paul, it should probably also mention that this only happens on starup, e.g.
> 
> Restore editor state on startup

How about "Restore editor state on open" since it also applies to "New Editor" actions as well?

PW

Comment 36 Dani Megert CLA 2007-04-04 13:30:28 EDT
But not if you simply open the file (e.g. via Navigator or Open Type). See also comment 18:
>However, the 'New Editor' action should
>probably not respect that preference. 
Comment 37 Paul Webster CLA 2007-04-04 14:03:52 EDT
OK, "Restore editor state on startup" and I'll revert the New Editor action to always respect the IPersistableEditor interface.

PW
Comment 38 Paul Webster CLA 2007-04-04 14:31:16 EDT
OK, "Restore &editor state on startup" and reworked so that it only effects the editors opened on startup.  New Editor always uses the persistable state if available, and just opening an editor never from the package explorer (et al) never does.

Released in HEAD
PW
Comment 39 Paul Webster CLA 2007-04-09 19:26:50 EDT
Fixed for the I build
PW
Comment 40 Paul Webster CLA 2007-05-01 09:11:54 EDT
In I20070501-0010
PW