From a2755221d0cd6e236b5bd2b8426ead8d458fdb35 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 12 Sep 2014 22:33:50 +0200 Subject: [PATCH] The cocoa behavior is: Exclusive bindings are impossible in IB Possible in code (tested with segmented control and selectedIndex & selectedTag) but then you get unexpected behavior. A segment can be selected after a click and then changes to another segment. After this commit, extra exclusive bindings are just ignored and we warn about it. --- AppKit/CPKeyValueBinding.j | 3 +-- Tests/AppKit/CPKeyValueBindingTest.j | 13 ++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index 3e0989998..263fc3435 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -454,8 +454,7 @@ var CPBindingOperationAnd = 0, if (![CPBinder isBindingAllowed:aBinding forObject:self]) { - [CPException raise:CPGenericException - reason:@"Cannot bind " + aBinding + " because a binding with the same functionality is already in use."]; + CPLog.warn([self description] + " : cannot bind " + aBinding + " because another binding with the same functionality is already in use."); return; } //if (![[self exposedBindings] containsObject:aBinding]) diff --git a/Tests/AppKit/CPKeyValueBindingTest.j b/Tests/AppKit/CPKeyValueBindingTest.j index 701e1d858..8412e18a9 100644 --- a/Tests/AppKit/CPKeyValueBindingTest.j +++ b/Tests/AppKit/CPKeyValueBindingTest.j @@ -342,7 +342,7 @@ [self assert:@"brie" equals:[control2 objectValue] message:@"control2 objectValue is wrong"]; } -- (void)testExclusiveBindingsThrowsException +- (void)testExclusiveBindings { var segmented = [[CPSegmentedControl alloc] initWithFrame:CGRectMakeZero()]; [segmented setSegmentCount:3]; @@ -351,10 +351,13 @@ [segmented bind:CPSelectedIndexBinding toObject:model withKeyPath:@"cheese" options:nil]; - [self assertThrows:function() - { - [segmented bind:CPSelectedTagBinding toObject:model withKeyPath:@"cheese" options:nil]; - }]; + // Try to bind another binding (mutually exclusive) to the same value. + [segmented bind:CPSelectedTagBinding toObject:model withKeyPath:@"cheese" options:nil]; + + [self assertNotNull:[segmented infoForBinding:CPSelectedIndexBinding]]; + + // Check that the source is not binded with the CPSelectedTagBinding + [self assertNull:[segmented infoForBinding:CPSelectedTagBinding]]; } @end