Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 37221

Summary: [EditorMgmt] AbstractTextEditor#isSaveOnCloseNeeded not called
Product: [Eclipse Project] Platform Reporter: adrian <stori>
Component: UIAssignee: Nick Edgar <n.a.edgar>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: ahunter.eclipse, celek, daniel_megert, hudsonr, kai-uwe_maetzel, Matthew_Hatem, n.a.edgar, peddle, phil.hunt, steven.wasleski
Version: 2.0.2   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description adrian CLA 2003-05-05 11:36:24 EDT
AbstractTextEditor#isSaveOnCloseNeeded() is never called, the close decision is
done solely based on isDirty().

I want my editor view to be closed, without prompting the user, in certain
situations when the unsaved changes are inconsequential.  The editor carries out
certain adjustments on its IDocument when it opens a new file, but there is no
need to save these if the user doesn't further modify its contents.
Comment 1 Dani Megert CLA 2003-07-16 05:52:51 EDT
This is correct but it is not a Platform Text bug but a Platform UI bug:
EditorManager.savePart should do this.

As a workaround you could overwrite doSave() in your editor.
Comment 2 Tim Koss CLA 2003-10-20 12:55:14 EDT
committed for 3.0
Comment 3 Christophe Elek CLA 2004-11-18 10:00:53 EST
Any news :)
Comment 4 Nick Edgar CLA 2004-11-18 11:23:21 EST
No news, but will consider for 3.1 M5.
We added support for this for views in 3.0.1 (if they implement ISaveablePart),
and should fix up editors too.  
Comment 5 Nick Edgar CLA 2004-11-18 11:39:18 EST
No news, but will consider for 3.1 M5.
We added support for this for views in 3.0.1 (if they implement ISaveablePart),
and should fix up editors too.  
Comment 6 Nick Edgar CLA 2005-02-07 18:46:39 EST
*** Bug 60528 has been marked as a duplicate of this bug. ***
Comment 7 Nick Edgar CLA 2005-02-07 19:33:12 EST
It turns out that the change to not call isSaveOnCloseNeeded() was a deliberate
change back in 2.0.  See bug 2714 and bug 24496.

At that time, isSaveOnCloseNeeded was apparently interpreted as "will closing
this editor lose changes", which, in the case of a shared document model like
that in Text, is false when more than one editor is open on the same document.

The user's expectation is that if they close an editor that has changes, they'll
get prompted to save even if the same document is open in another window (the
scenario in bug 2714 really was confusing).

By changing the workbench to only check isDirty(), ignoring
isSaveOnCloseNeeded(), we essentially hardwired that policy into the workbench,
rather than leaving the decision to save on close up to the editor itself.
While we believe that the current behaviour matches the recommended best
practice, there are apparently advanced scenarios where the editor should be
allowed to override this policy.

Kai and Dani, would you be willing to go down the other path suggested in bug
2714 and delete the AbstractTextEditor.isSaveOnCloseNeeded() method, thereby
getting the default behaviour in WorkbenchPart?

The spec for isSaveOnCloseNeeded() states simply:
"Returns whether the contents of this part should be saved when the part is closed."

The default implementation in WorkbenchPart simply forwards to isDirty().
Despite this, I believe the workbench should not assume this and should have the
following logic:

on editor close,
  if editor.isSaveOnCloseNeeded()
    if editor.isDirty()
      prompt to save (Yes, No, Cancel)
      if cancel,
        cancel the close
      else if yes, 
        call doSave() to save the changes
        close the editor
      else if no
        close the editor without saving the changes

Moving to Text for comment.
Comment 8 Nick Edgar CLA 2005-02-09 13:40:07 EST
See also bug 76768 comment 9.
Comment 9 Dani Megert CLA 2005-02-10 12:55:24 EST
Nick, we removed the method (builds > 20050210). Please let us know if we have
to react to bug 76768 comment 9.
Comment 10 Nick Edgar CLA 2005-02-10 13:33:13 EST
Randy, do you know if the change to start calling isSaveOnCloseNeeded would
affect any GEF editors?
Comment 11 Nick Edgar CLA 2005-02-10 13:37:18 EST
With the change to Text (thanks Dani), I'm inclined to go ahead and put the call
to isSaveOnCloseNeeded back in, so the scenarios here will not require the
change described in bug 76768 comment 9.  I think it's too risky to have it
replace the call to isDirty() as originally intended, so the behaviour will be
as sketched above in comment 7.  There is still some risk of breakage, but any
parts that just ignored isSaveOnCloseNeeded() will work fine.
Comment 12 Randy Hudson CLA 2005-02-10 14:02:37 EST
We don't override that method in our base editor so it is equivalent to isDirty
().

IMO, the dirty indicator "*" should always result in a prompt on close.  If the 
editor makes inconsequential model changes, such as changing the zoom level, 
the document position, expand/collapsed state, etc., then the dirty indicator 
must not appear. This is how MS Office behaves.

So I would say the fix is to change the isDirty() behavior for this editor.  If 
the user closes a dirty editor and is not prompted, you can expect future bug 
reports.
Comment 13 Nick Edgar CLA 2005-02-10 14:40:20 EST
Yes, people who want to override isSaveOnCloseNeeded() should be aware that this
may be confusing to the end user (see bug 2714).
Editor implementors will need to decide whether having a different policy for
prompt on close will have more pros than cons.

But I think that editors should be able to override the policy, as long as the
default policy in the workbench stays the same, and meets the typical user
expectation.
Comment 14 Nick Edgar CLA 2005-02-10 23:56:51 EST
Fix and tests released to head.

Affected types:
Workbench
WorkbenchPage
IViewPartTest
IEditorPartTests
MockEditorPart
SaveableMockViewPart

Comment 15 Nick Edgar CLA 2005-02-16 15:49:25 EST
Verified in I20040215-2300.