diff options
-rw-r--r-- | Source/SPAlertSheets.m | 7 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.h | 2 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 24 | ||||
-rw-r--r-- | 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) { |