From 1204639d4aeeac3d3dda7b0c53b8941266b9e685 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Wed, 2 Nov 2011 18:30:18 +0000 Subject: [Author: thomasvl] - Support for localizing non datasource versions of NSComboxBox (http://code.google.com/p/google-toolbox-for-mac/issues/detail?id=77). - Fix up some category names. - Avoid conflicting category names. - Move placeholder string support down to NSTextField instead of NSSearchField. - Support for NSTextField placeholder in unittesting state. - Support for non datasource combobox values in unittesting state. - Fix NSSegmentControl localization support. - Add explicit tests for no localized values and document it in the strings file. - Unittesting for as much as possible of the above. R=dmaclach DELTA=762 (660 added, 55 deleted, 47 changed) --- AppKit/GTMUILocalizer.m | 53 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'AppKit/GTMUILocalizer.m') diff --git a/AppKit/GTMUILocalizer.m b/AppKit/GTMUILocalizer.m index 56b0b7d..ffcc11d 100644 --- a/AppKit/GTMUILocalizer.m +++ b/AppKit/GTMUILocalizer.m @@ -23,7 +23,7 @@ - (void)localizeAccessibility:(id)object; - (void)localizeBindings:(id)object; -// Never recursively call any of these methods. Always call +// Never recursively call any of these methods. Always call // -[self localizeObject:recursively:] otherwise bindings will not be // localized properly. - (void)localizeWindow:(NSWindow *)window recursively:(BOOL)recursive; @@ -240,12 +240,12 @@ } } - // Do NSSearchField placeholders - if ([view isKindOfClass:[NSSearchField class]]) { - NSString *placeholder = [[(NSSearchField *)view cell] placeholderString]; + // Do NSTextField placeholders + if ([view isKindOfClass:[NSTextField class]]) { + NSString *placeholder = [[(NSTextField *)view cell] placeholderString]; NSString *localizedPlaceholer = [self localizedStringForString:placeholder]; if (localizedPlaceholer) { - [[(NSSearchField *)view cell] setPlaceholderString:localizedPlaceholer]; + [[(NSTextField *)view cell] setPlaceholderString:localizedPlaceholer]; } } @@ -282,8 +282,37 @@ NSSegmentedControl *segmentedControl = (NSSegmentedControl *)view; for (NSInteger i = 0; i < [segmentedControl segmentCount]; ++i) { NSString *label = [segmentedControl labelForSegment:i]; - [segmentedControl setLabel:[self localizedStringForString:label] - forSegment:i]; + NSString *localizedLabel = [self localizedStringForString:label]; + if (localizedLabel) { + [segmentedControl setLabel:localizedLabel forSegment:i]; + } + } + } + + // Do NSComboBox items. + if ([view isKindOfClass:[NSComboBox class]]) { + NSComboBox *combobox = (NSComboBox*)view; + // Make sure it doesn't use a DataSource. + if (![combobox usesDataSource]) { + NSMutableArray *localizedValues = [NSMutableArray array]; + BOOL replaceValues = NO; + NSString *value; + GTM_FOREACH_OBJECT(value, [combobox objectValues]) { + NSString *localizedValue = nil; + if ([value isKindOfClass:[NSString class]]) { + localizedValue = [self localizedStringForString:value]; + } + if (localizedValue) { + replaceValues = YES; + [localizedValues addObject:localizedValue]; + } else { + [localizedValues addObject:value]; + } + } + if (replaceValues) { + [combobox removeAllItems]; + [combobox addItemsWithObjectValues:localizedValues]; + } } } } @@ -343,10 +372,10 @@ NSString *path = [bindingInfo objectForKey:NSObservedKeyPathKey]; NSDictionary *options = [bindingInfo objectForKey:NSOptionsKey]; if (observedObject && path && options) { - NSMutableDictionary *newOptions + NSMutableDictionary *newOptions = [NSMutableDictionary dictionaryWithDictionary:options]; BOOL valueChanged = NO; - for (size_t i = 0; + for (size_t i = 0; i < sizeof(optionsToLocalize) / sizeof(optionsToLocalize[0]); ++i) { NSString *key = optionsToLocalize[i]; @@ -362,9 +391,9 @@ if (valueChanged) { // Only unbind and rebind if there is a change. [object unbind:exposedBinding]; - [object bind:exposedBinding - toObject:observedObject - withKeyPath:path + [object bind:exposedBinding + toObject:observedObject + withKeyPath:path options:newOptions]; } } -- cgit v1.2.3