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/TablesList.m | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'Source/TablesList.m') 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