From bf7ed8561accb5a3ce2e7cb8f681017adcd8f055 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Wed, 23 Dec 2009 20:08:14 +0000 Subject: In the database drop down, visually separate 'system' databases (i.e. mysql and information_schema) from 'user' databases by placing them at the top. --- Source/TableDocument.m | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 25524389..0bd76f6f 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -909,8 +909,7 @@ */ - (IBAction)setDatabases:(id)sender; { - if (!chooseDatabaseButton) - return; + if (!chooseDatabaseButton) return; [chooseDatabaseButton removeAllItems]; @@ -922,23 +921,43 @@ MCPResult *queryResult = [mySQLConnection listDBs]; - if ([queryResult numOfRows]) { - [queryResult dataSeek:0]; - } - - // if([allDatabases count]) - // [allDatabases removeAllObjects]; - - if(allDatabases) - [allDatabases release]; + if ([queryResult numOfRows]) [queryResult dataSeek:0]; + if (allDatabases) [allDatabases release]; + allDatabases = [[NSMutableArray alloc] initWithCapacity:[queryResult numOfRows]]; + NSMutableArray *systemDatabases = [NSMutableArray array]; + for (int i = 0 ; i < [queryResult numOfRows] ; i++) - [allDatabases addObject:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0)]; + { + NSString *database = NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0); + + // If the database is either information_schema or mysql then it is classed as a system table + if ([database isEqualToString:@"information_schema"] || [database isEqualToString:@"mysql"]) { + [systemDatabases addObject:database]; + } + else { + [allDatabases addObject:database]; + } + } + + // Add system databases + for (NSString *db in systemDatabases) + { + [chooseDatabaseButton addItemWithTitle:db]; + } + + // Add a separator between the system and user databases + if ([systemDatabases count] > 0) { + [[chooseDatabaseButton menu] addItem:[NSMenuItem separatorItem]]; + } - for (id db in allDatabases) + // Add user databases + for (NSString *db in allDatabases) + { [chooseDatabaseButton addItemWithTitle:db]; + } (![self database]) ? [chooseDatabaseButton selectItemAtIndex:0] : [chooseDatabaseButton selectItemWithTitle:[self database]]; } -- cgit v1.2.3