• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Close button vs. command-h
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Close button vs. command-h
      • From: Ryan Homer <email@hidden>
References: 
 >Close button vs. command-h (From: Ryan Homer <email@hidden>)
 >Re: Close button vs. command-h (From: Murat Konar <email@hidden>)
 >Re: Close button vs. command-h (From: Ryan Homer <email@hidden>)

  • Prev by Date: Re: Close button vs. command-h
  • Next by Date: Re: Close button vs. command-h
  • Previous by thread: Re: Close button vs. command-h
  • Next by thread: Re: Close button vs. command-h
  • Index(es):
    • Date
    • Thread