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/TablesList.m | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'Source/TablesList.m') diff --git a/Source/TablesList.m b/Source/TablesList.m index 7bb5ae48..c5102121 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -697,9 +697,15 @@ return; } - // Otherwise, set up a task and fire up a thread to deal with view changes and data loading + // Otherwise, set up a task [tableDocumentInstance startTaskWithDescription:taskString]; - [NSThread detachNewThreadSelector:@selector(updateSelectionTask) toTarget:self withObject:nil]; + + // If on the main thread, fire up a thread to deal with view changes and data loading, else perform inline + if ([NSThread isMainThread]) { + [NSThread detachNewThreadSelector:@selector(updateSelectionTask) toTarget:self withObject:nil]; + } else { + [self updateSelectionTask]; + } } - (void) updateSelectionTask @@ -1294,8 +1300,8 @@ - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView { - // Don't allow selection changes while performing a task - if ([tableDocumentInstance isWorking]) return NO; + // Don't allow selection changes while performing a task. + if (!tableListIsSelectable) return NO; // End editing (otherwise problems when user hits reload button) [tableWindow endEditingFor:nil]; @@ -1318,6 +1324,9 @@ - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { + // Reset selectability after change if necessary + if ([tableDocumentInstance isWorking]) tableListIsSelectable = NO; + // Perform no action if the selected table hasn't actually changed - reselection etc if ([tablesListView numberOfSelectedRows] == 1 && [[filteredTables objectAtIndex:[tablesListView selectedRow]] length] @@ -1405,12 +1414,16 @@ /** * Loads structure or source if tab selected the first time, - * using a threaded load. + * using a threaded load if currently on the main thread. */ - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem { [tableDocumentInstance startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading %@...", @"Loading table task string"), selectedTableName]]; - [NSThread detachNewThreadSelector:@selector(loadTabTask:) toTarget:self withObject:tabViewItem]; + if ([NSThread isMainThread]) { + [NSThread detachNewThreadSelector:@selector(loadTabTask:) toTarget:self withObject:tabViewItem]; + } else { + [self loadTabTask:tabViewItem]; + } } - (void)loadTabTask:(NSTabViewItem *)tabViewItem { @@ -1595,6 +1608,7 @@ */ - (void) startDocumentTaskForTab:(NSNotification *)aNotification { + tableListIsSelectable = NO; [toolbarAddButton setEnabled:NO]; [toolbarActionsButton setEnabled:NO]; [toolbarReloadButton setEnabled:NO]; @@ -1605,11 +1619,20 @@ */ - (void) endDocumentTaskForTab:(NSNotification *)aNotification { + tableListIsSelectable = YES; [toolbarAddButton setEnabled:YES]; [toolbarActionsButton setEnabled:YES]; [toolbarReloadButton setEnabled:YES]; } +/** + * Set the table list to selectable or not during the task process. + */ +- (void) setTableListSelectability:(BOOL)isSelectable +{ + tableListIsSelectable = isSelectable; +} + #pragma mark - #pragma mark SplitView Delegate Methods @@ -1636,6 +1659,7 @@ contentLoaded = NO; statusLoaded = NO; isTableListFiltered = NO; + tableListIsSelectable = YES; tableListContainsViews = NO; selectedTableType = SP_TABLETYPE_NONE; selectedTableName = nil; -- cgit v1.2.3