Re: Close button vs. command-h
Re: Close button vs. command-h
- Subject: Re: Close button vs. command-h
- From: "Clark Cox" <email@hidden>
- Date: Sat, 3 Feb 2007 08:05:32 -0500
On 2/3/07, Ryan Homer <email@hidden> wrote:
> In most cases, single window non-document-centric apps should
> probably quit when their window is closed (think System
> Preferences, Calculator, etc).
>
>
Thanks for the response, but I need my application to behave as I
have described. I have a main window that is central to the
application. I need to be able to restore my window after the user
has closed it with the close button. So, it should work like the Mail
app, Adium, iTunes, iCal, etc.
Then, open another window.
So, in these applications, do they intercept the close button and
perform a hide instead?
No. There is a huge difference between closing a window and hiding an
application. When I close the window in iCal, that single window
closes, *but* the menubar, and any other windows (such as the
preferences window) remain.
You could hide *the window* in response to a click in the close button
(which has the same effect as closing it as far as the user is
concerned). Then, in your application delegate, you can implement
-applicationShouldHandleReopen:hasVisibleWindows:, which would give
you a chance to respond to a click on your application icon in the
dock.
Something like (warning, composed in mail):
@implementation MyWindowDelegate
-(BOOL)windowShouldClose:(id)sender
{
if(sender == myMainWindow)
{
[myMainWindow orderOut: nil];
return NO;
}
return YES;
}
@end
@implementation MyApplicationDelegate
-(BOOL)applicationShouldHandleReopen:(NSApplication*)application
hasVisibleWindows:(BOOL)visibleWindows
{
if(!visibleWindows)
{
[myMainWindow makeKeyAndOrderFront: nil];
}
return YES;
}
@end
--
Clark S. Cox III
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden