How to intercept save panel?
How to intercept save panel?
- Subject: How to intercept save panel?
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 11 May 2003 08:23:28 -0400
When the user closes a document window in my document-based application, I
would like to present a sheet BEFORE the application decides whether there
are unsaved changes requiring it to present a save panel. In my sheet, the
user might make changes that would dirty the document, so my sheet has to
come up before the window even thinks about whether it needs to present the
save panel.
The best I have come up with is to override NSWindowController's
-shouldCloseDocument, returning [super shouldCloseDocument] when I'm done
with my own sheet. This method is apparently called (obviously) before the
save panel is presented.
Is this the best or "right" way to do this? A potential downside is that I
won't be able to call -shouldCloseDocument just to see what its value is,
but I can live with that.
Things I've tried without success:
I can't implement the -windowShouldClose: delegate method because it is
triggered AFTER the save panel is presented.
I can't override the -performClose: action method because it is not
triggered when the user clicks the close button in the window's title bar.
I can't override -close because it is triggered too late.
Things I haven't tried yet:
NSDcoumentController's -removeDocument: presumably is triggered too late for
an override to help me.
Override NSDocument's -prepareSavePanel: or
-shouldRunSavePanelWithAccessoryView? These are called AFTER the decision
whether to save is made, but I could run my own sheet from two different
code branches, here if the document already needs saving (and then call the
super's overridden method to let it present the save panel), and from
-windowShouldClose: if it does not (and then save if my sheet makes changes
that require saving.
I just noticed NSWindow's -standardWindowButton: method, which gives me a
title bar close button. Looking at the NSWindow header, I see that this is
new in Jaguar, which is OK by me. I don't want a new close button but,
fiddling around with it, I see that the action it triggers is the private
NSWindow method -_close. Is there some way I can override that, even though
it isn't declared in the header? Or write a category on NSWindow to
implement my own delegate method or notification when it is called?.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.