aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-07-19 04:54:32 +0200
committerMax <post@wickenrode.com>2015-10-02 19:30:07 +0200
commitd8acb8faf2c96fd059bef0c17e03279816159447 (patch)
tree9ec7d598eeeba9e5c95e252c56fba39e81586492 /Source
parent2d9145d32e1bc1a2507b503a5314205ee9afcd58 (diff)
downloadsequelpro-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')
-rw-r--r--Source/SPAlertSheets.h7
-rw-r--r--Source/SPAlertSheets.m34
-rw-r--r--Source/SPTableData.m73
3 files changed, 84 insertions, 30 deletions
diff --git a/Source/SPAlertSheets.h b/Source/SPAlertSheets.h
index 50d7bb18..f61d0e38 100644
--- a/Source/SPAlertSheets.h
+++ b/Source/SPAlertSheets.h
@@ -56,3 +56,10 @@ void SPBeginAlertSheet(
void *contextInfo,
NSString *msg
);
+
+void SPOnewayAlertSheet(
+ NSString *title,
+ NSString *defaultButton,
+ NSWindow *docWindow,
+ NSString *msg
+);
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
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 9b641347..cb98183e 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -500,8 +500,12 @@
[tableListInstance updateTables:self];
}
- SPBeginAlertSheet(NSLocalizedString(@"Error retrieving table information", @"error retrieving table information message"), NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [NSApp mainWindow], self, nil, nil, errorMessage);
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Error retrieving table information", @"error retrieving table information message"),
+ nil,
+ [NSApp mainWindow],
+ errorMessage
+ );
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
@@ -521,12 +525,13 @@
// A NULL value indicates that the user does not have permission to view the syntax
if ([[syntaxResult objectAtIndex:1] isNSNull]) {
- [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied")
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")]
- beginSheetModalForWindow:[NSApp mainWindow]
- modalDelegate:self didEndSelector:NULL contextInfo:NULL];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Permission Denied", @"Permission Denied"),
+ nil,
+ [NSApp mainWindow],
+ NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")
+ );
+
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
return nil;
}
@@ -852,10 +857,12 @@
// Check for any errors, but only display them if a connection still exists
if ([mySQLConnection queryErrored]) {
if ([mySQLConnection isConnected]) {
- SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [NSApp mainWindow], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),
- [mySQLConnection lastErrorMessage]]);
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Error", @"error"),
+ nil,
+ [NSApp mainWindow],
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),[mySQLConnection lastErrorMessage]]
+ );
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
return nil;
@@ -867,12 +874,12 @@
// A NULL value indicates that the user does not have permission to view the syntax
if ([syntaxString isNSNull]) {
- [[NSAlert alertWithMessageText:NSLocalizedString(@"Permission Denied", @"Permission Denied")
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")]
- beginSheetModalForWindow:[NSApp mainWindow]
- modalDelegate:self didEndSelector:NULL contextInfo:NULL];
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Permission Denied", @"Permission Denied"),
+ nil,
+ [NSApp mainWindow],
+ NSLocalizedString(@"The creation syntax could not be retrieved due to a permissions error.\n\nPlease check your user permissions with an administrator.", @"Create syntax permission denied detail")
+ );
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
return nil;
}
@@ -886,10 +893,12 @@
// Check for any errors, but only display them if a connection still exists
if ([mySQLConnection queryErrored]) {
if ([mySQLConnection isConnected]) {
- SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [NSApp mainWindow], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),
- [mySQLConnection lastErrorMessage]]);
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Error", @"error"),
+ nil,
+ [NSApp mainWindow],
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), [mySQLConnection lastErrorMessage]]
+ );
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
return nil;
@@ -995,10 +1004,12 @@
// Check for any errors, only displaying them if the connection hasn't been terminated
if ([mySQLConnection queryErrored]) {
if ([mySQLConnection isConnected]) {
- SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [NSApp mainWindow], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"),
- [mySQLConnection lastErrorMessage]]);
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Error", @"error"),
+ nil,
+ [NSApp mainWindow],
+ [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection lastErrorMessage]]
+ );
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
pthread_mutex_unlock(&dataProcessingLock);
@@ -1080,10 +1091,12 @@
// Check for any errors, but only display them if a connection still exists
if ([mySQLConnection queryErrored]) {
if ([mySQLConnection isConnected]) {
- SPBeginAlertSheet(NSLocalizedString(@"Error retrieving trigger information", @"error retrieving trigger information message"), NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [NSApp mainWindow], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving the trigger information for table '%@'. Please try again.\n\nMySQL said: %@", @"error retrieving table information informative message"),
- [tableListInstance tableName], [mySQLConnection lastErrorMessage]]);
+ SPOnewayAlertSheet(
+ NSLocalizedString(@"Error retrieving trigger information", @"error retrieving trigger information message"),
+ nil,
+ [NSApp mainWindow],
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving the trigger information for table '%@'. Please try again.\n\nMySQL said: %@", @"error retrieving table information informative message"), [tableListInstance tableName], [mySQLConnection lastErrorMessage]]
+ );
if (triggers) SPClear(triggers);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}