From a24e9c697049bacb587835153e2ebb4764fff008 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 23 Feb 2010 01:26:33 +0000 Subject: Fix Issue #574 (foreign key links not working after first use): - Move foreign key reference loading into it's own task and set state modification markers to allow it to override the table state history - Rename modifyingHistoryState to modifyingState now the usge has broadened slightly --- Source/TableContent.m | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'Source/TableContent.m') diff --git a/Source/TableContent.m b/Source/TableContent.m index a0e2d610..3a736a90 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -1528,17 +1528,33 @@ if ([tableDocumentInstance isWorking]) return; if ([theArrowCell getClickedColumn] == NSNotFound || [theArrowCell getClickedRow] == NSNotFound) return; + + // Check whether a save of the current row is required. + if ( ![self saveRowOnDeselect] ) return; + + // If on the main thread, fire up a thread to perform the load while keeping the modification flag + [tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Loading reference...", @"Loading referece task string")]; + if ([NSThread isMainThread]) { + [NSThread detachNewThreadSelector:@selector(clickLinkArrowTask:) toTarget:self withObject:theArrowCell]; + } else { + [self clickLinkArrowTask:theArrowCell]; + } +} +- (void)clickLinkArrowTask:(SPTextAndLinkCell *)theArrowCell +{ + NSAutoreleasePool *linkPool = [[NSAutoreleasePool alloc] init]; NSUInteger dataColumnIndex = [[[[tableContentView tableColumns] objectAtIndex:[theArrowCell getClickedColumn]] identifier] integerValue]; // Ensure the clicked cell has foreign key details available NSDictionary *refDictionary = [[dataColumns objectAtIndex:dataColumnIndex] objectForKey:@"foreignkeyreference"]; - if (!refDictionary) return; - - // Check whether a save of the current row is required. - if ( ![self saveRowOnDeselect] ) return; + if (!refDictionary) { + [linkPool release]; + return; + } - // Save existing scroll position and details + // Save existing scroll position and details and mark that state is being modified [spHistoryControllerInstance updateHistoryEntries]; + [spHistoryControllerInstance setModifyingState:YES]; NSString *targetFilterValue = [tableValues cellDataAtRow:[theArrowCell getClickedRow] column:dataColumnIndex]; @@ -1569,6 +1585,14 @@ [self setFiltersToRestore:nil]; } } + + // End state and ensure a new history entry + [spHistoryControllerInstance setModifyingState:NO]; + [spHistoryControllerInstance updateHistoryEntries]; + + // Empty the loading pool and exit the thread + [tableDocumentInstance endTask]; + [linkPool drain]; } /** -- cgit v1.2.3