Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 72114 - [ViewMgmt] Views that implement ISaveablePart are not consulted for dirty state before they are closed.
Summary: [ViewMgmt] Views that implement ISaveablePart are not consulted for dirty sta...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.0.1   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-17 12:21 EDT by Matthew Hatem CLA
Modified: 2005-06-10 10:22 EDT (History)
8 users (show)

See Also:


Attachments
Just a prelim patch for feedback (5.57 KB, patch)
2004-08-31 13:56 EDT, Matthew Hatem CLA
no flags Details | Diff
updated to include the use of a helper class to share code (11.00 KB, patch)
2004-09-01 10:19 EDT, Matthew Hatem CLA
no flags Details | Diff
allows for custom prompt dialog (4.43 KB, patch)
2004-10-21 14:36 EDT, Matthew Hatem CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Hatem CLA 2004-08-17 12:21:16 EDT
A View part that implements ISaveablePart should be consulted about it's state
before it is closed.  This would give the view to give the user the chance to
veto the event.

This should be supported for all close events, including Workbench shutdown.
Comment 1 Nick Edgar CLA 2004-08-17 13:48:33 EDT
Stefan, Matt is trying to work around this problem in 3.0.
Is there any way he can request a view's dirty state from the presentation?
Comment 2 Nick Edgar CLA 2004-08-24 12:25:58 EDT
Matt is investigating for 3.0.1.
Behaviour should depend on an internal pref to prevent unwanted change in
behaviour for any existing views implementing ISaveablePart.
Comment 3 Matthew Hatem CLA 2004-08-31 13:56:54 EDT
Created attachment 14303 [details]
Just a prelim patch for feedback

I did some cut and paste from EditorManager.  Not optimal, but it gets the job
done with minimal modifications.  I have not done a complete regression test on
this patch.  I'm posting it to get some initial feedback.
Comment 4 Nick Edgar CLA 2004-08-31 14:54:55 EDT
I'm OK with the patch overall.  Ideally the methods copied from EditorManager
could be shared somewhere, either in WorkbenchPage (already bloated) or some new
helper class, though I would want to keep the EditorManager.savePart method
there in 3.0.1 -- it could forward as needed.

Stefan, could you please review Matt's patch as well?  Do you have thoughts on
how best to share the code?  
Comment 5 Nick Edgar CLA 2004-08-31 14:56:05 EDT
Actually, in order to avoid unwanted change in behaviour in 3.0.1 for other
views implementing ISaveablePart, we should check an internal preference as to
whether to prompt on dirty view close.  Default would be false.
Comment 6 Nick Edgar CLA 2004-08-31 15:37:20 EDT
I've posted the following to the eclipse.platform newsgroup:

RFC: Close prompt for views that implement ISaveablePart

In Eclipse 2.1, the Workbench added the ISaveablePart interface, allowing views
to participate in the open/modify/save lifecycle usually reserved for editors. 
This was initially done to allow people making modifications in the Synchronize
view to use Ctrl+S or File > Save to save their changes.  

However, we never added the support to prompt to save any unsaved changes when
closing such a view, in the same way that editors do.  This is something we're
considering adding for 3.1, and possibly 3.0.1.
For more details, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=72114

Question: does anybody in the community have views that implement ISaveablePart,
and would they want this change of behaviour?
Comment 7 Nick Edgar CLA 2004-08-31 16:06:29 EDT
See bug 10234 for the original work on ISaveablePart.

See also bug 45248.

Comment 8 Juergen Weber CLA 2004-09-01 04:52:33 EDT
See also bug 71701.
Comment 9 Matthew Hatem CLA 2004-09-01 10:19:40 EDT
Created attachment 14324 [details]
updated to include the use of a helper class to share code
Comment 10 Michael Van Meekeren CLA 2004-09-07 12:17:07 EDT
nick,  any response from the NG or other?  I'd like to put this in today or mark
as 3.1 or other if not.
Comment 11 Nick Edgar CLA 2004-09-07 16:42:39 EDT
Patch reviewed and released into 3.0.1 and head streams.

Also added test in IWorkbenchPageTest.testHideSaveableView().
To support this test, there's a new test harness method:
SaveableHelper.testSetAutomatedResponse(int), which the savePart method checks.
Comment 12 Nick Edgar CLA 2004-09-09 16:43:17 EDT
Verified in M20040908, using modified browser example.
Comment 13 Amy Wu CLA 2004-09-15 18:15:54 EDT
Hi,
  I just noticed this change in save behavior.  I've opened a side-effect bug, 
Bug 74028.
Comment 14 Nick Edgar CLA 2004-09-15 21:22:16 EDT
Need to reopen this one due to bug 74028.
Will add the pref as described in comment #2.
Comment 15 Nick Edgar CLA 2004-09-15 23:29:56 EDT
I've released an updated patch to both streams, along with improved test coverage:

in class Perspective:
    public boolean canCloseView(IViewPart view) {
    	if (PrefUtil.getInternalPreferenceStore().getBoolean("fix72114")) {
    		if (view instanceof ISaveablePart) {
    			ISaveablePart saveable = (ISaveablePart)view;
    			if (saveable.isSaveOnCloseNeeded()) {
    				IWorkbenchWindow window = view.getSite().getWorkbenchWindow();		
    				return SaveableHelper.savePart(saveable, view, window, true);
    			}
    		}
    	}
    	return true;
    }

Matt, you'll need to add the following to your plugin_customization.ini file:
org.eclipse.ui.workbench/fix72114=true
Comment 16 Nick Edgar CLA 2004-09-16 16:44:35 EDT
Verified in M20040916-1125.
Comment 17 Nick Edgar CLA 2004-09-16 16:48:41 EDT
Matt and Amy, can you please also verify this in the M20040616-1125 build?
Comment 18 Amy Wu CLA 2004-09-16 17:38:00 EDT
I have verified (loading org.eclipse.ui.workbench from the R3_0_maintenance 
branch) that without org.eclipse.ui.workbench/fix72114=true I dont get prompt 
dialog.  With it && isSaveOnCloseNeeded return true I get the dialog.  With 
pref && isSaveOnCloseNeeded return false, I don't get dialog.

Thanks!
Comment 19 Matthew Hatem CLA 2004-10-21 14:35:27 EDT
It is critical that our application be able to specify a custom prompt.  Reusing
the Eclipse "save resource" prompt is not always adequate.

Patch to follow.
Comment 20 Matthew Hatem CLA 2004-10-21 14:36:09 EDT
Created attachment 15333 [details]
allows for custom prompt dialog
Comment 21 Nick Edgar CLA 2004-10-21 14:54:06 EDT
Matt, please open a separate bug report rather than reopening reports for fixes
that have shipped.
Comment 22 Nick Edgar CLA 2004-10-21 14:54:32 EDT
re-closing as verified
Comment 23 Michael Van Meekeren CLA 2004-11-02 11:04:37 EST
nick, do you want to mention this in New and Noteworthy for M3
Comment 24 Nick Edgar CLA 2004-11-02 11:22:28 EST
I don't think it's major enough to mention, plus it still requires specifying
org.eclipse.ui.workbench/fix72114=true
to get this behaviour.
Comment 25 Al B CLA 2005-06-10 10:13:42 EDT
Has this been totally resolved in 3.0.2 or is still required to add a
plugin_customization.ini file to the product with the
org.eclipse.ui.workbench/fix72114=true line added to it? I have a view that
implements ISaveablePart and it notifies the workbench whenever the dirty state
changes since I can see the workbench save icon getting enable.  However, it
does not seem to notify the workbench by calling
ISaveablePart.isSaveOnCloseNeeded() and isDirty() as appropriate to determine
whether to open the save dialog when the view is closed.
Comment 26 Nick Edgar CLA 2005-06-10 10:22:08 EDT
In 3.0.2, org.eclipse.ui.workbench/fix72114=true is still needed.
This check has been removed in 3.1.

Note that in 3.0.x, it only checks when the view is explicitly closed, not when
the window is closed or the workbench is shut down.  This has been fixed in 3.1.