From e19f96073ffeaa6b0ae60f67206695e271ce70cc Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 24 Sep 2009 09:49:45 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20issue=20if=20after=20displaying=20a?= =?UTF-8?q?=20sheet=20for=20renaming/duplicating/adding=20a=20table=20an?= =?UTF-8?q?=20error=20sheet=20will=20be=20ordered=20out=20(order=20out=20t?= =?UTF-8?q?he=20first=20sheet=20explicitly=20in=20beforehand)=20-=20this?= =?UTF-8?q?=20solves=20issue=20418=20=E2=80=A2=20improved=20table=20name?= =?UTF-8?q?=20check=20for=20renaming/duplicating/adding=20a=20table=20-=20?= =?UTF-8?q?it=20checks=20for=20trailing=20white=20spaces=20since=20'foo=20?= =?UTF-8?q?=20=20'=20is=20not=20valid=20-=20it=20checks=20for=20length=20-?= =?UTF-8?q?=20it=20checks=20whether=20the=20entered=20table=20name=20doesn?= =?UTF-8?q?'t=20occur=20as=20table/view=20name=20in=20the=20current=20data?= =?UTF-8?q?base=20(case-insensitively=20and=20only=20while=20entering=20th?= =?UTF-8?q?e=20name=20in=20sheets)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TablesList.m | 58 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file 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 -- cgit v1.2.3