From c83f7b115e9cb41f7c92212434096515ac8e6909 Mon Sep 17 00:00:00 2001 From: Max Lohrmann Date: Tue, 30 May 2017 01:27:36 +0200 Subject: Small changes to PR #2807 and surrounding code --- Source/SPCopyTable.m | 32 +++++++++++++++++++++++--------- Source/SPTableContent.m | 14 ++++++++------ Source/SPTableContentDataSource.h | 2 ++ Source/SPTableContentDataSource.m | 2 +- Source/SPTableContentDelegate.m | 2 +- 5 files changed, 35 insertions(+), 17 deletions(-) (limited to 'Source') diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m index f2ad878f..aa77ffbc 100644 --- a/Source/SPCopyTable.m +++ b/Source/SPCopyTable.m @@ -184,6 +184,7 @@ static const NSInteger kBlobAsImageFile = 4; [fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil]; } + BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex]; [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) { for (NSUInteger c = 0; c < numColumns; c++ ) { id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]); @@ -197,13 +198,12 @@ static const NSInteger kBlobAsImageFile = 4; [result appendFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]; else if ([cellData isKindOfClass:[NSData class]]) { if(withBlobHandling == kBlobInclude) { - BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex]; NSString *displayString; if (hexBlobs) displayString = [[NSString alloc] initWithFormat:@"0x%@", [cellData dataToHexString]]; else displayString = [[NSString alloc] initWithData:cellData encoding:[mySQLConnection stringEncoding]]; - if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSASCIIStringEncoding]; + if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSISOLatin1StringEncoding]; if (displayString) { [result appendFormat:@"%@\t", displayString]; [displayString release]; @@ -320,6 +320,7 @@ static const NSInteger kBlobAsImageFile = 4; [fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil]; } + BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex]; [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) { for (NSUInteger c = 0; c < numColumns; c++ ) { id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]); @@ -333,8 +334,12 @@ static const NSInteger kBlobAsImageFile = 4; [result appendFormat:@"\"%@\",", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]; else if ([cellData isKindOfClass:[NSData class]]) { if(withBlobHandling == kBlobInclude) { - NSString *displayString = [[NSString alloc] initWithData:cellData encoding:[mySQLConnection stringEncoding]]; - if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSASCIIStringEncoding]; + NSString *displayString; + if (hexBlobs) + displayString = [[NSString alloc] initWithFormat:@"0x%@", [cellData dataToHexString]]; + else + displayString = [[NSString alloc] initWithData:cellData encoding:[mySQLConnection stringEncoding]]; + if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSISOLatin1StringEncoding]; if (displayString) { [result appendFormat:@"\"%@\",", displayString]; [displayString release]; @@ -625,6 +630,7 @@ static const NSInteger kBlobAsImageFile = 4; Class nsDataClass = [NSData class]; Class spmysqlGeometryData = [SPMySQLGeometryData class]; NSStringEncoding connectionEncoding = [mySQLConnection stringEncoding]; + BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex]; [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) { for (NSUInteger c = 0; c < numColumns; c++ ) { id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]); @@ -637,10 +643,15 @@ static const NSInteger kBlobAsImageFile = 4; else if ([cellData isSPNotLoaded]) [result appendFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]; else if ([cellData isKindOfClass:nsDataClass]) { - NSString *displayString = [[NSString alloc] initWithData:cellData encoding:connectionEncoding]; - if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSASCIIStringEncoding]; + NSString *displayString; + if (hexBlobs) + displayString = [[NSString alloc] initWithFormat:@"0x%@", [cellData dataToHexString]]; + else + displayString = [[NSString alloc] initWithData:cellData encoding:connectionEncoding]; + if (!displayString) displayString = [[NSString alloc] initWithData:cellData encoding:NSISOLatin1StringEncoding]; if (displayString) { [result appendString:displayString]; + [result appendString:@"\t"]; [displayString release]; } } @@ -754,7 +765,6 @@ static const NSInteger kBlobAsImageFile = 4; - (NSUInteger)autodetectWidthForColumnDefinition:(NSDictionary *)columnDefinition maxRows:(NSUInteger)rowsToCheck { CGFloat columnBaseWidth; - id contentString; NSUInteger cellWidth, maxCellWidth, i; NSRange linebreakRange; double rowStep; @@ -767,6 +777,7 @@ static const NSInteger kBlobAsImageFile = 4; NSUInteger columnIndex = (NSUInteger)[[columnDefinition objectForKey:@"datacolumnindex"] integerValue]; NSDictionary *stringAttributes = @{NSFontAttributeName : tableFont}; Class spmysqlGeometryData = [SPMySQLGeometryData class]; + BOOL hexBlobs = [prefs boolForKey:SPDisplayBinaryDataAsHex]; // Check the number of rows available to check, sampling every n rows if ([tableStorage count] < rowsToCheck) @@ -784,7 +795,7 @@ static const NSInteger kBlobAsImageFile = 4; for (i = 0; i < rowsToCheck; i += rowStep) { // Retrieve part of the cell's content to get widths, topping out at a maximum length - contentString = SPDataStoragePreviewAtRowAndColumn(tableStorage, i, columnIndex, 500); + id contentString = SPDataStoragePreviewAtRowAndColumn(tableStorage, i, columnIndex, 500); // If the cell hasn't loaded yet, skip processing if (!contentString) @@ -806,7 +817,10 @@ static const NSInteger kBlobAsImageFile = 4; // Otherwise, ensure the cell is represented as a short string if ([contentString isKindOfClass:[NSData class]]) { - contentString = [contentString shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]]; + if (hexBlobs) + contentString = [[NSString alloc] initWithFormat:@"0x%@", [(NSData *)contentString dataToHexString]]; + else + contentString = [contentString shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]]; } else if ([(NSString *)contentString length] > 500) { contentString = [contentString substringToIndex:500]; } diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index e2895e15..aeac9bc4 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" @@ -2382,7 +2383,6 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper [currentResult addObject:[NSArray arrayWithArray:tempRow]]; - BOOL hexBlobs = [prefs boolForKey: SPDisplayBinaryDataAsHex]; // Add rows for (i = 0; i < [self numberOfRowsInTableView:tableContentView]; i++) { @@ -2390,7 +2390,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]]; @@ -2442,15 +2443,16 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper } else { NSString *str; - if (hide) + if (hide) { str = @"<BLOB>"; - else if (hexBlobs) { - str = [NSString stringWithFormat: @"0x%@", [o dataToHexString]]; + } + else if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) { + str = [NSString stringWithFormat:@"0x%@", [o dataToHexString]]; } else { str = [o stringRepresentationUsingEncoding:[mySQLConnection stringEncoding]]; } - [tempRow addObject: str]; + [tempRow addObject:str]; } if(image) [image release]; diff --git a/Source/SPTableContentDataSource.h b/Source/SPTableContentDataSource.h index f257dce7..19864a80 100644 --- a/Source/SPTableContentDataSource.h +++ b/Source/SPTableContentDataSource.h @@ -32,4 +32,6 @@ @interface SPTableContent (SPTableContentDataSource) +- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex; + @end diff --git a/Source/SPTableContentDataSource.m b/Source/SPTableContentDataSource.m index 562a5856..a623f83b 100644 --- a/Source/SPTableContentDataSource.m +++ b/Source/SPTableContentDataSource.m @@ -120,7 +120,7 @@ if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) { if ([(NSData *)value length] > 255) { - return [NSString stringWithFormat:@"0x%@...", [[(NSData *)value subdataWithRange:NSMakeRange(0, 255)] dataToHexString]]; + return [NSString stringWithFormat:@"0x%@…", [[(NSData *)value subdataWithRange:NSMakeRange(0, 255)] dataToHexString]]; } return [NSString stringWithFormat:@"0x%@", [(NSData *)value dataToHexString]]; } diff --git a/Source/SPTableContentDelegate.m b/Source/SPTableContentDelegate.m index e188c4de..0a80b602 100644 --- a/Source/SPTableContentDelegate.m +++ b/Source/SPTableContentDelegate.m @@ -30,6 +30,7 @@ #import "SPTableContentDelegate.h" #import "SPTableContentFilter.h" +#import "SPTableContentDataSource.h" #ifndef SP_CODA /* headers */ #import "SPAppController.h" #endif @@ -54,7 +55,6 @@ @interface SPTableContent (SPDeclaredAPI) - (BOOL)cancelRowEditing; -- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex; @end -- cgit v1.2.3