Skip to content

Commit 23e86b8

Browse files
committed
Merge pull request #2210 from nacho4d/feature/2105-part1
Feature/2105 part1
2 parents cf83388 + c10748c commit 23e86b8

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

Source/SPAlertSheets.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ void SPOnewayAlertSheet(
6161
NSString *title,
6262
NSString *defaultButton,
6363
NSWindow *docWindow,
64-
NSString *msg
64+
NSString *msg,
65+
NSAlertStyle alertStyle
6566
);

Source/SPAlertSheets.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ + (void)beginWaitingAlertSheetWithTitle:(NSString *)title
149149
* Because of that there is no way to set a delegate and callback method
150150
* and there is only one default button.
151151
* If nil is passed as the button title it will be changed to @"OK".
152+
* If nil is passed as the window NSAlert will be modal
152153
*/
153154
void SPOnewayAlertSheet(
154155
NSString *title,
155156
NSString *defaultButton,
156157
NSWindow *docWindow,
157-
NSString *msg)
158+
NSString *msg,
159+
NSAlertStyle alertStyle)
158160
{
159161
NSString *defaultText = (defaultButton)? defaultButton : NSLocalizedString(@"OK", @"OK button");
160162

@@ -168,12 +170,17 @@ void SPOnewayAlertSheet(
168170

169171
// Set the informative message if supplied
170172
if (msg) [alert setInformativeText:msg];
173+
174+
// Set style (Defaults to NSWarningAlertStyle)
175+
[alert setAlertStyle:alertStyle];
171176

172177
// Run the alert
173-
[alert beginSheetModalForWindow:docWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
174-
175-
// Ensure the alerting window is frontmost
176-
[docWindow makeKeyWindow];
178+
if (docWindow) {
179+
[alert beginSheetModalForWindow:docWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
180+
[docWindow makeKeyWindow]; // Ensure the alerting window is frontmost
181+
} else {
182+
[alert runModal];
183+
}
177184
});
178185
}
179186

Source/SPDatabaseDocument.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6162,7 +6162,8 @@ - (void)_selectDatabaseAndItem:(NSDictionary *)selectionDetails
61626162
NSLocalizedString(@"Error", @"error"),
61636163
nil,
61646164
parentWindow,
6165-
[NSString stringWithFormat:NSLocalizedString(@"Unable to select database %@.\nPlease check you have the necessary privileges to view the database, and that the database still exists.", @"message of panel when connection to db failed after selecting from popupbutton"), targetDatabaseName]
6165+
[NSString stringWithFormat:NSLocalizedString(@"Unable to select database %@.\nPlease check you have the necessary privileges to view the database, and that the database still exists.", @"message of panel when connection to db failed after selecting from popupbutton"), targetDatabaseName],
6166+
NSWarningAlertStyle
61666167
);
61676168
}
61686169

Source/SPTableData.m

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ - (NSDictionary *) informationForTable:(NSString *)tableName
492492
NSLocalizedString(@"Error retrieving table information", @"error retrieving table information message"),
493493
nil,
494494
[NSApp mainWindow],
495-
errorMessage
495+
errorMessage,
496+
NSWarningAlertStyle
496497
);
497498

498499
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
@@ -517,7 +518,8 @@ - (NSDictionary *) informationForTable:(NSString *)tableName
517518
NSLocalizedString(@"Permission Denied", @"Permission Denied"),
518519
nil,
519520
[NSApp mainWindow],
520-
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")
521+
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"),
522+
NSWarningAlertStyle
521523
);
522524

523525
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
@@ -568,15 +570,13 @@ - (NSDictionary *) informationForTable:(NSString *)tableName
568570
returningInclusively: NO
569571
ignoringQuotedStrings: NO];
570572
if(fieldName == nil || [fieldName length] == 0) {
571-
#warning NSAlert from background thread! (This whole function needs improvement)
572573
NSBeep();
573-
NSAlert *alert = [[NSAlert alloc] init];
574-
[alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")];
575-
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"%@” couldn't be parsed. You can edit the column setup but the column will not be shown in the Content view; please report this issue to the Sequel Pro team using the Help menu item.", @"%@” couldn't be parsed. You can edit the column setup but the column will not be shown in the Content view; please report this issue to the Sequel Pro team using the Help menu item."), fieldsParser]];
576-
[alert setMessageText:NSLocalizedString(@"Error while parsing CREATE TABLE syntax",@"error while parsing CREATE TABLE syntax")];
577-
[alert setAlertStyle:NSCriticalAlertStyle];
578-
[alert runModal];
579-
[alert release];
574+
SPOnewayAlertSheet(
575+
NSLocalizedString(@"Error while parsing CREATE TABLE syntax",@"error while parsing CREATE TABLE syntax"),
576+
nil,
577+
nil,
578+
[NSString stringWithFormat:NSLocalizedString(@"%@” couldn't be parsed. You can edit the column setup but the column will not be shown in the Content view; please report this issue to the Sequel Pro team using the Help menu item.", @"%@” couldn't be parsed. You can edit the column setup but the column will not be shown in the Content view; please report this issue to the Sequel Pro team using the Help menu item."), fieldsParser],
579+
NSCriticalAlertStyle);
580580
continue;
581581
}
582582
//if the next character is again a backtick, we stumbled across an escaped backtick. we have to continue parsing.
@@ -849,7 +849,8 @@ - (NSDictionary *) informationForView:(NSString *)viewName
849849
NSLocalizedString(@"Error", @"error"),
850850
nil,
851851
[NSApp mainWindow],
852-
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),[mySQLConnection lastErrorMessage]]
852+
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),[mySQLConnection lastErrorMessage]],
853+
NSWarningAlertStyle
853854
);
854855
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
855856
}
@@ -866,7 +867,8 @@ - (NSDictionary *) informationForView:(NSString *)viewName
866867
NSLocalizedString(@"Permission Denied", @"Permission Denied"),
867868
nil,
868869
[NSApp mainWindow],
869-
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")
870+
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"),
871+
NSWarningAlertStyle
870872
);
871873
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
872874
return nil;
@@ -885,7 +887,8 @@ - (NSDictionary *) informationForView:(NSString *)viewName
885887
NSLocalizedString(@"Error", @"error"),
886888
nil,
887889
[NSApp mainWindow],
888-
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), [mySQLConnection lastErrorMessage]]
890+
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), [mySQLConnection lastErrorMessage]],
891+
NSWarningAlertStyle
889892
);
890893
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
891894
}
@@ -996,7 +999,8 @@ - (BOOL)updateStatusInformationForCurrentTable
996999
NSLocalizedString(@"Error", @"error"),
9971000
nil,
9981001
[NSApp mainWindow],
999-
[NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection lastErrorMessage]]
1002+
[NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection lastErrorMessage]],
1003+
NSWarningAlertStyle
10001004
);
10011005
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
10021006
}
@@ -1083,7 +1087,8 @@ - (BOOL) updateTriggersForCurrentTable
10831087
NSLocalizedString(@"Error retrieving trigger information", @"error retrieving trigger information message"),
10841088
nil,
10851089
[NSApp mainWindow],
1086-
[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]]
1090+
[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]],
1091+
NSWarningAlertStyle
10871092
);
10881093
if (triggers) SPClear(triggers);
10891094
if (changeEncoding) [mySQLConnection restoreStoredEncoding];

0 commit comments

Comments
 (0)