Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

A binding with 'NSNegateBoolean' transformer will not handle 'nil' correct #1986

Open
wants to merge 1 commit into from

4 participants

@mrcarlberg
Collaborator

I have no fix for this as I have a hard time figuring out how to solve this. I have only done the test case. Any help in doing this should be highly appreciated.

The corresponding working Objective-C test case is here:

- (void)testTransformValueBinding {
    NSButton *control = [[NSButton alloc] initWithFrame:CGRectZero];
    [control setButtonType:NSSwitchButton];

    NSArray *content =
    @[
     [@{ @"state": @YES } mutableCopy],
     [@{ @"state": @NO } mutableCopy],
     [@{} mutableCopy]
     ];

    NSArrayController *arrayController = [[NSArrayController alloc] initWithContent:content];

    [control bind:NSValueBinding toObject:arrayController withKeyPath:@"selection.state" options:@{ NSValueTransformerNameBindingOption: @"NSNegateBoolean" }];

    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:0]];
    STAssertEqualObjects([control objectValue], @(NSOffState), @"content[0] is negated");
    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:1]];
    STAssertEqualObjects([control objectValue], @(NSOnState), @"content[1] is negated");
    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:2]];
    STAssertEqualObjects([control objectValue], @(NSOnState), @"content[2] is negated");

    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:1]];
    [control performClick:nil];
    STAssertEqualObjects([control objectValue], @(NSOffState), @"value was changed");
    STAssertEqualObjects([content[1] valueForKey:@"state"], @YES, @"content[1] was negated after change");

    [arrayController setSelectionIndexes:[NSIndexSet indexSetWithIndex:2]];
    [control performClick:nil];
    STAssertEqualObjects([control objectValue], @(NSOffState), @"value was changed");
    STAssertEqualObjects([content[2] valueForKey:@"state"], @YES, @"content[2] was negated after change");
}
@cappbot
Collaborator

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

@aljungberg
Owner

Shouldn't NSIsNotNilTransformer be used for a value that can be nil?

@mrcarlberg
Collaborator

Yes, it can. But now I have a bool value that I need to negate. If it is null it should be counted as false and after the transformer it should be true. This doesn't not work in Cappuccino. It does work in Cocoa as the test case shows.

@mrcarlberg
Collaborator

I can add that the reason for not working is that when the value is null it will be a 'null marker' and transformers are not applied when the value is a 'marker'.

@ahankinson

-#new
+#needs-patch

@cappbot
Collaborator

Milestone: Someday. Label: #needs-patch. What's next? This issue needs a volunteer to write and submit code to address it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 Tests/AppKit/CPCheckBoxTest.j
View
11 Tests/AppKit/CPCheckBoxTest.j
@@ -77,7 +77,8 @@
var content =
[
@{ @"state": YES },
- @{ @"state": NO }
+ @{ @"state": NO },
+ @{}
],
arrayController = [[CPArrayController alloc] initWithContent:content];
@@ -88,10 +89,18 @@
[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"]
+ [arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndex:2]];
+ [self assert:CPOnState equals:[control objectValue] message:"content[2] is negated"]
+ [arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndex:1]];
[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"]
+
+ [arrayController setSelectionIndexes:[CPIndexSet indexSetWithIndex:2]];
+ [control performClick:nil];
+ [self assert:CPOffState equals:[control objectValue] message:"value was changed"]
+ [self assert:YES equals:[content[2] valueForKey:@"state"] message:"content[2] was negated after change"]
}
@end
Something went wrong with that request. Please try again.