aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAlertSheets.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-08-19 17:10:55 +0000
committerBibiko <bibiko@eva.mpg.de>2010-08-19 17:10:55 +0000
commit692e6e7330d9a6fd0227f74c1665ddc0b19cc4c6 (patch)
tree6eb9bb4b085cbf80b3f038d9cb07edde4220774c /Source/SPAlertSheets.m
parent8915074c6393bdc5cbaa7900299122f0d4e365be (diff)
downloadsequelpro-692e6e7330d9a6fd0227f74c1665ddc0b19cc4c6.tar.gz
sequelpro-692e6e7330d9a6fd0227f74c1665ddc0b19cc4c6.tar.bz2
sequelpro-692e6e7330d9a6fd0227f74c1665ddc0b19cc4c6.zip
• added SPBeginWaitingAlertSheet() routine which offers the chance to display an alert sheet which waits for the change in the didEndSelector method of a passed class NSInteger variable
• applied the SPBeginWaitingAlertSheet routine to Pref > Editor's check for unsaved color themes and in SPCustomQuery's sheet about Stop/Continue/Run All if a query failed after executing "Run All"
Diffstat (limited to 'Source/SPAlertSheets.m')
-rw-r--r--Source/SPAlertSheets.m95
1 files changed, 94 insertions, 1 deletions
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]];
+}