Re: Closing windows bearing sheets
Re: Closing windows bearing sheets
- Subject: Re: Closing windows bearing sheets
- From: Dan Bernstein <email@hidden>
- Date: Thu, 7 Mar 2002 23:12:43 +0200
On Tuesday, March 5, 2002, at 12:51 AM, Kurt Revis wrote:
On Monday, March 4, 2002, at 02:06 PM, email@hidden wrote:
You can see what I mean by opening TextEdit, creating 2 new documents,
choosing Page Setup for one of them and option-clicking the close
widget
of the other. This will close the 2 windows, including the one which
was
displaying the Page Setup sheet. Trying to quit TextEdit now wouldn't
work.
Step 1. Log a bug on Apple.
Step 2. Wait for Apple to fix it. :->
Here is an easy workaround for the problem. In your window controller,
in -windowShouldClose, if [[self window] attachedSheet] is not nil,
return NO.
But actually I *do* want the window to close! The window belongs to a
document that has multiple windows. When the "main" document window is
closed, all other windows should close as well, even if they happen to
have a sheet attached to them.
The solution I've adopted for sheets that I create is to add a check for
attached sheet in -windowWillClose:, and if there is one, to -[NSApp
endSheet: returnCode:] it with a special return code. The
-sheetDidEnd:returnCode:contextInfo: responds to this return code by
doing nothing but calling the sheet's delegate's -windowWillClose:
(which is otherwise never called for a sheet whose parent window is
closed this way).
Something similar may or may not work for sheets coming from
NSBegin...Alert(), but for those I may want to really prevent the window
from closing, as you've suggested.
-- Dan Bernstein
_______________________________________________
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.