From 3ee25e4389c44f6486c0b8a7b631e06b3f2ce026 Mon Sep 17 00:00:00 2001 From: wlux Date: Thu, 27 Jan 2011 20:32:01 +0000 Subject: [PATCH] Fix application termination behavior by sending a message to the document controller to let the user review any unsaved changes in its managed documents before asking the application delegate whether its okay to terminate the application. This matches Cocoa's documented and implemented behavior. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31957 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 14 ++++++++++++++ Source/NSApplication.m | 36 ++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index f298be249..fa10be002 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-01-27 Wolfgang Lux + + * Source/NSApplication.m (-terminate:): Send message to the + document controller to let the user review any unsaved changes in + its managed documents before asking the application delegate + whether its okay to terminate the application. This matches + Cocoa's documented and implemented behavior. + + * Source/NSApplication.m (-terminate): Move call to GSRemoveIcon + from here ... + * Source/NSApplication.m (-replyToApplicationShouldTerminate:): + ... to here to ensure that the app icon is removed from the icon + manager even when the delegate delays application termination. + 2011-01-26 Wolfgang Lux * Headers/AppKit/NSWindow.h: Add missing declaration of the diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 0be20ef68..8e435104c 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -3432,8 +3432,22 @@ struct _DelegateWrapper */ - (void) terminate: (id)sender { - NSApplicationTerminateReply termination = NSTerminateNow; + NSDocumentController *sdc; + NSApplicationTerminateReply termination; + /* First ask the shared document controller to save any unsaved changes */ + sdc = [NSDocumentController sharedDocumentController]; + if ([[sdc documentClassNames] count] > 0) + { + if ([sdc reviewUnsavedDocumentsWithAlertTitle: _(@"Quit") + cancellable: YES] == NO) + { + return; + } + } + + /* Now ask the application delegate whether its okay to terminate */ + termination = NSTerminateNow; if ([_delegate respondsToSelector: @selector(applicationShouldTerminate:)]) { /* The old API has applicationShouldTerminate: return a BOOL, @@ -3447,28 +3461,9 @@ struct _DelegateWrapper */ termination = ([_delegate applicationShouldTerminate: self] & 0xff); } - else - { - NSDocumentController *sdc; - - sdc = [NSDocumentController sharedDocumentController]; - if ([[sdc documentClassNames] count] > 0) - { - if ([sdc reviewUnsavedDocumentsWithAlertTitle: _(@"Quit") - cancellable: YES] == YES) - { - termination = NSTerminateNow; - } - else - { - termination = NSTerminateCancel; - } - } - } if (termination == NSTerminateNow) { - GSRemoveIcon(_app_icon_window); [self replyToApplicationShouldTerminate: YES]; } /* @@ -3492,6 +3487,7 @@ struct _DelegateWrapper _app_is_running = NO; + GSRemoveIcon(_app_icon_window); [[self windows] makeObjectsPerformSelector: @selector(close)]; [NSCursor setHiddenUntilMouseMoves: NO];