aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPAlertSheets.h15
-rw-r--r--Source/SPAlertSheets.m95
-rw-r--r--Source/SPCustomQuery.h1
-rw-r--r--Source/SPCustomQuery.m30
-rw-r--r--Source/SPPreferenceController.m50
5 files changed, 140 insertions, 51 deletions
diff --git a/Source/SPAlertSheets.h b/Source/SPAlertSheets.h
index d0f64f5b..eb5f5760 100644
--- a/Source/SPAlertSheets.h
+++ b/Source/SPAlertSheets.h
@@ -33,3 +33,18 @@ void SPBeginAlertSheet(
void *contextInfo,
NSString *msg
);
+
+void SPBeginWaitingAlertSheet(
+ NSString *title,
+ NSString *defaultButton,
+ NSString *alternateButton,
+ NSString *otherButton,
+NSAlertStyle alertStyle,
+ NSWindow *docWindow,
+ id modalDelegate,
+ SEL didEndSelector,
+ void *contextInfo,
+ NSString *msg,
+ NSString *infoText,
+ NSInteger *returnCode
+);
diff --git a/Source/SPAlertSheets.m b/Source/SPAlertSheets.m
index 67fb396e..b16b7c19 100644
--- a/Source/SPAlertSheets.m
+++ b/Source/SPAlertSheets.m
@@ -31,7 +31,7 @@
* error text which contains inadvertant printf formatting.
* - The didDismissSelector is no longer supported
* - The sheet no longer needs to be orderOut:ed after use
- * - The alert is alays shown on the main thread.
+ * - The alert is always shown on the main thread.
*/
void SPBeginAlertSheet(
NSString *title,
@@ -71,3 +71,96 @@ void SPBeginAlertSheet(
// Ensure the alerting window is frontmost
[[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:
+ * - 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.
+ * - The didDismissSelector is no longer supported
+ * - The sheet no longer needs to be orderOut:ed after use
+ * - The alert is always shown on the main thread.
+ */
+void SPBeginWaitingAlertSheet(
+ NSString *title,
+ NSString *defaultButton,
+ NSString *alternateButton,
+ NSString *otherButton,
+ NSAlertStyle alertStyle,
+ NSWindow *docWindow,
+ id modalDelegate,
+ SEL didEndSelector,
+ void *contextInfo,
+ NSString *msg,
+ NSString *infoText,
+ NSInteger *returnCode
+) {
+
+ NSButton *aButton;
+
+ // Initialize returnCode with a value which can't be returned as
+ // returnCode in the didEndSelector method
+ NSInteger initialReturnCode = -5;
+ returnCode = initialReturnCode;
+
+ // Set up an NSAlert with the supplied details
+ NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+ [alert setMessageText:title];
+
+ aButton = [alert addButtonWithTitle:defaultButton];
+ [aButton setTag:NSAlertDefaultReturn];
+
+ // Add 'alternate' and 'other' buttons as appropriate
+ if (alternateButton) {
+ aButton = [alert addButtonWithTitle:alternateButton];
+ [aButton setTag:NSAlertAlternateReturn];
+ }
+ if (otherButton) {
+ aButton = [alert addButtonWithTitle:otherButton];
+ [aButton setTag:NSAlertOtherReturn];
+ }
+
+ // Set alert style
+ [alert setAlertStyle:NSWarningAlertStyle];
+ if(alertStyle)
+ [alert setAlertStyle:alertStyle];
+
+ // Set the informative message if supplied
+ if (infoText) [alert setInformativeText:infoText];
+
+ // Set the informative message if supplied
+ if (msg) [alert setMessageText:msg];
+
+ // Run the alert on the main thread
+ [[alert onMainThread] beginSheetModalForWindow:docWindow modalDelegate:modalDelegate didEndSelector:didEndSelector contextInfo:contextInfo];
+
+ // wait for the sheet
+ NSModalSession session = [[NSApp onMainThread] beginModalSessionForWindow:[alert window]];
+ for (;;) {
+
+ // Since the returnCode can only be -1, 0, or 1
+ // run the session until returnCode was changed in
+ // the didEndSelector method of the calling class
+ if(returnCode != initialReturnCode)
+ break;
+
+ // Execute code on DefaultRunLoop
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
+ beforeDate:[NSDate distantFuture]];
+
+ // Break the run loop if sheet was closed
+ if ([NSApp runModalSession:session] != NSRunContinuesResponse
+ || ![[alert window] isVisible])
+ break;
+
+ // Execute code on DefaultRunLoop
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
+ beforeDate:[NSDate distantFuture]];
+
+ }
+ [NSApp endModalSession:session];
+ [NSApp endSheet:[alert window]];
+}
diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h
index c1521390..0081ce5c 100644
--- a/Source/SPCustomQuery.h
+++ b/Source/SPCustomQuery.h
@@ -159,6 +159,7 @@
NSTimer *queryLoadTimer;
NSUInteger queryLoadInterfaceUpdateInterval, queryLoadTimerTicksSinceLastUpdate, queryLoadLastRowCount;
+ NSInteger runAllContinueStopSheetReturnCode;
}
// IBAction methods
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 939b0b9f..31aaea54 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -659,18 +659,21 @@
// ask the user to continue after detecting an error
if (![mySQLConnection queryCancelled]) {
- NSAlert *alert = [[[NSAlert alloc] init] autorelease];
- [alert addButtonWithTitle:NSLocalizedString(@"Run All", @"run all button")];
- [alert addButtonWithTitle:NSLocalizedString(@"Continue", @"continue button")];
- [alert addButtonWithTitle:NSLocalizedString(@"Stop", @"stop button")];
- [alert setMessageText:NSLocalizedString(@"MySQL Error", @"mysql error message")];
- [alert setInformativeText:[mySQLConnection getLastErrorMessage]];
- [alert setAlertStyle:NSWarningAlertStyle];
- NSInteger choice = [[alert onMainThread] runModal];
- switch (choice){
- case NSAlertFirstButtonReturn:
+
+ SPBeginWaitingAlertSheet(@"title",
+ NSLocalizedString(@"Run All", @"run all button"), NSLocalizedString(@"Continue", @"continue button"), NSLocalizedString(@"Stop", @"stop button"),
+ NSWarningAlertStyle, [tableDocumentInstance parentWindow], self,
+ @selector(sheetDidEnd:returnCode:contextInfo:),
+ @"runAllContinueStopSheet",
+ NSLocalizedString(@"MySQL Error", @"mysql error message"),
+ [mySQLConnection getLastErrorMessage],
+ runAllContinueStopSheetReturnCode
+ );
+
+ switch (runAllContinueStopSheetReturnCode) {
+ case NSAlertDefaultReturn:
suppressErrorSheet = YES;
- case NSAlertSecondButtonReturn:
+ case NSAlertAlternateReturn:
break;
default:
if(i < queryCount-1) // output that message only if it was not the last one
@@ -3142,6 +3145,11 @@
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
+ if ([contextInfo isEqualToString:@"runAllContinueStopSheet"]) {
+ runAllContinueStopSheetReturnCode = returnCode;
+ return;
+ }
+
if ([contextInfo isEqualToString:@"clearHistory"]) {
if (returnCode == NSOKButton) {
// Remove items in the query controller
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m
index 2810eeb6..9f09ac2c 100644
--- a/Source/SPPreferenceController.m
+++ b/Source/SPPreferenceController.m
@@ -32,6 +32,7 @@
#import "SPColorAdditions.h"
#import "SPColorWellCell.h"
#import "SPFileManagerAdditions.h"
+#import "SPAlertSheets.h"
@interface SPPreferenceController (PrivateAPI)
@@ -1892,7 +1893,6 @@
- (void)checkForUnsavedThemeDidEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
- [[sheet window] orderOut:self];
checkForUnsavedThemeSheetStatus = returnCode;
}
@@ -1904,45 +1904,17 @@
[[NSColorPanel sharedColorPanel] close];
- checkForUnsavedThemeSheetStatus = -1;
-
- NSAlert *alert = [[[NSAlert alloc] init] autorelease];
- [alert addButtonWithTitle:NSLocalizedString(@"Proceed", @"proceed button")];
- [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"cancel button")];
- [alert addButtonWithTitle:nil];
- [alert setMessageText:NSLocalizedString(@"Warning", @"warning")];
- [alert setInformativeText:NSLocalizedString(@"Current color theme is unsaved. Do you want to proceed without saving it?", @"Current color theme is unsaved. Do you want to proceed without saving it message")];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert setShowsHelp:NO];
- [alert setShowsSuppressionButton:NO];
-
- [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(checkForUnsavedThemeDidEndSheet:returnCode:contextInfo:) contextInfo:nil];
-
- // wait for the sheet
- NSModalSession session = [NSApp beginModalSessionForWindow:[alert window]];
- for (;;) {
-
- if(checkForUnsavedThemeSheetStatus != -1)
- break;
-
- // Execute code on DefaultRunLoop
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
- beforeDate:[NSDate distantFuture]];
-
- // Break the run loop if sheet was closed
- if ([NSApp runModalSession:session] != NSRunContinuesResponse
- || ![[alert window] isVisible])
- break;
-
- // Execute code on DefaultRunLoop
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
- beforeDate:[NSDate distantFuture]];
-
- }
- [NSApp endModalSession:session];
- [NSApp endSheet:[alert window]];
+ SPBeginWaitingAlertSheet(@"title",
+ NSLocalizedString(@"Proceed", @"proceed button"), NSLocalizedString(@"Cancel", @"cancel button"), nil,
+ NSWarningAlertStyle, [self window], self,
+ @selector(checkForUnsavedThemeDidEndSheet:returnCode:contextInfo:),
+ nil,
+ NSLocalizedString(@"Warning", @"warning"),
+ NSLocalizedString(@"Current color theme is unsaved. Do you want to proceed without saving it?", @"Current color theme is unsaved. Do you want to proceed without saving it message"),
+ checkForUnsavedThemeSheetStatus
+ );
- if(checkForUnsavedThemeSheetStatus == NSAlertFirstButtonReturn) {
+ if(checkForUnsavedThemeSheetStatus == NSAlertDefaultReturn) {
return YES;
}