diff --git a/AppKit/CPRuleEditor/CPRuleEditor.j b/AppKit/CPRuleEditor/CPRuleEditor.j index b1f30dc30..3ac9d2b80 100644 --- a/AppKit/CPRuleEditor/CPRuleEditor.j +++ b/AppKit/CPRuleEditor/CPRuleEditor.j @@ -207,8 +207,28 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType", [self registerForDraggedTypes:[CPArray arrayWithObjects:CPRuleEditorItemPBoardType,nil]]; [_boundArrayOwner addObserver:self forKeyPath:_boundArrayKeyPath options:CPKeyValueObservingOptionOld | CPKeyValueObservingOptionNew context:boundArrayContext]; + + [[CPNotificationCenter defaultCenter] addObserver:self + selector:@selector(_ruleEditorLocalizerDidLoad:) + name:@"_CPRuleEditorLocalizerDidLoadNotification" + object:nil]; } +- (void)_ruleEditorLocalizerDidLoad:(CPNotification)aNotification +{ + if ([aNotification object] === [self standardLocalizer]) + { + // Defer execution to the next run loop cycle so that any active slice + // insertions have fully completed and are present in the `_slices` array. + [[CPRunLoop mainRunLoop] performBlock:function() { + var count = [_slices count]; + for (var i = 0; i < count; i++) + { + [[_slices objectAtIndex:i] _reconfigureSubviews]; + } + } argument:nil order:0 modes:[CPDefaultRunLoopMode]]; + } +} /*! @endcond */ /*! diff --git a/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j b/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j index f9dddbfb9..79ab94da8 100644 --- a/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j +++ b/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j @@ -77,6 +77,9 @@ var LocalizerStringsRegex = new RegExp("\"(.+)\"\\s*=\\s*\"(.+)\"\\s*;\\s*(//.+) } _dictionary = [CPDictionary dictionaryWithDictionary:dict]; + + // Post notification to let the rule editor know the translation dictionary is ready + [[CPNotificationCenter defaultCenter] postNotificationName:@"_CPRuleEditorLocalizerDidLoadNotification" object:self]; } - (CPString)localizedStringForString:(CPString)aString diff --git a/Tests/Manual/CPRuleEditorTestSpanish/RuleDelegate.j b/Tests/Manual/CPRuleEditorTestSpanish/RuleDelegate.j index 1c536b7c6..842056535 100644 --- a/Tests/Manual/CPRuleEditorTestSpanish/RuleDelegate.j +++ b/Tests/Manual/CPRuleEditorTestSpanish/RuleDelegate.j @@ -17,7 +17,8 @@ if ([criterion isEqualToString:@"firstName"] || [criterion isEqualToString:@"lastName"]) { - return [@[@"contains", @"is equal to"] objectAtIndex:index]; + // "is equal to" is placed at index 0 so that the reordered Spanish sentence layout loads automatically on startup + return [@[@"is equal to", @"contains"] objectAtIndex:index]; } if ([criterion isEqualToString:@"age"]) @@ -54,7 +55,7 @@ if ([criterion isEqualToString:@"contains"] || [criterion isEqualToString:@"is equal to"]) { - // Operators have one child representing the input field value + // Operators have 1 child representing the value node return 1; } @@ -104,7 +105,30 @@ } else if ([criterion isEqualToString:@"value"]) { - [parts setObject:[CPExpression expressionForConstantValue:[value stringValue]] forKey:CPRuleEditorPredicateRightExpression]; + // Resolve the correct active text field from the slice row on screen + var activeValue = value; + var slices = [editor valueForKey:@"_slices"]; + + if (slices && row < [slices count]) + { + var slice = [slices objectAtIndex:row]; + var optionViews = [slice valueForKey:@"_ruleOptionViews"]; + if (optionViews) + { + var count = [optionViews count]; + for (var i = 0; i < count; i++) + { + var view = [optionViews objectAtIndex:i]; + if ([view isKindOfClass:[CPTextField class]] && [view isEditable]) + { + activeValue = view; + break; + } + } + } + } + + [parts setObject:[CPExpression expressionForConstantValue:[activeValue stringValue]] forKey:CPRuleEditorPredicateRightExpression]; } return parts;