aboutsummaryrefslogtreecommitdiff
path: root/AppKit/GTMUILocalizer.m
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/GTMUILocalizer.m
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/GTMUILocalizer.m')
-rw-r--r--AppKit/GTMUILocalizer.m78
1 files changed, 46 insertions, 32 deletions
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