diff options
Diffstat (limited to 'Source/SPCharsetCollationHelper.m')
-rw-r--r-- | Source/SPCharsetCollationHelper.m | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Source/SPCharsetCollationHelper.m b/Source/SPCharsetCollationHelper.m index 378fb7cf..72387597 100644 --- a/Source/SPCharsetCollationHelper.m +++ b/Source/SPCharsetCollationHelper.m @@ -53,6 +53,7 @@ @synthesize selectedCharset; @synthesize selectedCollation; @synthesize defaultCharsetFormatString; +@synthesize defaultCollationFormatString; @synthesize _oldCharset; - (id)initWithCharsetButton:(NSPopUpButton *)aCharsetButton CollationButton:(NSPopUpButton *)aCollationButton @@ -63,7 +64,8 @@ self = [super init]; if (self != nil) { [self setPromoteUTF8:YES]; - [self setDefaultCharsetFormatString:NSLocalizedString(@"Default (%@)",@"Charset Dropdown : Default item ($1 = name)")]; + [self setDefaultCharsetFormatString:NSLocalizedString(@"Default (%@)",@"Charset Dropdown : Default item ($1 = charset name)")]; + [self setDefaultCollationFormatString:NSLocalizedString(@"Default (%@)",@"Collation Dropdown : Default collation for given charset ($1 = collation name)")]; charsetButton = aCharsetButton; collationButton = aCollationButton; //connect the charset button with ourselves @@ -210,6 +212,7 @@ //get the charset id NSString *charsetId = [[charsetButton selectedItem] representedObject]; + BOOL charsetIsInherited = ([self selectedCharset] == nil); //now let's get the list of collations for the selected charset id NSArray *applicableCollations = [databaseData getDatabaseCollationsForEncoding:charsetId]; @@ -220,16 +223,18 @@ //add a separator [[collationButton menu] addItem:[NSMenuItem separatorItem]]; - - //if this is the defaultCharset and we have a defaultCollation use that instead - BOOL useGivenDefaultCollation = (defaultCharset && defaultCollation && [charsetId isEqualToString:defaultCharset]); - - if(useGivenDefaultCollation) { - NSString *userDefaultCollateTitle = [NSString stringWithFormat:fmtStrDefaultId,defaultCollation]; + + // there are two kinds of default collations: + // - the inherited default (which is only used if NEITHER charset NOR collation is explicitly set), and + // - the charset default (which is used if charset is explicitly set, but collation is not) + // - that even applies if the selectedCharset is the same as the defaultCharset! + if(charsetIsInherited) { + // implies [charsetId isEqualToString:defaultCharset] + NSString *userInheritedCollateTitle = [NSString stringWithFormat:defaultCollationFormatString,defaultCollation]; //remove the dummy default item. [collationButton removeItemAtIndex:0]; //add it to the top of the list - [collationButton insertItemWithTitle:userDefaultCollateTitle atIndex:0]; + [collationButton insertItemWithTitle:userInheritedCollateTitle atIndex:0]; } //add the real items @@ -238,8 +243,8 @@ NSString *collationName = [collation objectForKey:@"COLLATION_NAME"]; [collationButton addItemWithTitle:collationName]; - //is this the default collation for this charset (and we didn't override it)? - if(!useGivenDefaultCollation && [[collation objectForKey:@"IS_DEFAULT"] isEqualToString:@"Yes"]) { + //is this the default collation for this charset and charset was given explicitly (ie. breaking inheritance)? + if(!charsetIsInherited && [[collation objectForKey:@"IS_DEFAULT"] isEqualToString:@"Yes"]) { NSString *defaultCollateTitle = [NSString stringWithFormat:fmtStrDefaultId,collationName]; //remove the dummy default item. [collationButton removeItemAtIndex:0]; @@ -247,7 +252,7 @@ [collationButton insertItemWithTitle:defaultCollateTitle atIndex:0]; } } - //reset selection to first item (it may moved when adding the default item) + //reset selection to first item (it may have moved when adding the default item) [collationButton selectItemAtIndex:0]; //honor selectedCollation |