From 74cb1152eeb0dcc83f12ea6cf040eacc4e15c551 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 25 Mar 2010 08:59:35 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Navigator=20-=20make=20usage=20of=20a=20not?= =?UTF-8?q?ification=20sent=20by=20the=20[MCPConnection=20queryDbStructure?= =?UTF-8?q?]=20to=20update=20the=20navigator,=20and=20this=20decouples=20a?= =?UTF-8?q?=20doc=20window=20and=20MCPConnection=20from=20the=20navigator?= =?UTF-8?q?=20-=20minimized=20the=20tree=20update=20-=20now=20connectionID?= =?UTF-8?q?-based=20-=20any=20tree=20update=20will=20be=20now=20performed?= =?UTF-8?q?=20on=20main=20thread=20and=20waits=20until=20done=20to=20avoid?= =?UTF-8?q?=20'overlapping'=20updates=20triggered=20by=20different=20notif?= =?UTF-8?q?ications=20which=20normally=20ended=20up=20in=20an=20inchoate?= =?UTF-8?q?=20tree=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 4 +- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 10 ++--- Source/SPNavigatorController.h | 4 +- Source/SPNavigatorController.m | 45 ++++++++++++++++------ Source/TableDocument.h | 1 - Source/TableDocument.m | 12 +----- 6 files changed, 42 insertions(+), 34 deletions(-) diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 25ef7d36..5fa3fe86 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -67,9 +67,7 @@ static inline NSData* NSStringDataUsingLossyEncoding(NSString* self, NSInteger e - (NSString *)onReconnectShouldUseEncoding:(id)connection; - (void)noConnectionAvailable:(id)connection; - (MCPConnectionCheck)connectionLost:(id)connection; -- (void)updateNavigator:(id)sender; -- (NSString *)connectionID; - +- (NSString*)connectionID; @end @interface MCPConnection : NSObject diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 94fb4434..0685d162 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -44,7 +44,7 @@ const char *kMCPConnectionDefaultSocket = MYSQL_UNIX_ADDR; const NSUInteger kMCPConnection_Not_Inited = 1000; const NSUInteger kLengthOfTruncationForLog = 100; -static BOOL sTruncateLongFieldInLogs = YES; +static BOOL sTruncateLongFieldInLogs = YES; /** * Privte API @@ -1365,7 +1365,7 @@ void performThreadedKeepAlive(void *ptr) // Reset the query cancelled boolean queryCancelled = NO; - + // If no connection is present, return nil. if (!mConnected) { // Write a log entry @@ -2033,12 +2033,12 @@ void performThreadedKeepAlive(void *ptr) } uniqueDbIdentifier = [[NSDictionary dictionaryWithDictionary:uniqueIdentifier] retain]; - - if(delegate && [delegate respondsToSelector:@selector(updateNavigator:)]) - [[self delegate] updateNavigator:self]; + // Notify that the structure querying has been performed + [[NSNotificationCenter defaultCenter] postNotificationName:@"SPDBStructureWasUpdated" object:delegate]; isQueryingDbStructure = NO; [queryPool release]; + return; } mysql_close(structConnection); diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h index 09507464..94e8b6a3 100644 --- a/Source/SPNavigatorController.h +++ b/Source/SPNavigatorController.h @@ -57,13 +57,13 @@ + (SPNavigatorController *)sharedNavigatorController; - (IBAction)outlineViewAction:(id)sender; -- (IBAction)updateEntries:(id)sender; - (IBAction)reloadAllStructures:(id)sender; - (IBAction)filterTree:(id)sender; - (IBAction)syncButtonAction:(id)sender; +- (void)updateEntriesForConnection:(NSString*)connectionID; - (NSString*)tableInfoLabelForIndex:(NSInteger)index ofType:(NSInteger)type; - +- (void)updateNavigator:(NSNotification *)aNotification; - (void)restoreSelectedItems; - (void)setIgnoreUpdate:(BOOL)flag; - (void)selectPath:(NSString*)schemaPath; diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m index 6295058c..64e54053 100644 --- a/Source/SPNavigatorController.m +++ b/Source/SPNavigatorController.m @@ -82,6 +82,7 @@ static SPNavigatorController *sharedNavigatorController = nil; - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; if(schemaData) [schemaData release]; if(schemaDataUnFiltered) [schemaDataUnFiltered release]; if(infoArray) [infoArray release]; @@ -117,6 +118,9 @@ static SPNavigatorController *sharedNavigatorController = nil; [outlineSchema2 setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES]; [outlineSchema2 setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNavigator:) + name:@"SPDBStructureWasUpdated" object:nil]; + } - (NSString *)windowFrameAutosaveName @@ -285,7 +289,9 @@ static SPNavigatorController *sharedNavigatorController = nil; if(schemaData && [schemaData objectForKey:connectionID]) { NSInteger docCounter = 0; - + + // Detect if more than one connection windows with the connectionID are open. + // If so, don't remove it. if ([[[NSDocumentController sharedDocumentController] documents] count]) { for(id doc in [[NSDocumentController sharedDocumentController] documents]) { if(![[doc valueForKeyPath:@"mySQLConnection"] isConnected]) continue; @@ -342,10 +348,17 @@ static SPNavigatorController *sharedNavigatorController = nil; } } -#pragma mark - -#pragma mark IBActions +- (void)updateNavigator:(NSNotification *)aNotification +{ + id object = [aNotification object]; + + if([object isKindOfClass:[TableDocument class]]) + [self performSelectorOnMainThread:@selector(updateEntriesForConnection:) withObject:[object connectionID] waitUntilDone:YES]; + else + [self performSelectorOnMainThread:@selector(updateEntriesForConnection:) withObject:nil waitUntilDone:YES]; +} -- (IBAction)updateEntries:(id)sender; +- (void)updateEntriesForConnection:(NSString*)connectionID { if(ignoreUpdate) { @@ -356,7 +369,10 @@ static SPNavigatorController *sharedNavigatorController = nil; [self saveSelectedItems]; [infoArray removeAllObjects]; - [schemaData removeAllObjects]; + if(connectionID) + [schemaData removeObjectForKey:connectionID]; + else + [schemaData removeAllObjects]; [outlineSchema1 reloadData]; [outlineSchema2 reloadData]; @@ -364,19 +380,21 @@ static SPNavigatorController *sharedNavigatorController = nil; if ([[[NSDocumentController sharedDocumentController] documents] count]) { for(id doc in [[NSDocumentController sharedDocumentController] documents]) { - if(![[doc valueForKeyPath:@"mySQLConnection"] isConnected]) continue; + id theConnection = [doc valueForKeyPath:@"mySQLConnection"]; + + if(!theConnection || ![theConnection isConnected]) continue; NSString *connectionName = [doc connectionID]; - if(!connectionName || [connectionName isEqualToString:@"_"]) continue; + if(!connectionName || [connectionName isEqualToString:@"_"] || (connectionID && ![connectionName isEqualToString:connectionID]) ) continue; if(![schemaData objectForKey:connectionName]) { - if([[doc valueForKeyPath:@"mySQLConnection"] getDbStructure] && [[[doc valueForKeyPath:@"mySQLConnection"] getDbStructure] objectForKey:connectionName]) { - [schemaData setObject:[[[doc valueForKeyPath:@"mySQLConnection"] getDbStructure] objectForKey:connectionName] forKey:connectionName]; + if([theConnection getDbStructure] && [[theConnection getDbStructure] objectForKey:connectionName]) { + [schemaData setObject:[[theConnection getDbStructure] objectForKey:connectionName] forKey:connectionName]; } else { - if([[doc valueForKeyPath:@"mySQLConnection"] serverMajorVersion] > 4) { + if([theConnection serverMajorVersion] > 4) { [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data loaded yet", connectionName]]; } else { [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data for this server version", connectionName]]; @@ -391,7 +409,6 @@ static SPNavigatorController *sharedNavigatorController = nil; [self restoreExpandStatus]; [self restoreSelectedItems]; - } [self syncButtonAction:self]; @@ -399,6 +416,10 @@ static SPNavigatorController *sharedNavigatorController = nil; } +#pragma mark - +#pragma mark IBActions + + - (IBAction)reloadAllStructures:(id)sender { @@ -793,7 +814,7 @@ static SPNavigatorController *sharedNavigatorController = nil; - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row { // Use first row as dummy to increase the distance between content and header - return (row == 0) ? 5.0 : 15; //[tableView rowHeight]; + return (row == 0) ? 5.0 : 16.0; } - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 5178ef56..18b8be2a 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -251,7 +251,6 @@ - (void)showConsole:(id)sender; - (IBAction)showNavigator:(id)sender; - (IBAction)toggleNavigator:(id)sender; -- (void)updateNavigator:(id)sender; // Accessor methods - (NSString *)host; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 949f2a68..0a68eda2 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1148,7 +1148,7 @@ BOOL isNavigatorVisible = [[[SPNavigatorController sharedNavigatorController] window] isVisible]; if(!isNavigatorVisible) { - [[SPNavigatorController sharedNavigatorController] updateEntries:self]; + [[SPNavigatorController sharedNavigatorController] updateEntriesForConnection:[self connectionID]]; } // Show or hide the navigator @@ -1166,16 +1166,6 @@ } } -/* - * Called from MCPConnection or self to inform the navigator that an instance invoked queryDbStructure - * or a window was closed - */ -- (void)updateNavigator:(id)sender -{ - if([[[SPNavigatorController sharedNavigatorController] window] isVisible]) - [[SPNavigatorController sharedNavigatorController] updateEntries:self]; -} - #pragma mark - #pragma mark Task progress and notification methods -- cgit v1.2.3