diff options
author | Max <post@wickenrode.com> | 2015-07-19 04:54:32 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-10-02 19:30:07 +0200 |
commit | d8acb8faf2c96fd059bef0c17e03279816159447 (patch) | |
tree | 9ec7d598eeeba9e5c95e252c56fba39e81586492 /Source/SPAlertSheets.m | |
parent | 2d9145d32e1bc1a2507b503a5314205ee9afcd58 (diff) | |
download | sequelpro-d8acb8faf2c96fd059bef0c17e03279816159447.tar.gz sequelpro-d8acb8faf2c96fd059bef0c17e03279816159447.tar.bz2 sequelpro-d8acb8faf2c96fd059bef0c17e03279816159447.zip |
Create a method for async alert messages to handle worker code displaying UI messages (part of #2175)
Diffstat (limited to 'Source/SPAlertSheets.m')
-rw-r--r-- | Source/SPAlertSheets.m | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Source/SPAlertSheets.m b/Source/SPAlertSheets.m index 59f058d0..85afbdfb 100644 --- a/Source/SPAlertSheets.m +++ b/Source/SPAlertSheets.m @@ -144,6 +144,40 @@ @end /** + * A Send-and-forget variant for displaying alerts. + * It will queue the alert on the main thread and *always* immediately return. + * Because of that there is no way to set a delegate and callback method + * and there is only one default button. + * If nil is passed as the button title it will be changed to @"OK". + */ +void SPOnewayAlertSheet( + NSString *title, + NSString *defaultButton, + NSWindow *docWindow, + NSString *msg) +{ + NSString *defaultText = (defaultButton)? defaultButton : NSLocalizedString(@"OK", @"OK button"); + + dispatch_async(dispatch_get_main_queue(), ^{ + // Set up an NSAlert with the supplied details + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + [alert setMessageText:title]; + + NSButton *aButton = [alert addButtonWithTitle:defaultText]; + [aButton setTag:NSAlertDefaultReturn]; + + // Set the informative message if supplied + if (msg) [alert setInformativeText:msg]; + + // Run the alert + [alert beginSheetModalForWindow:docWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; + + // Ensure the alerting window is frontmost + [docWindow makeKeyWindow]; + }); +} + +/** * Provide a simple alias of NSBeginAlertSheet, 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 |