Skip to content

Commit f5e022b

Browse files
authored
Merge pull request #2721 from abhibeckert/master
#2629 show binary data as hex now also applies to blob
2 parents cbfadab + 1d12c0e commit f5e022b

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

Source/SPTableContentDataSource.m

+27-7
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ - (id)tableView:(SPCopyTable *)tableView objectValueForTableColumn:(NSTableColum
106106
value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES];
107107
}
108108
}
109-
110-
NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];
111-
112-
NSString *columnType = [columnDefinition objectForKey:@"typegrouping"];
113109

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

122118
if ([value isKindOfClass:[NSData class]]) {
123-
124-
if ([columnType isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) {
125-
return [NSString stringWithFormat:@"0x%@", [value dataToHexString]];
119+
120+
if ([self cellValueIsDisplayedAsHexForColumn:columnIndex]) {
121+
if ([(NSData *)value length] > 255) {
122+
return [NSString stringWithFormat:@"0x%@...", [[(NSData *)value subdataWithRange:NSMakeRange(0, 255)] dataToHexString]];
123+
}
124+
return [NSString stringWithFormat:@"0x%@", [(NSData *)value dataToHexString]];
126125
}
127126

128127
pthread_mutex_t *fieldEditorCheckLock = NULL;
@@ -207,6 +206,27 @@ - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableCol
207206
}
208207
}
209208

209+
- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex
210+
{
211+
if (![prefs boolForKey:SPDisplayBinaryDataAsHex]) {
212+
return NO;
213+
}
214+
215+
NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];
216+
NSString *typeGrouping = columnDefinition[@"typegrouping"];
217+
218+
if ([typeGrouping isEqual:@"binary"]) {
219+
return YES;
220+
}
221+
222+
if ([typeGrouping isEqual:@"blobdata"]) {
223+
return YES;
224+
}
225+
226+
227+
return NO;
228+
}
229+
210230
@end
211231

212232
@implementation SPTableContent (SPTableContentDataSource_Private_API)

Source/SPTableContentDelegate.m

+4-9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
@interface SPTableContent (SPDeclaredAPI)
5555

5656
- (BOOL)cancelRowEditing;
57+
- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex;
5758

5859
@end
5960

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

275276
// TODO: Fix editing of "Display as Hex" columns and remove this (also see above)
276-
if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) {
277+
if ([self cellValueIsDisplayedAsHexForColumn:[[tableColumn identifier] integerValue]]) {
277278
NSBeep();
278279
[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")];
279280
return NO;
@@ -330,7 +331,7 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
330331
cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]];
331332
}
332333

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

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

524-
NSString *columnType = [columnDefinition objectForKey:@"typegrouping"];
525-
526-
// Find a more reliable way of doing this check
527-
if ([columnType isEqualToString:@"binary"] &&
528-
[prefs boolForKey:SPDisplayBinaryDataAsHex] &&
529-
[[self tableView:tableContentView objectValueForTableColumn:tableColumn row:rowIndex] hasPrefix:@"0x"]) {
530-
525+
if ([self cellValueIsDisplayedAsHexForColumn:[[tableColumn identifier] integerValue]]) {
531526
[cell setTextColor:rowIndex == [tableContentView selectedRow] ? whiteColor : blueColor];
532527
}
533528

0 commit comments

Comments
 (0)