aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-24 09:49:45 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-24 09:49:45 +0000
commite19f96073ffeaa6b0ae60f67206695e271ce70cc (patch)
treedd242230862711d911eb95ac453f3f72fc4b17e2
parentda0dba0eae177dcb27993a64ef2fb0e4cd0b018b (diff)
downloadsequelpro-e19f96073ffeaa6b0ae60f67206695e271ce70cc.tar.gz
sequelpro-e19f96073ffeaa6b0ae60f67206695e271ce70cc.tar.bz2
sequelpro-e19f96073ffeaa6b0ae60f67206695e271ce70cc.zip
• fixed issue if after displaying a sheet for renaming/duplicating/adding a table an error sheet will be ordered out (order out the first sheet explicitly in beforehand)
- this solves issue 418 • improved table name check for renaming/duplicating/adding a table - it checks for trailing white spaces since 'foo ' is not valid - it checks for length - it checks whether the entered table name doesn't occur as table/view name in the current database (case-insensitively and only while entering the name in sheets)
-rw-r--r--Source/TablesList.m58
1 files changed, 47 insertions, 11 deletions
diff --git a/Source/TablesList.m b/Source/TablesList.m
index 48a885f8..bfe053c4 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -43,6 +43,7 @@
- (void)addTable;
- (void)copyTable;
- (void)renameTable;
+- (BOOL)isTableNameValid:(NSString *)tableName;
@end
@@ -492,17 +493,22 @@
/**
* Method for alert sheets.
*/
-- (void)sheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
+- (void)sheetDidEnd:(id)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
{
+
+ // Order out current sheet to suppress overlapping of sheets
+ if([sheet respondsToSelector:@selector(orderOut:)])
+ [sheet orderOut:nil];
+
if ([contextInfo isEqualToString:@"addRow"]) {
alertSheetOpened = NO;
}
- else if ([contextInfo isEqualToString:@"removeRow"]) {
+ else if ([contextInfo isEqualToString:@"removeRow"]) {
if (returnCode == NSAlertDefaultReturn) {
[self performSelector:@selector(removeTable) withObject:nil afterDelay:0.0];
}
}
- else if ([contextInfo isEqualToString:@"truncateTable"]) {
+ else if ([contextInfo isEqualToString:@"truncateTable"]) {
if (returnCode == NSAlertDefaultReturn) {
[self truncateTable];
}
@@ -550,19 +556,21 @@
*/
- (void)controlTextDidChange:(NSNotification *)notification
{
+
id object = [notification object];
-
+
if (object == tableNameField) {
- [addTableButton setEnabled:([[tableNameField stringValue] length] > 0)];
+ [addTableButton setEnabled:[self isTableNameValid:[tableNameField stringValue]]];
}
-
- if (object == copyTableNameField) {
- ([copyTableButton setEnabled:([[copyTableNameField stringValue] length] > 0) && (![[self tableName] isEqualToString:[copyTableNameField stringValue]])]);
+
+ else if (object == copyTableNameField) {
+ [copyTableButton setEnabled:[self isTableNameValid:[copyTableNameField stringValue]]];
}
-
- if (object == tableRenameField) {
- ([renameTableButton setEnabled:([[tableRenameField stringValue] length] > 0) && (![[self tableName] isEqualToString:[tableRenameField stringValue]])]);
+
+ else if (object == tableRenameField) {
+ [renameTableButton setEnabled:[self isTableNameValid:[tableRenameField stringValue]]];
}
+
}
/*
@@ -2078,4 +2086,32 @@
[tableWindow setTitle:[tableDocumentInstance displayName]];
}
+/*
+ * Check tableName for length and if the tableName doesn't match
+ * against current database table/view names (case-insensitive).
+ */
+- (BOOL)isTableNameValid:(NSString *)tableName
+{
+ BOOL isValid = YES;
+
+ // Check case-insensitive and delete trailing whitespaces
+ // since 'foo ' or ' ' are not valid table names
+ NSString *fieldStr = [[tableName stringByMatching:@"(.*?)\\s*$" capture:1] lowercaseString];
+
+ // If table name has trailing whitespaces return 'no valid'
+ if([fieldStr length] != [tableName length]) return NO;
+
+ if([fieldStr length] > 0) {
+ for(id table in [self allTableAndViewNames]) {
+ if([fieldStr isEqualToString:[table lowercaseString]]) {
+ isValid = NO;
+ break;
+ }
+ }
+ } else {
+ isValid = NO;
+ }
+ return isValid;
+}
+
@end