Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 45248 - [ViewMgmt] need a way for views to override save action
Summary: [ViewMgmt] need a way for views to override save action
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-20 20:23 EDT by Amy Wu CLA
Modified: 2005-02-16 15:50 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Amy Wu CLA 2003-10-20 20:23:38 EDT
This feature request was open in response to bugzilla bug 10234

I created a view that contains an editor, so I currently have my view implement 
ISaveablePart so that when a Save is performed in my view, I save inside my 
embedded editor rather than save the current active editor.  As of 3.0 M3, 
ISaveablePart is still marked as "experimental API"  Could this ISaveablePart 
stop being "experiemental" and start being real?  Or can there be a better way 
to override the save action?

I cannot change my view into an editor because my view works off selection from 
the active editor.  So if I turn my view into an editor, I'd have 2 active 
editors, which isn't possible.
Comment 1 Nick Edgar CLA 2003-10-28 09:57:00 EST
Could you please provide more details on what you have in both the view and 
editor?  

Note that in R3.0, the Synchronize view no longer needs to implement 
ISaveablePart since it now shows changes in a compare editor.  
Comment 2 Amy Wu CLA 2003-10-28 18:27:11 EST
My view is basically used for script editing.  The view contains a sashform 
with 2 panels/parts.  When a user selects objects in the active editor, my view 
will display a list of scriptable objects in one panel.  Then when the user 
selects a scriptable object, the appropriate editor for that object will appear 
in the other panel of my view.  That editor is basically an IEditorPart (with 
additional info) and it should have the same functionality as a typical 
IEditorPart.  So if the user is editing script in my view, then hits Ctrl+S, 
the contents of the editor in my view should save rather than just the contents 
of the active editor.
Comment 3 Nick Edgar CLA 2003-12-15 13:04:18 EST
The "experimental API" comments on ISaveablePart have been removed.

It would be better if there was more explicit support for your scenario, e.g. 
allowing multiple parts to participate in a save, rather than requiring each of 
the parts to implement doSave and delegate to the other parts (if visible).
Comment 4 David Green CLA 2004-02-13 21:01:11 EST
I'm interested in seeing ISaveablePart be included in the "Save All" 
functionality of the workbench, including when the workbench is closed and 
some ISaveablePart instances are dirty.
Comment 5 Nick Edgar CLA 2004-02-16 09:59:27 EST
So Save All would unconditionally save all dirty editors and views that 
implement ISaveablePart?  And, on exit, if there were views implementing 
ISaveablePart that were dirty, then they would also show up in the prompt to 
save dialog?  For the latter, it would only be able to show the view title, 
since views have no notion of input element.  Would this suffice?
Comment 6 Nick Edgar CLA 2004-08-31 16:06:11 EDT
See also bug 72114.
Comment 7 Amy Wu CLA 2004-09-16 17:08:35 EDT
In regards to comment #3, yes, some sort of save participant would be real 
nice.  So then when a user performs a Save on the active editor, my view can 
also participate and maybe touch some code up in my embedded editor, then save 
the file in my embedded if it's different than the file in the active editor.  
This way I dont have to have a special or different behavior depending on if 
the user triggered a Save action in the active editor or in my view.  This 
would then also take care of the Save All action for me because when the 
active editor is saved, my view will also be triggered to save.

And as for the save dialog prompt, ideally it would be nice to have the view 
specify what to put in the dialog, but for me, I could work around it by at 
least making my view title a little more descriptive.
Comment 8 Nick Edgar CLA 2004-09-16 17:38:11 EDT
Amy, could you accomplish that -without- your view implementing ISaveablePart,
but having a handshaking protocol between the editor and view?  E.g. view lets
editor know about its presence.  When the editor is told to doSave(), it also
delegated to the view if present? 
Comment 9 Amy Wu CLA 2004-09-16 18:08:51 EDT
Yes, I think that would almost work.  Except for the Save action is only 
enabled if the editor isDirty.  So I guess the view would also need to have a 
say in whether the editor is really dirty or not, which can be somewhat 
confusing to the user if they see that the editor is marked dirty even though 
it really is not.
Comment 10 Nick Edgar CLA 2004-09-29 14:11:41 EDT
See also bug 43464.
Comment 11 Nick Edgar CLA 2004-09-29 14:12:51 EDT
Consider for 3.1.
Should take out the fix72114 preference, making it be the default behaviour.
Should also address bug 43464 (prompt on shutdown).
Comment 12 Nick Edgar CLA 2005-02-07 17:49:44 EST
I've taken out the fix72114 preference check from Perspective.canCloseView().
So the code is now:

    public boolean canCloseView(IViewPart view) {
		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;
    }

If the view doesn't want the prompt to save when dirty, it can return false for
isSaveOnCloseNeeded().

For coordination between the view and editor, I recommend setting it up so that
they share the same underlying document model, where both the view and editor
respond to dirty state changes on the model.  This is how the shared document
model in text editors works.  No further workbench support should be needed for
this.

For customizing the appearance of the save on close prompt, see bug 76768.

For Save All support, and other ISaveablePart issues, see bug 84406.
Comment 13 Nick Edgar CLA 2005-02-16 15:50:13 EST
Verified in I20040215-2300.