aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAlertSheets.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-05-09 01:00:23 +0000
committerrowanbeentje <rowan@beent.je>2010-05-09 01:00:23 +0000
commit4144a5e1b78480fd86994a9c255c9a0fb98db48b (patch)
tree144569ffc18dea3b4b3feedf89b04753c1ef53c3 /Source/SPAlertSheets.m
parent1ba45688cf6b851a662429eb770ce4fcea93d1bf (diff)
downloadsequelpro-4144a5e1b78480fd86994a9c255c9a0fb98db48b.tar.gz
sequelpro-4144a5e1b78480fd86994a9c255c9a0fb98db48b.tar.bz2
sequelpro-4144a5e1b78480fd86994a9c255c9a0fb98db48b.zip
Rework alert sheets:
- Change MCPConnection.m to no longer use a reference to tableWindow to attach sheets - instead use a delate error display method if available - Rework TableSource and TableContent sheetDidEnd methods into per-task methods rather than overloading contextInfo - Rework SPAlertSheets to perform actions on the main thread, with the loss of (unused) support for a didDismissSelector. This addresses a number of crashes logged by the crash reporter
Diffstat (limited to 'Source/SPAlertSheets.m')
-rw-r--r--Source/SPAlertSheets.m50
1 files changed, 32 insertions, 18 deletions
diff --git a/Source/SPAlertSheets.m b/Source/SPAlertSheets.m
index ccc8f337..67fb396e 100644
--- a/Source/SPAlertSheets.m
+++ b/Source/SPAlertSheets.m
@@ -25,10 +25,13 @@
#import "SPMainThreadTrampoline.h"
/**
- * Provide a very simple alias of NSBeginAlertSheet with one difference:
- * 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.
+ * 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
+ * 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.
*/
void SPBeginAlertSheet(
NSString *title,
@@ -38,22 +41,33 @@ void SPBeginAlertSheet(
NSWindow *docWindow,
id modalDelegate,
SEL didEndSelector,
- SEL didDismissSelector,
void *contextInfo,
NSString *msg
) {
- NSBeginAlertSheet(
- title,
- defaultButton,
- alternateButton,
- otherButton,
- docWindow,
- modalDelegate,
- didEndSelector,
- didDismissSelector,
- contextInfo,
- [msg stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]
- );
-
+ NSButton *aButton;
+
+ // 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 the informative message if supplied
+ if (msg) [alert setInformativeText:msg];
+
+ // Run the alert on the main thread
+ [[alert onMainThread] beginSheetModalForWindow:docWindow modalDelegate:modalDelegate didEndSelector:didEndSelector contextInfo:contextInfo];
+
+ // Ensure the alerting window is frontmost
[[docWindow onMainThread] makeKeyWindow];
}