From 0d1fff4494127c5676067c2c9bef597e7bc0ca94 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 21 Jan 2010 14:15:33 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20call=20to=20update=20the=20completi?= =?UTF-8?q?on=20list=20to=20neuralgic=20places=20-=20next=20steps=20to=20m?= =?UTF-8?q?inimize=20the=20traffic=20-=20ie=20manipulating=20the=20dict=20?= =?UTF-8?q?directly=20without=20querying=20-=20follows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 10 +++++++++- Source/TableDocument.m | 8 ++++++++ Source/TableSource.m | 3 +++ Source/TablesList.m | 26 +++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 7378253a..036d221b 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -204,7 +204,15 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // Add structural db/table/field data to completions list or fallback to gathering TablesList data NSDictionary *dbs = [NSDictionary dictionaryWithDictionary:[mySQLConnection getDbStructure]]; if(dbs != nil && [dbs count]) { - NSArray *allDbs = [dbs allKeys]; + NSMutableArray *allDbs = [[NSMutableArray array] autorelease]; + [allDbs addObjectsFromArray:[dbs allKeys]]; + + // Add database names having no tables since they don't appear in the information_schema + if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allDatabaseNames"] != nil) + for(id db in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allDatabaseNames"]) + if(![allDbs containsObject:db]) + [allDbs addObject:db]; + NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES selector:@selector(localizedCompare:)]; NSMutableArray *sortedDbs = [[NSMutableArray array] autorelease]; [sortedDbs addObjectsFromArray:[allDbs sortedArrayUsingDescriptors:[NSArray arrayWithObject:desc]]]; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 8d9bdca7..d0410044 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1143,12 +1143,20 @@ if ([contextInfo isEqualToString:@"removeDatabase"]) { if (returnCode == NSAlertDefaultReturn) { [self _removeDatabase]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + } } // Add a new database else if ([contextInfo isEqualToString:@"addDatabase"]) { if (returnCode == NSOKButton) { [self _addDatabase]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + } else { // reset chooseDatabaseButton if([[self database] length]) diff --git a/Source/TableSource.m b/Source/TableSource.m index 1fd0cd44..1aa6185e 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -771,6 +771,9 @@ fetches the result as an array with a dictionary for each row in it // Mark the content table for refresh [tablesListInstance setContentRequiresReload:YES]; + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + return YES; } else { diff --git a/Source/TablesList.m b/Source/TablesList.m index 645e2305..e784f862 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -1315,7 +1315,10 @@ // Set window title [tableWindow setTitle:[tableDocumentInstance displaySPName]]; - } + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + + } else { // Error while renaming alertSheetOpened = YES; @@ -1871,6 +1874,10 @@ [tableWindow setTitle:[tableDocumentInstance displaySPName]]; [tablesListView deselectAll:self]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + } /** @@ -1965,6 +1972,10 @@ [self updateFilter:self]; [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; [self updateSelectionWithTaskString:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), selectedTableName]]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + } else { // Error while creating new table @@ -2154,6 +2165,10 @@ [self updateFilter:self]; [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; [self updateSelectionWithTaskString:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), selectedTableName]]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + } } } @@ -2181,6 +2196,10 @@ selectedTableName = [[NSString alloc] initWithString:[tableRenameField stringValue]]; [tablesListView reloadData]; [self updateSelectionWithTaskString:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), selectedTableName]]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + return; } } else { @@ -2243,12 +2262,17 @@ selectedTableName = [[NSString alloc] initWithString:[tableRenameField stringValue]]; [tablesListView reloadData]; [self updateSelectionWithTaskString:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), selectedTableName]]; + + // Query the structure of all databases in the background (mainly for completion) + [NSThread detachNewThreadSelector:@selector(queryDbStructure) toTarget:mySQLConnection withObject:nil]; + return; } } // Set window title [tableWindow setTitle:[tableDocumentInstance displaySPName]]; + } /* -- cgit v1.2.3