diff --git a/AppKit/CPCheckBox.j b/AppKit/CPCheckBox.j index 036c8ab24..d58c49402 100644 --- a/AppKit/CPCheckBox.j +++ b/AppKit/CPCheckBox.j @@ -140,6 +140,8 @@ CPCheckBoxImageOffset = 4.0; [_source setAllowsMixedState:NO]; } } + else + newValue = [self transformValue:newValue withOptions:options]; [_source setState:newValue]; } diff --git a/Tests/AppKit/CPCheckBoxTest.j b/Tests/AppKit/CPCheckBoxTest.j index 13d931c58..d2b388dbe 100644 --- a/Tests/AppKit/CPCheckBoxTest.j +++ b/Tests/AppKit/CPCheckBoxTest.j @@ -74,4 +74,28 @@ [self assert:CPOnState equals:[control objectValue] message:"content 1 is on"]; } +- (void)testTransformValueBinding +{ + var control = [[CPCheckBox alloc] initWithFrame:CGRectMakeZero()]; + + content = [ + [CPDictionary dictionaryWithObject:YES forKey:@"state"], + [CPDictionary dictionaryWithObject:NO forKey:@"state"] + ]; + arrayController = [[CPArrayController alloc] initWithContent:content]; + + // First test defaults. + [control bind:CPValueBinding toObject:arrayController withKeyPath:@"selection.state" options:[CPDictionary dictionaryWithObject:@"CPNegateBoolean" forKey:CPValueTransformerNameBindingOption]]; + + [arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndex:0]]; + [self assert:CPOffState equals:[control objectValue] message:"content[0] is negated"] + [arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndex:1]]; + [self assert:CPOnState equals:[control objectValue] message:"content[1] is negated"] + + [control performClick:nil]; + [self assert:CPOffState equals:[control objectValue] message:"value was changed"] + [self assert:YES equals:[content[1] valueForKey:@"state"] message:"content[1] was negated after change"] +} + @end +