diff options
Diffstat (limited to 'Source/SPTableContent.m')
-rw-r--r-- | Source/SPTableContent.m | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 416b7cd8..48871c11 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -31,6 +31,7 @@ #import "SPTableContent.h" #import "SPTableContentFilter.h" +#import "SPTableContentDataSource.h" #import "SPDatabaseDocument.h" #import "SPTableStructure.h" #import "SPTableInfo.h" @@ -81,6 +82,7 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper @interface SPTableContent () - (BOOL)cancelRowEditing; +- (void)documentWillClose:(NSNotification *)notification; @end @@ -172,7 +174,6 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper usedQuery = [[NSString alloc] initWithString:@""]; tableLoadTimer = nil; - tableLoadingCondition = [NSCondition new]; blackColor = [NSColor blackColor]; lightGrayColor = [NSColor lightGrayColor]; @@ -243,20 +244,16 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper [nibLoader release]; -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_7 //let's see if we can use the NSPopover (10.7+) or have to make do with our legacy clone. //this is using reflection right now, as our SDK is 10.8 but our minimum supported version is 10.6 Class popOverClass = NSClassFromString(@"NSPopover"); - if(popOverClass) - { + if(popOverClass) { paginationPopover = [[popOverClass alloc] init]; [paginationPopover setDelegate:(SPTableContent<NSPopoverDelegate> *)self]; [paginationPopover setContentViewController:paginationViewController]; [paginationPopover setBehavior:NSPopoverBehaviorTransient]; } - else -#endif - { + else { [paginationBox setContentView:[paginationViewController view]]; // Add the pagination view to the content area @@ -297,6 +294,10 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper selector:@selector(endDocumentTaskForTab:) name:SPDocumentTaskEndNotification object:tableDocumentInstance]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(documentWillClose:) + name:SPDocumentWillCloseNotification + object:tableDocumentInstance]; } #pragma mark - @@ -1060,11 +1061,8 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper // Set up the table updates timer and wait for it to notify this thread about completion [[self onMainThread] initTableLoadTimer]; - [tableLoadingCondition lock]; - while (![tableValues dataDownloaded]) { - [tableLoadingCondition waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]]; - } - [tableLoadingCondition unlock]; + [tableValues awaitDataDownloaded]; + tableRowsCount = [tableValues count]; // If the final column autoresize wasn't performed, perform it @@ -1269,10 +1267,7 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper } if ([tableValues dataDownloaded]) { - [tableLoadingCondition lock]; - [tableLoadingCondition signal]; [self clearTableLoadTimer]; - [tableLoadingCondition unlock]; } // Check whether a table update is required, based on whether new rows are @@ -1328,20 +1323,21 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper { NSAutoreleasePool *reloadPool = [[NSAutoreleasePool alloc] init]; - // Check whether a save of the current row is required. - if (![[self onMainThread] saveRowOnDeselect]) return; + // Check whether a save of the current row is required, abort if pending changes couldn't be saved. + if ([[self onMainThread] saveRowOnDeselect]) { - // Save view details to restore safely if possible (except viewport, which will be - // preserved automatically, and can then be scrolled as the table loads) - [self storeCurrentDetailsForRestoration]; - [self setViewportToRestore:NSZeroRect]; + // Save view details to restore safely if possible (except viewport, which will be + // preserved automatically, and can then be scrolled as the table loads) + [self storeCurrentDetailsForRestoration]; + [self setViewportToRestore:NSZeroRect]; - // Clear the table data column cache and status (including counts) - [tableDataInstance resetColumnData]; - [tableDataInstance resetStatusData]; + // Clear the table data column cache and status (including counts) + [tableDataInstance resetColumnData]; + [tableDataInstance resetStatusData]; - // Load the table's data - [self loadTable:[tablesListInstance tableName]]; + // Load the table's data + [self loadTable:[tablesListInstance tableName]]; + } [tableDocumentInstance endTask]; @@ -1638,13 +1634,11 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper } #endif -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_7 - (void)popoverDidClose:(NSNotification *)notification { //not to hide the view, but to change the paginationButton [self setPaginationViewVisibility:NO]; } -#endif /** * Show or hide the pagination layer, also changing the first responder as appropriate. @@ -1672,7 +1666,6 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper } } -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_7 if(paginationPopover) { if(makeVisible) { [paginationPopover showRelativeToRect:[paginationButton bounds] ofView:paginationButton preferredEdge:NSMinYEdge]; @@ -1684,7 +1677,6 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper } return; } -#endif if (makeVisible) { if (paginationViewFrame.size.height == paginationViewHeight) return; @@ -2399,7 +2391,8 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper for (NSTableColumn *aTableColumn in tableColumns) { - id o = SPDataStorageObjectAtRowAndColumn(tableValues, i, [[aTableColumn identifier] integerValue]); + NSUInteger columnIndex = [[aTableColumn identifier] integerValue]; + id o = SPDataStorageObjectAtRowAndColumn(tableValues, i, columnIndex); if ([o isNSNull]) { [tempRow addObject:includeNULLs ? [NSNull null] : [prefs objectForKey:SPNullValue]]; @@ -2450,7 +2443,17 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper [[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01f] base64Encoding]]]; } else { - [tempRow addObject:hide ? @"<BLOB>" : [o stringRepresentationUsingEncoding:[mySQLConnection stringEncoding]]]; + NSString *str; + if (hide) { + str = @"<BLOB>"; + } + else if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) { + str = [NSString stringWithFormat:@"0x%@", [o dataToHexString]]; + } + else { + str = [o stringRepresentationUsingEncoding:[mySQLConnection stringEncoding]]; + } + [tempRow addObject:str]; } if(image) [image release]; @@ -2549,13 +2552,15 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper @"filterValue": targetFilterValue, @"filterComparison": SPBoxNil(filterComparison) }; - [self setFiltersToRestore:filterSettings]; - - // Attempt to switch to the target table - if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) { - NSBeep(); - [self setFiltersToRestore:nil]; - } + SPMainQSync(^{ + [self setFiltersToRestore:filterSettings]; + + // Attempt to switch to the target table + if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) { + NSBeep(); + [self setFiltersToRestore:nil]; + } + }); } #ifndef SP_CODA @@ -4148,6 +4153,13 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper tableRowsSelectable = YES; } +//this method is called right before the UI objects are deallocated +- (void)documentWillClose:(NSNotification *)notification +{ + // if a result load is in progress we must stop the timer or it may try to call invalid IBOutlets + [self clearTableLoadTimer]; +} + #pragma mark - #pragma mark KVO methods @@ -4232,7 +4244,6 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper if(fieldEditor) SPClear(fieldEditor); [self clearTableLoadTimer]; - SPClear(tableLoadingCondition); SPClear(tableValues); pthread_mutex_destroy(&tableValuesLock); SPClear(dataColumns); |