diff options
author | Abhi Beckert <abhi@abhibeckert.com> | 2017-03-10 13:38:59 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-10 13:38:59 +1000 |
commit | f5e022b6667815a05c0b2478db07f50af2e52d0b (patch) | |
tree | 9ebf384a89caa2a726fce85dffb9c4878a43fac8 | |
parent | cbfadab19e17a4c50e4ddfd5599887cb0597ced5 (diff) | |
parent | 1d12c0e41319ffd2a1f1ab62305bd2688910f151 (diff) | |
download | sequelpro-f5e022b6667815a05c0b2478db07f50af2e52d0b.tar.gz sequelpro-f5e022b6667815a05c0b2478db07f50af2e52d0b.tar.bz2 sequelpro-f5e022b6667815a05c0b2478db07f50af2e52d0b.zip |
Merge pull request #2721 from abhibeckert/master
#2629 show binary data as hex now also applies to blob
-rw-r--r-- | Source/SPTableContentDataSource.m | 34 | ||||
-rw-r--r-- | Source/SPTableContentDelegate.m | 13 |
2 files changed, 31 insertions, 16 deletions
diff --git a/Source/SPTableContentDataSource.m b/Source/SPTableContentDataSource.m index 34b886d4..56e8df71 100644 --- a/Source/SPTableContentDataSource.m +++ b/Source/SPTableContentDataSource.m @@ -106,10 +106,6 @@ 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]]) { return [value wktString]; @@ -120,9 +116,12 @@ } if ([value isKindOfClass:[NSData class]]) { - - if ([columnType isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) { - return [NSString stringWithFormat:@"0x%@", [value dataToHexString]]; + + 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 dataToHexString]]; } pthread_mutex_t *fieldEditorCheckLock = NULL; @@ -207,6 +206,27 @@ } } +- (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 @implementation SPTableContent (SPTableContentDataSource_Private_API) diff --git a/Source/SPTableContentDelegate.m b/Source/SPTableContentDelegate.m index 6634e29e..a510108b 100644 --- a/Source/SPTableContentDelegate.m +++ b/Source/SPTableContentDelegate.m @@ -54,6 +54,7 @@ @interface SPTableContent (SPDeclaredAPI) - (BOOL)cancelRowEditing; +- (BOOL)cellValueIsDisplayedAsHexForColumn:(NSUInteger)columnIndex; @end @@ -273,7 +274,7 @@ NSDictionary *columnDefinition = [cqColumnDefinition objectAtIndex:[[tableColumn identifier] integerValue]]; // 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(); [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; @@ -330,7 +331,7 @@ 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]]; isFieldEditable = NO; } @@ -521,13 +522,7 @@ NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex]; - NSString *columnType = [columnDefinition objectForKey:@"typegrouping"]; - - // 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"]) { - + if ([self cellValueIsDisplayedAsHexForColumn:[[tableColumn identifier] integerValue]]) { [cell setTextColor:rowIndex == [tableContentView selectedRow] ? whiteColor : blueColor]; } |