aboutsummaryrefslogtreecommitdiff
path: root/AppKit
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2010-01-21 17:00:21 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2010-01-21 17:00:21 +0000
commitbd829ad75159a3cfe3ba81bee61fa725909f2ad4 (patch)
tree9d591db75edebf3180207adf2168a8c8ff56396c /AppKit
parent53974a084bc914ea8666918b43803574515c9aef (diff)
[Author: dmaclach]
Clean up GTMUILocalizer so that it has a single entry point. Bindings weren't always being updated recursively. R=thomasvl DELTA=95 (45 added, 38 deleted, 12 changed)
Diffstat (limited to 'AppKit')
-rw-r--r--AppKit/GTMUILocalizer.h25
-rw-r--r--AppKit/GTMUILocalizer.m78
-rw-r--r--AppKit/GTMUILocalizerTest.m6
3 files changed, 57 insertions, 52 deletions
diff --git a/AppKit/GTMUILocalizer.h b/AppKit/GTMUILocalizer.h
index c07d7a1..81f9dca 100644
--- a/AppKit/GTMUILocalizer.h
+++ b/AppKit/GTMUILocalizer.h
@@ -64,6 +64,12 @@
// will localize properly. This keeps the differences between the nibs down
// to the bare essentials.
//
+// NOTE: NSToolbar localization support is limited to only working on the
+// default items in the toolbar. We cannot localize items that are on of the
+// customization palette but not in the default items because there is not an
+// API for NSToolbar to get all possible items. You are responsible for
+// localizing all non-default toolbar items by hand.
+//
@interface GTMUILocalizer : NSObject {
@private
IBOutlet id owner_;
@@ -72,23 +78,10 @@
NSBundle *bundle_;
}
- (id)initWithBundle:(NSBundle *)bundle;
-- (void)localizeObject:(id)object recursively:(BOOL)recursive;
-- (void)localizeWindow:(NSWindow *)window recursively:(BOOL)recursive;
-- (void)localizeView:(NSView *)view recursively:(BOOL)recursive;
-- (void)localizeMenu:(NSMenu *)menu recursively:(BOOL)recursive;
-- (void)localizeCell:(NSCell *)cell recursively:(BOOL)recursive;
-- (void)localizeBindings:(id)object;
-// NOTE: NSToolbar localization support is limited to only working on the
-// default items in the toolbar. We cannot localize items that are on of the
-// customization palette but not in the default items because there is not an
-// API for NSToolbar to get all possible items. You are responsible for
-// localizing all non-default toolbar items by hand.
-- (void)localizeToolbar:(NSToolbar *)toolbar;
-
-// Localize an object for accessibility; can be called for both NSViews and
-// NSCells as they are both accessibility objects.
-- (void)localizeAccessibility:(id)object;
+// Localize |object|. If |recursive| is true, it will attempt
+// to localize objects owned/referenced by |object|.
+- (void)localizeObject:(id)object recursively:(BOOL)recursive;
// A method for subclasses to override in case you have a different
// way to go about getting localized strings.
diff --git a/AppKit/GTMUILocalizer.m b/AppKit/GTMUILocalizer.m
index d87f1b4..16d00dd 100644
--- a/AppKit/GTMUILocalizer.m
+++ b/AppKit/GTMUILocalizer.m
@@ -19,6 +19,21 @@
#import "GTMDefines.h"
#import "GTMUILocalizer.h"
+@interface GTMUILocalizer (GTMUILocalizerPrivate)
+- (void)localizeAccessibility:(id)object;
+- (void)localizeBindings:(id)object;
+
+// 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;
+- (void)localizeToolbar:(NSToolbar *)toolbar;
+- (void)localizeView:(NSView *)view recursively:(BOOL)recursive;
+- (void)localizeMenu:(NSMenu *)menu recursively:(BOOL)recursive;
+- (void)localizeCell:(NSCell *)cell recursively:(BOOL)recursive;
+
+@end
+
@implementation GTMUILocalizer
- (id)initWithBundle:(NSBundle *)bundle {
if ((self = [super init])) {
@@ -99,6 +114,8 @@
[self localizeMenu:menu recursively:recursive];
} else if ([object isKindOfClass:[NSCell class]]) {
[self localizeCell:(NSCell *)object recursively:recursive];
+ } else if ([object isKindOfClass:[NSToolbar class]]) {
+ [self localizeToolbar:(NSToolbar*)object];
}
[self localizeBindings:object];
}
@@ -111,11 +128,8 @@
[window setTitle:localizedTitle];
}
if (recursive) {
- NSView *content = [window contentView];
- [self localizeView:content recursively:recursive];
- NSToolbar *toolbar = [window toolbar];
- if (toolbar)
- [self localizeToolbar:toolbar];
+ [self localizeObject:[window contentView] recursively:recursive];
+ [self localizeObject:[window toolbar] recursively:recursive];
}
}
@@ -173,12 +187,12 @@
// Must do the menu before the titles, or else this will screw up
// popup menus on us.
- [self localizeMenu:[view menu] recursively:recursive];
+ [self localizeObject:[view menu] recursively:recursive];
if (recursive) {
NSArray *subviews = [view subviews];
NSView *subview = nil;
GTM_FOREACH_OBJECT(subview, subviews) {
- [self localizeView:subview recursively:recursive];
+ [self localizeObject:subview recursively:recursive];
}
}
@@ -220,7 +234,7 @@
[item setLabel:localizedLabel];
}
if (recursive) {
- [self localizeView:[item view] recursively:recursive];
+ [self localizeObject:[item view] recursively:recursive];
}
}
}
@@ -240,10 +254,10 @@
NSMatrix *matrix = (NSMatrix *)view;
// Process the prototype
id cell = [matrix prototype];
- [self localizeCell:cell recursively:recursive];
+ [self localizeObject:cell recursively:recursive];
// Process the cells
GTM_FOREACH_OBJECT(cell, [matrix cells]) {
- [self localizeCell:cell recursively:recursive];
+ [self localizeObject:cell recursively:recursive];
// The tooltip isn't on a cell, so we do it via the matrix.
NSString *toolTip = [matrix toolTipForCell:cell];
NSString *localizedToolTip = [self localizedStringForString:toolTip];
@@ -259,30 +273,11 @@
NSArray *columns = [tableView tableColumns];
NSTableColumn *column = nil;
GTM_FOREACH_OBJECT(column, columns) {
- [self localizeCell:[column headerCell] recursively:recursive];
+ [self localizeObject:[column headerCell] recursively:recursive];
}
}
}
-- (void)localizeAccessibility:(id)object {
- NSArray *supportedAttrs = [object accessibilityAttributeNames];
- if ([supportedAttrs containsObject:NSAccessibilityHelpAttribute]) {
- NSString *accessibilityHelp
- = [object accessibilityAttributeValue:NSAccessibilityHelpAttribute];
- if (accessibilityHelp) {
- NSString *localizedAccessibilityHelp
- = [self localizedStringForString:accessibilityHelp];
- if (localizedAccessibilityHelp) {
- [object accessibilitySetValue:localizedAccessibilityHelp
- forAttribute:NSAccessibilityHelpAttribute];
- }
- }
- }
-
- // We cannot do the same thing with NSAccessibilityDescriptionAttribute; see
- // the links in the header file for more details.
-}
-
- (void)localizeMenu:(NSMenu *)menu recursively:(BOOL)recursive {
if (menu) {
NSString *title = [menu title];
@@ -299,7 +294,7 @@
[menuItem setTitle:localizedTitle];
}
if (recursive) {
- [self localizeMenu:[menuItem submenu] recursively:recursive];
+ [self localizeObject:[menuItem submenu] recursively:recursive];
}
}
}
@@ -312,7 +307,7 @@
if (localizedTitle) {
[cell setTitle:localizedTitle];
}
- [self localizeMenu:[cell menu] recursively:recursive];
+ [self localizeObject:[cell menu] recursively:recursive];
id obj = [cell representedObject];
[self localizeObject:obj recursively:recursive];
}
@@ -368,4 +363,23 @@
}
}
+- (void)localizeAccessibility:(id)object {
+ NSArray *supportedAttrs = [object accessibilityAttributeNames];
+ if ([supportedAttrs containsObject:NSAccessibilityHelpAttribute]) {
+ NSString *accessibilityHelp
+ = [object accessibilityAttributeValue:NSAccessibilityHelpAttribute];
+ if (accessibilityHelp) {
+ NSString *localizedAccessibilityHelp
+ = [self localizedStringForString:accessibilityHelp];
+ if (localizedAccessibilityHelp) {
+ [object accessibilitySetValue:localizedAccessibilityHelp
+ forAttribute:NSAccessibilityHelpAttribute];
+ }
+ }
+ }
+
+ // We cannot do the same thing with NSAccessibilityDescriptionAttribute; see
+ // the links in the header file for more details.
+}
+
@end
diff --git a/AppKit/GTMUILocalizerTest.m b/AppKit/GTMUILocalizerTest.m
index fc5153c..1f87067 100644
--- a/AppKit/GTMUILocalizerTest.m
+++ b/AppKit/GTMUILocalizerTest.m
@@ -82,14 +82,12 @@
// Test binding localization.
NSTextField *textField = [controller bindingsTextField];
STAssertNotNil(textField, nil);
- [localizer localizeObject:textField recursively:NO];
NSString *displayPatternValue1Binding
- = [NSString stringWithFormat:@"%@1", NSDisplayPatternValueBinding];
-
+ = [NSString stringWithFormat:@"%@1", NSDisplayPatternValueBinding];
[self verifyBinding:displayPatternValue1Binding forObject:textField];
+
NSSearchField *searchField = [controller bindingsSearchField];
STAssertNotNil(searchField, nil);
- [localizer localizeObject:searchField recursively:NO];
[self verifyBinding:NSPredicateBinding forObject:searchField];
[localizer release];