From a4b8942109134428b04f355679e410146d07ff89 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Mon, 16 Aug 2010 00:15:28 +0000 Subject: - Apply column autosizing improvements to custom query loading - Move Table Content progress tracking onto the main thread's load timer - Improve thread safety when autosizing - Improve autosize to not contrain wide columns as much in tables where all columns can be shown, or if the column is double-clicked to size. (This completes work on Issue #271 and Issue #272) --- Source/SPTableContent.m | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'Source/SPTableContent.m') diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 26eeb568..795c9970 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -691,14 +691,13 @@ NSUInteger i; NSUInteger dataColumnsCount = [dataColumns count]; BOOL *columnBlobStatuses = malloc(dataColumnsCount * sizeof(BOOL)); + tableLoadTargetRowCount = targetRowCount; // Set up the table updates timer [[self onMainThread] initTableLoadTimer]; // Set the column count on the data store [tableValues setColumnCount:dataColumnsCount]; - - CGFloat relativeTargetRowCount = 100.0/targetRowCount; NSAutoreleasePool *dataLoadingPool; NSProgressIndicator *dataLoadingIndicator = [tableDocumentInstance valueForKey:@"queryProgressBar"]; @@ -735,16 +734,6 @@ pthread_mutex_unlock(&tableValuesLock); - // Update the task interface as necessary - if (!isFiltered) { - if (tableRowsCount < targetRowCount) { - [tableDocumentInstance setTaskPercentage:(tableRowsCount*relativeTargetRowCount)]; - } else if (tableRowsCount == targetRowCount) { - [tableDocumentInstance setTaskPercentage:100.0]; - [[tableDocumentInstance onMainThread] setTaskProgressToIndeterminateAfterDelay:YES]; - } - } - // Drain and reset the autorelease pool every ~1024 rows if (!(tableRowsCount % 1024)) { [dataLoadingPool drain]; @@ -1047,6 +1036,18 @@ */ - (void) tableLoadUpdate:(NSTimer *)theTimer { + + // Update the task interface as necessary + if (!isFiltered && tableLoadTargetRowCount != NSUIntegerMax) { + if (tableRowsCount < tableLoadTargetRowCount) { + [tableDocumentInstance setTaskPercentage:(tableRowsCount*100/tableLoadTargetRowCount)]; + } else if (tableRowsCount >= tableLoadTargetRowCount) { + [tableDocumentInstance setTaskPercentage:100.0]; + [tableDocumentInstance setTaskProgressToIndeterminateAfterDelay:YES]; + tableLoadTargetRowCount = NSUIntegerMax; + } + } + if (tableLoadTimerTicksSinceLastUpdate < tableLoadInterfaceUpdateInterval) { tableLoadTimerTicksSinceLastUpdate++; return; @@ -1064,7 +1065,7 @@ // Update column widths in two cases: on very first rows displayed, and once // more than 200 rows are present. - if (tableLoadInterfaceUpdateInterval || (tableRowsCount >= 200 && tableLoadLastRowCount < 200)) { + if (tableLoadInterfaceUpdateInterval == 1 || (tableRowsCount >= 200 && tableLoadLastRowCount < 200)) { [self autosizeColumns]; } @@ -2823,7 +2824,9 @@ */ - (void)autosizeColumns { - NSDictionary *columnWidths = [tableContentView autodetectColumnWidthsForFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPGlobalResultTableFont]]]; + if (isWorking) pthread_mutex_lock(&tableValuesLock); + NSDictionary *columnWidths = [tableContentView autodetectColumnWidths]; + if (isWorking) pthread_mutex_unlock(&tableValuesLock); [tableContentView setDelegate:nil]; for (NSDictionary *columnDefinition in dataColumns) { @@ -3255,7 +3258,7 @@ NSDictionary *columnDefinition = [dataColumns objectAtIndex:[[theColumn identifier] integerValue]]; // Get the column width - NSUInteger targetWidth = [tableContentView autodetectWidthForColumnDefinition:columnDefinition usingFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPGlobalResultTableFont]] maxRows:500]; + NSUInteger targetWidth = [tableContentView autodetectWidthForColumnDefinition:columnDefinition maxRows:500]; // Clear any saved widths for the column NSString *dbKey = [NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]; -- cgit v1.2.3