From 68168615e8c35c2d5c6e08284dc1478376883d8d Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 22 Nov 2009 15:00:00 +0000 Subject: - Improve upon r1560 by removing a couple of race conditions triggered on encoding changes, status requests, or blob/text lookups on slower connections - Restore first responder in TableContent loads on the main thread to fix a potential crasher --- Source/TableContent.m | 2 +- Source/TablesList.m | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'Source') diff --git a/Source/TableContent.m b/Source/TableContent.m index bcaed509..9d5268c8 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -410,7 +410,7 @@ } // Restore first responder - [tableWindow makeFirstResponder:currentFirstResponder]; + [tableWindow performSelectorOnMainThread:@selector(makeFirstResponder:) withObject:currentFirstResponder waitUntilDone:NO]; // Enable or disable the limit fields according to preference setting if ( [prefs boolForKey:SPLimitResults] ) { diff --git a/Source/TablesList.m b/Source/TablesList.m index eabf062f..de1ce991 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -721,6 +721,7 @@ - (void) updateSelectionTask { NSAutoreleasePool *selectionChangePool = [[NSAutoreleasePool alloc] init]; + NSString *tableEncoding = nil; // Update the selected table name and type if (selectedTableName) [selectedTableName release]; @@ -739,22 +740,12 @@ // Reset the table information caches [tableDataInstance resetAllData]; - if (selectedTableType == SP_TABLETYPE_TABLE) { - [tableDataInstance updateInformationForCurrentTable]; - } else if (selectedTableType == SP_TABLETYPE_VIEW) { - [tableDataInstance updateInformationForCurrentView]; - } - - // Notify listeners of the table change now that the state is fully set up. - [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:tableDocumentInstance]; - - [separatorTableMenuItem setHidden:NO]; - [separatorTableContextMenuItem setHidden:NO]; + // Check the encoding if appropriate to determine if an encoding change and reset is required if( selectedTableType == SP_TABLETYPE_VIEW || selectedTableType == SP_TABLETYPE_TABLE) { // tableEncoding == nil indicates that there was an error while retrieving table data - NSString *tableEncoding = [tableDataInstance tableEncoding]; + tableEncoding = [tableDataInstance tableEncoding]; // If encoding is set to Autodetect, update the connection character set encoding // based on the newly selected table's encoding - but only if it differs from the current encoding. @@ -762,9 +753,21 @@ if (tableEncoding != nil && ![tableEncoding isEqualToString:[tableDocumentInstance connectionEncoding]]) { [tableDocumentInstance setConnectionEncoding:tableEncoding reloadingViews:NO]; [tableDataInstance resetAllData]; + tableEncoding = [tableDataInstance tableEncoding]; } } - + } + + // Ensure status information is cached on the working thread + [tableDataInstance updateStatusInformationForCurrentTable]; + + // Notify listeners of the table change now that the state is fully set up. + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:tableDocumentInstance]; + + [separatorTableMenuItem setHidden:NO]; + [separatorTableContextMenuItem setHidden:NO]; + + if( selectedTableType == SP_TABLETYPE_VIEW || selectedTableType == SP_TABLETYPE_TABLE) { if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) { [tableSourceInstance loadTable:selectedTableName]; structureLoaded = YES; -- cgit v1.2.3