From 8f3065bb99ff46ddfcffdd05eb55e09871cad0c9 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 8 Nov 2009 22:58:56 +0000 Subject: - Support nested task levels to allow tasks to overlap - Thread history loading, thus using the nested task elvels and fixing history interaction in recent builds - Thread initial database loads - Improve progress indicator slightly --- Source/SPHistoryController.m | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'Source/SPHistoryController.m') diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m index 7f522b7d..6c2683d0 100644 --- a/Source/SPHistoryController.m +++ b/Source/SPHistoryController.m @@ -51,6 +51,7 @@ - (void) awakeFromNib { tableContentInstance = [theDocument valueForKey:@"tableContentInstance"]; + tablesListInstance = [theDocument valueForKey:@"tablesListInstance"]; } - (void) dealloc @@ -252,6 +253,7 @@ /** * Load a history entry and attempt to return the interface to that state. + * Performs the load in a task which is threaded as necessary. */ - (void) loadEntryAtPosition:(unsigned int)position { @@ -262,6 +264,22 @@ return; } + // Ensure a save of the current state - scroll position, selection - if we're at the last entry + if (historyPosition == [history count] - 1) [self updateHistoryEntries]; + + // Start the task and perform the load + [theDocument startTaskWithDescription:NSLocalizedString(@"Loading history entry...", @"Loading history entry task desc")]; + if ([NSThread isMainThread]) { + [NSThread detachNewThreadSelector:@selector(loadEntryTaskWithPosition:) toTarget:self withObject:[NSNumber numberWithUnsignedInt:position]]; + } else { + [self loadEntryTaskWithPosition:[NSNumber numberWithUnsignedInt:position]]; + } +} +- (void) loadEntryTaskWithPosition:(NSNumber *)positionNumber +{ + NSAutoreleasePool *loadPool = [[NSAutoreleasePool alloc] init]; + unsigned int position = [positionNumber unsignedIntValue]; + modifyingHistoryState = YES; // Update the position and extract the history entry @@ -289,6 +307,10 @@ // Check and set the database if (![[theDocument database] isEqualToString:[historyEntry objectForKey:@"database"]]) { NSPopUpButton *chooseDatabaseButton = [theDocument valueForKey:@"chooseDatabaseButton"]; + [tablesListInstance setTableListSelectability:YES]; + [[tablesListInstance valueForKey:@"tablesListView"] deselectAll:self]; + [theDocument setDatabaseListIsSelectable:YES]; + [tablesListInstance setTableListSelectability:YES]; [chooseDatabaseButton selectItemWithTitle:[historyEntry objectForKey:@"database"]]; [theDocument chooseDatabase:self]; if (![[theDocument database] isEqualToString:[historyEntry objectForKey:@"database"]]) { @@ -298,7 +320,6 @@ // Check and set the table if ([historyEntry objectForKey:@"table"] && ![[theDocument table] isEqualToString:[historyEntry objectForKey:@"table"]]) { - TablesList *tablesListInstance = [theDocument valueForKey:@"tablesListInstance"]; NSArray *tables = [tablesListInstance tables]; if ([tables indexOfObject:[historyEntry objectForKey:@"table"]] == NSNotFound) { return [self abortEntryLoad]; @@ -308,10 +329,10 @@ return [self abortEntryLoad]; } } else if (![historyEntry objectForKey:@"table"] && [theDocument table]) { - TablesList *tablesListInstance = [theDocument valueForKey:@"tablesListInstance"]; + [tablesListInstance setTableListSelectability:YES]; [[tablesListInstance valueForKey:@"tablesListView"] deselectAll:self]; } else { - [[theDocument valueForKey:@"tablesListInstance"] setContentRequiresReload:YES]; + [tablesListInstance setContentRequiresReload:YES]; } // Check and set the view @@ -340,6 +361,10 @@ modifyingHistoryState = NO; [self updateToolbarItem]; + + // End the task + [theDocument endTask]; + [loadPool drain]; } /** -- cgit v1.2.3