aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-02-23 01:26:33 +0000
committerrowanbeentje <rowan@beent.je>2010-02-23 01:26:33 +0000
commita24e9c697049bacb587835153e2ebb4764fff008 (patch)
treebab464b0eb1c44bb35ed745d41ba2e46beb9350d
parentc11169058366ca679789bc82cf1b3ca8ed496967 (diff)
downloadsequelpro-a24e9c697049bacb587835153e2ebb4764fff008.tar.gz
sequelpro-a24e9c697049bacb587835153e2ebb4764fff008.tar.bz2
sequelpro-a24e9c697049bacb587835153e2ebb4764fff008.zip
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
-rw-r--r--Source/SPHistoryController.h4
-rw-r--r--Source/SPHistoryController.m16
-rw-r--r--Source/TableContent.h1
-rw-r--r--Source/TableContent.m34
-rw-r--r--Source/TableDocument.m6
5 files changed, 43 insertions, 18 deletions
diff --git a/Source/SPHistoryController.h b/Source/SPHistoryController.h
index 0b2d50d9..dd5c7133 100644
--- a/Source/SPHistoryController.h
+++ b/Source/SPHistoryController.h
@@ -45,12 +45,12 @@ enum sphistory_view_types
NSMutableArray *history;
NSMutableDictionary *tableContentStates;
NSUInteger historyPosition;
- BOOL modifyingHistoryState;
+ BOOL modifyingState;
}
@property (readonly) NSUInteger historyPosition;
@property (readonly) NSMutableArray *history;
-@property (readwrite, assign) BOOL modifyingHistoryState;
+@property (readwrite, assign) BOOL modifyingState;
// Interface interaction
- (void) updateToolbarItem;
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
index 2c1a657f..04d8a765 100644
--- a/Source/SPHistoryController.m
+++ b/Source/SPHistoryController.m
@@ -32,7 +32,7 @@
@synthesize history;
@synthesize historyPosition;
-@synthesize modifyingHistoryState;
+@synthesize modifyingState;
#pragma mark Setup and teardown
@@ -45,7 +45,7 @@
history = [[NSMutableArray alloc] init];
tableContentStates = [[NSMutableDictionary alloc] init];
historyPosition = NSNotFound;
- modifyingHistoryState = NO;
+ modifyingState = NO;
}
return self;
}
@@ -183,7 +183,7 @@
{
// Don't modify anything if we're in the process of restoring an old history state
- if (modifyingHistoryState) return;
+ if (modifyingState) return;
// Work out the current document details
NSString *theDatabase = [theDocument database];
@@ -298,7 +298,7 @@
NSAutoreleasePool *loadPool = [[NSAutoreleasePool alloc] init];
NSUInteger position = [positionNumber unsignedIntegerValue];
- modifyingHistoryState = YES;
+ modifyingState = YES;
// Update the position and extract the history entry
historyPosition = position;
@@ -317,7 +317,7 @@
&& [[historyEntry objectForKey:@"view"] integerValue] == [self currentlySelectedView] == SP_VIEW_CONTENT)
{
[tableContentInstance loadTable:[historyEntry objectForKey:@"table"]];
- modifyingHistoryState = NO;
+ modifyingState = NO;
[self updateToolbarItem];
[theDocument endTask];
[loadPool drain];
@@ -379,7 +379,7 @@
}
}
- modifyingHistoryState = NO;
+ modifyingState = NO;
[self updateToolbarItem];
// End the task
@@ -394,7 +394,7 @@
- (void) abortEntryLoadWithPool:(NSAutoreleasePool *)pool
{
NSBeep();
- modifyingHistoryState = NO;
+ modifyingState = NO;
[theDocument endTask];
if (pool) [pool drain];
}
@@ -421,7 +421,7 @@
NSDictionary *contentState;
// Return if the history state is currently being modified
- if (modifyingHistoryState) return;
+ if (modifyingState) return;
// Return if no database or table are selected
if (!theDatabase || !theTable) return;
diff --git a/Source/TableContent.h b/Source/TableContent.h
index 1b9e4af6..2e45ac59 100644
--- a/Source/TableContent.h
+++ b/Source/TableContent.h
@@ -137,6 +137,7 @@
// Additional methods
- (void)setConnection:(MCPConnection *)theConnection;
- (void)clickLinkArrow:(SPTextAndLinkCell *)theArrowCell;
+- (void)clickLinkArrowTask:(SPTextAndLinkCell *)theArrowCell;
- (IBAction)setCompareTypes:(id)sender;
- (void)processResultIntoDataStorage:(MCPStreamingResult *)theResult approximateRowCount:(NSUInteger)targetRowCount;
- (BOOL)addRowToDB;
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];
}
/**
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 67d30f71..25fa50a0 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -991,10 +991,10 @@
NSAutoreleasePool *taskPool = [[NSAutoreleasePool alloc] init];
// Save existing scroll position and details, and ensure no duplicate entries are created as table list changes
- BOOL historyStateChanging = [spHistoryControllerInstance modifyingHistoryState];
+ BOOL historyStateChanging = [spHistoryControllerInstance modifyingState];
if (!historyStateChanging) {
[spHistoryControllerInstance updateHistoryEntries];
- [spHistoryControllerInstance setModifyingHistoryState:YES];
+ [spHistoryControllerInstance setModifyingState:YES];
}
// show error on connection failed
@@ -1018,7 +1018,7 @@
// Add a history entry
if (!historyStateChanging) {
- [spHistoryControllerInstance setModifyingHistoryState:NO];
+ [spHistoryControllerInstance setModifyingState:NO];
[spHistoryControllerInstance updateHistoryEntries];
}