diff options
author | Max <post@wickenrode.com> | 2015-10-25 19:34:44 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-10-25 19:34:44 +0100 |
commit | 2a8528d88a7ad2c9294d64c6b0effd67e14fbf4b (patch) | |
tree | 8ad01402a20bb7d9c6badc8cf071f8afe4c1688f /Source/SPTableStructureDelegate.m | |
parent | e7cf9cde835a3db7921a96da063b908c0084a43f (diff) | |
download | sequelpro-2a8528d88a7ad2c9294d64c6b0effd67e14fbf4b.tar.gz sequelpro-2a8528d88a7ad2c9294d64c6b0effd67e14fbf4b.tar.bz2 sequelpro-2a8528d88a7ad2c9294d64c6b0effd67e14fbf4b.zip |
Improve the way Sequel Pro inferrs the collation of a column. (#2237)
This does not entirely fix the bug of SP sometimes displaying the wrong collation, but should work in >= 99% of cases.
Diffstat (limited to 'Source/SPTableStructureDelegate.m')
-rw-r--r-- | Source/SPTableStructureDelegate.m | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index 3f2c54e6..1e470e79 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -62,6 +62,8 @@ if ((NSUInteger)rowIndex >= [tableFields count]) return @"..."; if ([[tableColumn identifier] isEqualToString:@"collation"]) { + NSString *tableEncoding = [tableDataInstance tableEncoding]; + NSString *columnEncoding = nil; NSInteger idx = 0; if ((idx = [[NSArrayObjectAtIndex(tableFields, rowIndex) objectForKey:@"encoding"] integerValue]) > 0 && idx < [encodingPopupCell numberOfItems]) { @@ -69,28 +71,44 @@ NSUInteger start = [enc rangeOfString:@"("].location + 1; - collations = [databaseDataInstance getDatabaseCollationsForEncoding:[enc substringWithRange:NSMakeRange(start, [enc length] - start - 1)]]; + columnEncoding = [enc substringWithRange:NSMakeRange(start, [enc length] - start - 1)]; + collations = [databaseDataInstance getDatabaseCollationsForEncoding:columnEncoding]; } else { // If the structure has loaded (not still loading!) and the table encoding // is set, use the appropriate collations. - collations = ([tableDocumentInstance structureLoaded] && [tableDataInstance tableEncoding] != nil) ? [databaseDataInstance getDatabaseCollationsForEncoding:[tableDataInstance tableEncoding]] : @[]; + collations = @[]; + if([tableDocumentInstance structureLoaded]) { + columnEncoding = [tableDataInstance tableEncoding]; + if(columnEncoding) collations = [databaseDataInstance getDatabaseCollationsForEncoding:columnEncoding]; + } } - [[tableColumn dataCell] removeAllItems]; + NSPopUpButtonCell *collationCell = [tableColumn dataCell]; + + [collationCell removeAllItems]; if ([collations count] > 0) { - NSString *defaultCollation = [[tableDataInstance statusValues] objectForKey:@"collation"]; + NSString *tableCollation = [[tableDataInstance statusValues] objectForKey:@"Collation"]; - if (!defaultCollation) { - defaultCollation = [databaseDataInstance getDatabaseDefaultCollation]; + if (![tableCollation length]) { + tableCollation = [databaseDataInstance getDefaultCollationForEncoding:tableEncoding]; + } + + NSString *columnCollation = [NSArrayObjectAtIndex(tableFields, rowIndex) objectForKey:@"collationName"]; + + if (![columnCollation length]) { + columnCollation = [databaseDataInstance getDefaultCollationForEncoding:columnEncoding]; } [[tableColumn dataCell] addItemWithTitle:@""]; BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts]; CGFloat monospacedFontSize = [prefs floatForKey:SPMonospacedFontSize] > 0 ? [prefs floatForKey:SPMonospacedFontSize] : [NSFont smallSystemFontSize]; + NSMutableDictionary *menuAttributes = [NSMutableDictionary dictionaryWithObject:[NSColor lightGrayColor] forKey:NSForegroundColorAttributeName]; + [menuAttributes setObject:useMonospacedFont ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]; + BOOL columnUsesTableDefaultEncoding = ([columnEncoding isEqualToString:tableEncoding]); // Populate collation popup button for (NSDictionary *collation in collations) { @@ -99,12 +117,9 @@ [[tableColumn dataCell] addItemWithTitle:collationName]; // If this matches the table's collation, draw in gray - if ([collationName length] && [collationName isEqualToString:defaultCollation]) { + if (columnUsesTableDefaultEncoding && [collationName isEqualToString:tableCollation]) { NSMenuItem *collationMenuItem = [(NSPopUpButtonCell *)[tableColumn dataCell] itemAtIndex:([[tableColumn dataCell] numberOfItems] - 1)]; - NSMutableDictionary *menuAttributes = [NSMutableDictionary dictionaryWithObject:[NSColor lightGrayColor] forKey:NSForegroundColorAttributeName]; - - [menuAttributes setObject:useMonospacedFont ? [NSFont fontWithName:SPDefaultMonospacedFontName size:monospacedFontSize] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]; - + NSAttributedString *itemString = [[[NSAttributedString alloc] initWithString:collationName attributes:menuAttributes] autorelease]; [collationMenuItem setAttributedTitle:itemString]; |