From 1b2508ed0b5489ec2abe1dd148d1a208bf67bd40 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 13 Aug 2010 10:51:08 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Navigator=20-=20speed=20up=20tree=20display?= =?UTF-8?q?=20by=20caching=20the=20sort=20order=20of=20dictionary=20keys?= =?UTF-8?q?=20(only=20for=20more=20than=2050)=20-=20this=20speeds=20up=20t?= =?UTF-8?q?he=20entire=20Navigator=20GUI=20response=20enormously=20-=20fix?= =?UTF-8?q?=20the=20fighting=20refresh=20calls=20in=20sync=20mode=20if=20u?= =?UTF-8?q?ser=20double-clicked=20at=20an=20item=20in=20the=20Navigator=20?= =?UTF-8?q?which=20ended=20up=20in=20an=20unstable=20tree=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPNavigatorController.h | 3 +- Source/SPNavigatorController.m | 65 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 10 deletions(-) (limited to 'Source') diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h index a664212d..2338b91a 100644 --- a/Source/SPNavigatorController.h +++ b/Source/SPNavigatorController.h @@ -43,14 +43,13 @@ NSMutableDictionary *allSchemaKeys; NSMutableArray *infoArray; NSMutableArray *updatingConnections; - NSMutableDictionary *expandStatus1; NSMutableDictionary *expandStatus2; + NSMutableDictionary *cachedSortedKeys; NSString *selectedKey2; NSRect selectionViewPort2; BOOL ignoreUpdate; BOOL isFiltered; - BOOL isFiltering; NSImage *connectionIcon; diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m index 1cac11c2..191e7043 100644 --- a/Source/SPNavigatorController.m +++ b/Source/SPNavigatorController.m @@ -75,6 +75,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte allSchemaKeys = [[NSMutableDictionary alloc] init]; schemaData = [[NSMutableDictionary alloc] init]; expandStatus2 = [[NSMutableDictionary alloc] init]; + cachedSortedKeys = [[NSMutableDictionary alloc] init]; infoArray = [[NSMutableArray alloc] init]; updatingConnections = [[NSMutableArray alloc] init]; selectedKey2 = @""; @@ -99,6 +100,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte if(infoArray) [infoArray release]; if(updatingConnections) [updatingConnections release]; if(expandStatus2) [expandStatus2 release]; + if(cachedSortedKeys) [cachedSortedKeys release]; [connectionIcon release]; [databaseIcon release]; [tableIcon release]; @@ -315,6 +317,12 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte } } +- (void)_setSyncButtonOn +{ + [syncButton setState:NSOnState]; + [self syncButtonAction:self]; +} + - (void)selectInActiveDocumentItem:(id)item fromView:(id)outlineView { // Do nothing for connection root item yet @@ -351,9 +359,17 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte } if([[doc connectionID] isEqualToString:[pathArray objectAtIndex:0]]) { + // TODO: in sync mode switch it off while selecting the item in the doc and re-enable it after a delay of one 0.1sec + // to avoid gui rendering problems + NSInteger oldState = [syncButton state]; + [syncButton setState:NSOffState]; + // Select the database and table [doc selectDatabase:[pathArray objectAtIndex:1] item:([pathArray count] > 2)?[pathArray objectAtIndex:2]:nil]; + if(oldState == NSOnState) + [self performSelector:@selector(_setSyncButtonOn) withObject:nil afterDelay:0.1]; + } else { [SPTooltip showWithObject:NSLocalizedString(@"The connection of the active connection window is not identical.", @"the connection of the active connection window is not identical tooltip") @@ -387,6 +403,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte if([[self window] isVisible]) { [self saveSelectedItems]; [infoArray removeAllObjects]; + [cachedSortedKeys removeAllObjects]; } @@ -552,6 +569,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte [allSchemaKeys removeObjectForKey:connectionID]; [updatingConnections removeAllObjects]; [infoArray removeAllObjects]; + [cachedSortedKeys removeAllObjects]; [expandStatus2 removeAllObjects]; [outlineSchema2 reloadData]; selectedKey2 = @""; @@ -677,18 +695,12 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte } -- (void)_expandItemOutlineSchema2AfterReloading -{ - [outlineSchema2 expandItem:[outlineSchema2 itemAtRow:0] expandChildren:YES]; -} - - (void)reloadAfterFiltering { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; isFiltering = YES; [outlineSchema2 reloadData]; - // [self performSelectorOnMainThread:@selector(_expandItemOutlineSchema2AfterReloading) withObject:nil waitUntilDone:YES]; - [self performSelector:@selector(_expandItemOutlineSchema2AfterReloading) onThread:[NSThread currentThread] withObject:nil waitUntilDone:YES modes:[NSArray arrayWithObjects: NSDefaultRunLoopMode, nil]]; + [outlineSchema2 expandItem:[outlineSchema2 itemAtRow:0] expandChildren:YES]; isFiltering = NO; [pool release]; } @@ -774,7 +786,44 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte } if ([item isKindOfClass:NSDictionaryClass]) { - return [item objectForKey:NSArrayObjectAtIndex([(NSArray*)objc_msgSend(item, @selector(allKeys)) sortedArrayUsingFunction:compareStrings context:nil],index)]; + + NSArray *allKeys = (NSArray*)objc_msgSend(item, @selector(allKeys)); + + // If item contains more than 50 keys store the sort order and use the cached data to speed up + // the displaying of the tree data + if(!isFiltered && [allKeys count] > 50 && [outlineView parentForItem:item]) { + + // Get the parent + id parentObject = [outlineView parentForItem:item]; + + // No parent return the child by using the normal sort routine + if(!parentObject || ![parentObject isKindOfClass:NSDictionaryClass]) + return [item objectForKey:NSArrayObjectAtIndex([allKeys sortedArrayUsingFunction:compareStrings context:nil],index)]; + + // Get the parent key name for storing + id parentKeys = [parentObject allKeysForObject:item]; + if(parentKeys && [parentKeys count] == 1) { + + NSString *itemRef = [NSArrayObjectAtIndex(parentKeys,0) description]; + + // For safety reasons + if(!itemRef) + return [item objectForKey:NSArrayObjectAtIndex([allKeys sortedArrayUsingFunction:compareStrings context:nil],index)]; + + // Not yet cached so do it + if(![cachedSortedKeys objectForKey:itemRef]) + [cachedSortedKeys setObject:[allKeys sortedArrayUsingFunction:compareStrings context:nil] forKey:itemRef]; + + return [item objectForKey:NSArrayObjectAtIndex([cachedSortedKeys objectForKey:itemRef],index)]; + + } + + // If something failed return the child by using the normal way + return [item objectForKey:NSArrayObjectAtIndex([allKeys sortedArrayUsingFunction:compareStrings context:nil],index)]; + + } else { + return [item objectForKey:NSArrayObjectAtIndex([allKeys sortedArrayUsingFunction:compareStrings context:nil],index)]; + } } else if ([item isKindOfClass:[NSArray class]]) { -- cgit v1.2.3