Skip to content

Commit

Permalink
#2629 show binary data as hex now also applies to blob
Browse files Browse the repository at this point in the history
  • Loading branch information
abhibeckert committed Mar 10, 2017
1 parent c866a5b commit 1d12c0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
34 changes: 27 additions & 7 deletions Source/SPTableContentDataSource.m
Expand Up @@ -106,10 +106,6 @@ - (id)tableView:(SPCopyTable *)tableView objectValueForTableColumn:(NSTableColum
value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES]; value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES];
} }
} }

NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];

NSString *columnType = [columnDefinition objectForKey:@"typegrouping"];


if ([value isKindOfClass:[SPMySQLGeometryData class]]) { if ([value isKindOfClass:[SPMySQLGeometryData class]]) {
return [value wktString]; return [value wktString];
Expand All @@ -120,9 +116,12 @@ - (id)tableView:(SPCopyTable *)tableView objectValueForTableColumn:(NSTableColum
} }


if ([value isKindOfClass:[NSData class]]) { if ([value isKindOfClass:[NSData class]]) {


if ([columnType isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) { if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) {
return [NSString stringWithFormat:@"0x%@", [value dataToHexString]]; if ([(NSData *)value length] > 255) {
return [NSString stringWithFormat:@"0x%@...", [[(NSData *)value subdataWithRange:NSMakeRange(0, 255)] dataToHexString]];
}
return [NSString stringWithFormat:@"0x%@", [(NSData *)value dataToHexString]];
} }


pthread_mutex_t *fieldEditorCheckLock = NULL; pthread_mutex_t *fieldEditorCheckLock = NULL;
Expand Down Expand Up @@ -207,6 +206,27 @@ - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCol
} }
} }


- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex
{
if (![prefs boolForKey:SPDisplayBinaryDataAsHex]) {
return NO;
}

NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];
NSString *typeGrouping = columnDefinition[@"typegrouping"];

if ([typeGrouping isEqual:@"binary"]) {
return YES;
}

if ([typeGrouping isEqual:@"blobdata"]) {
return YES;
}


return NO;
}

@end @end


@implementation SPTableContent (SPTableContentDataSource_Private_API) @implementation SPTableContent (SPTableContentDataSource_Private_API)
Expand Down
13 changes: 4 additions & 9 deletions Source/SPTableContentDelegate.m
Expand Up @@ -54,6 +54,7 @@
@interface SPTableContent (SPDeclaredAPI) @interface SPTableContent (SPDeclaredAPI)


- (BOOL)cancelRowEditing; - (BOOL)cancelRowEditing;
- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex;


@end @end


Expand Down Expand Up @@ -273,7 +274,7 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
NSDictionary *columnDefinition = [cqColumnDefinition objectAtIndex:[[tableColumn identifier] integerValue]]; NSDictionary *columnDefinition = [cqColumnDefinition objectAtIndex:[[tableColumn identifier] integerValue]];


// TODO: Fix editing of "Display as Hex" columns and remove this (also see above) // TODO: Fix editing of "Display as Hex" columns and remove this (also see above)
if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) { if ([self cellValueIsDisplayedAsHexForColumn:[[tableColumn identifier] integerValue]]) {
NSBeep(); NSBeep();
[SPTooltip showWithObject:NSLocalizedString(@"Disable \"Display Binary Data as Hex\" in the View menu to edit this field.",@"Temporary : Tooltip shown when trying to edit a binary field in table content view while it is displayed using HEX conversion")]; [SPTooltip showWithObject:NSLocalizedString(@"Disable \"Display Binary Data as Hex\" in the View menu to edit this field.",@"Temporary : Tooltip shown when trying to edit a binary field in table content view while it is displayed using HEX conversion")];
return NO; return NO;
Expand Down Expand Up @@ -330,7 +331,7 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]]; cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]];
} }


if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) { if ([self cellValueIsDisplayedAsHexForColumn:[[tableColumn identifier] integerValue]]) {
[fieldEditor setTextMaxLength:[[self tableView:tableContentView objectValueForTableColumn:tableColumn row:rowIndex] length]]; [fieldEditor setTextMaxLength:[[self tableView:tableContentView objectValueForTableColumn:tableColumn row:rowIndex] length]];
isFieldEditable = NO; isFieldEditable = NO;
} }
Expand Down Expand Up @@ -521,13 +522,7 @@ - (void)tableView:(SPCopyTable *)tableView willDisplayCell:(id)cell forTableColu


NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex]; NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];


NSString *columnType = [columnDefinition objectForKey:@"typegrouping"]; if ([self cellValueIsDisplayedAsHexForColumn:[[tableColumn identifier] integerValue]]) {

// Find a more reliable way of doing this check
if ([columnType isEqualToString:@"binary"] &&
[prefs boolForKey:SPDisplayBinaryDataAsHex] &&
[[self tableView:tableContentView objectValueForTableColumn:tableColumn row:rowIndex] hasPrefix:@"0x"]) {

[cell setTextColor:rowIndex == [tableContentView selectedRow] ? whiteColor : blueColor]; [cell setTextColor:rowIndex == [tableContentView selectedRow] ? whiteColor : blueColor];
} }


Expand Down

0 comments on commit 1d12c0e

Please sign in to comment.