From fdf2f07d8dfd4260c2dd5dd3326ad7206c1e30f1 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 19 Aug 2010 20:28:39 +0000 Subject: =?UTF-8?q?=E2=80=A2=20made=20usage=20of=20SPBeginWaitingAlertShee?= =?UTF-8?q?t=20while=20closing=20a=20spf=20file=20for=20readability=20of?= =?UTF-8?q?=20that=20spf=20file=20=E2=80=A2=20suppress=20if=20a=20window?= =?UTF-8?q?=20with=20one=20tab=20will=20be=20closed=20that=20[...=20parent?= =?UTF-8?q?TabShouldClose]=20method=20will=20be=20called=20twice=20via=20c?= =?UTF-8?q?loseTab:=20-=20this=20issue=20could=20be=20the=20reason=20for?= =?UTF-8?q?=20recent=20crashes/exception=20esp.=20of=20the=20NSNavigator?= =?UTF-8?q?=20(should=20be=20investigated=20further)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAlertSheets.m | 7 +++---- Source/SPDatabaseDocument.h | 2 ++ Source/SPDatabaseDocument.m | 24 ++++++++++++++++-------- Source/SPWindowController.m | 12 ++++++++---- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Source/SPAlertSheets.m b/Source/SPAlertSheets.m index b16b7c19..bcaea921 100644 --- a/Source/SPAlertSheets.m +++ b/Source/SPAlertSheets.m @@ -72,11 +72,10 @@ void SPBeginAlertSheet( [[docWindow onMainThread] makeKeyWindow]; } - /** - * Provide a simple alias of NSBeginAlertSheet which waits for a in calling class globally - * declared returnCode by reference which must be changed in the didEndSelector - * of the calling class, with a few differences: + * Provide a simple alias of a NSApp-wide modal NSBeginAlertSheet which waits + * for a in calling class globally declared returnCode by reference which must + * be changed in the didEndSelector of the calling class, with a few differences: * - printf-type format strings are no longer supported within the "msg" * message text argument, preventing access of random stack areas for * error text which contains inadvertant printf formatting. diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 9d027b4f..28ee97ad 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -180,6 +180,8 @@ id statusValues; + NSInteger saveDocPrefSheetStatus; + // Properties SPWindowController *parentWindowController; NSWindow *parentWindow; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index a31a9ac7..e99bc702 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -1077,6 +1077,11 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { + if([contextInfo isEqualToString:@"saveDocPrefSheetStatus"]) { + saveDocPrefSheetStatus = returnCode; + return; + } + // Order out current sheet to suppress overlapping of sheets if ([sheet respondsToSelector:@selector(orderOut:)]) [sheet orderOut:nil]; @@ -3202,16 +3207,19 @@ mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]]; if(!spf || ![spf count] || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:NSLocalizedString(@"Ignore", @"ignore button") - otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Connection data file “%@” couldn't be read. Please try to save the document under a different name.", @"message error while reading connection data file and suggesting to save it under a differnet name"), [fileName lastPathComponent]]]; - [alert setAlertStyle:NSCriticalAlertStyle]; - NSInteger returnCode = [alert runModal]; + SPBeginWaitingAlertSheet(@"title", + NSLocalizedString(@"OK", @"OK button"), NSLocalizedString(@"Ignore", @"ignore button"), nil, + NSCriticalAlertStyle, parentWindow, self, + @selector(sheetDidEnd:returnCode:contextInfo:), + @"saveDocPrefSheetStatus", + [NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")], + [NSString stringWithFormat:NSLocalizedString(@"Connection data file “%@” couldn't be read. Please try to save the document under a different name.", @"message error while reading connection data file and suggesting to save it under a differnet name"), [fileName lastPathComponent]], + saveDocPrefSheetStatus + ); + if (spf) [spf release]; - if(returnCode == NSAlertAlternateReturn) + if(saveDocPrefSheetStatus == NSAlertAlternateReturn) return YES; return NO; diff --git a/Source/SPWindowController.m b/Source/SPWindowController.m index 65c1c330..33a5ae74 100644 --- a/Source/SPWindowController.m +++ b/Source/SPWindowController.m @@ -596,10 +596,14 @@ */ - (BOOL)windowShouldClose:(id)sender { - for (NSTabViewItem *eachItem in [tabView tabViewItems]) { - SPDatabaseDocument *eachDocument = [eachItem identifier]; - if (![eachDocument parentTabShouldClose]) return NO; - } + + // Iterate through all tabs if more than one tab is opened only otherwise + // [... parentTabShouldClose] will be called twice [see self closeTab:(id)sender] + if([[tabView tabViewItems] count] > 1) + for (NSTabViewItem *eachItem in [tabView tabViewItems]) { + SPDatabaseDocument *eachDocument = [eachItem identifier]; + if (![eachDocument parentTabShouldClose]) return NO; + } // Remove global session data if the last window of a session will be closed if([[NSApp delegate] sessionURL] && [[[NSApp delegate] orderedDatabaseConnectionWindows] count] == 1) { -- cgit v1.2.3