From 262bd5b7c1e2cef57a8020f8e42e97eb11650805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Wallstro=CC=88m?= Date: Wed, 6 Mar 2013 19:30:17 +0100 Subject: [PATCH 1/4] Use dedicated class, _CPStateMarker, instead of CPString for selection markers. --- AppKit/CPKeyValueBinding.j | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index e48f9fc22..705ec8be6 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -347,7 +347,7 @@ var CPBindingOperationAnd = 0, - (void)_placeholderForMarker:aMarker { - var placeholder = _placeholderForMarker[aMarker]; + var placeholder = _placeholderForMarker[[aMarker hash]]; if (placeholder) return placeholder['value']; @@ -359,14 +359,14 @@ var CPBindingOperationAnd = 0, { if (isDefault) { - var existingPlaceholder = _placeholderForMarker[aMarker]; + var existingPlaceholder = _placeholderForMarker[[aMarker hash]]; // Don't overwrite an explicitly set placeholder with a default. if (existingPlaceholder && !existingPlaceholder['isDefault']) return; } - _placeholderForMarker[aMarker] = { 'isDefault': isDefault, 'value': aPlaceholder }; + _placeholderForMarker[[aMarker hash]] = { 'isDefault': isDefault, 'value': aPlaceholder }; } @end @@ -802,6 +802,26 @@ var CPBindingOperationAnd = 0, @end +@implementation _CPStateMarker : CPObject +{ + CPString _name; +} + +- (id)initWithName:(CPString)aName +{ + if (self = [super init]) + _name = aName + + return self; +} + +- (CPString)description +{ + return "<" + _name + ">"; +} + +@end + // Keys in options dictionary @@ -811,10 +831,10 @@ CPObservedKeyPathKey = @"CPObservedKeyPathKey"; CPOptionsKey = @"CPOptionsKey"; // special markers -CPMultipleValuesMarker = @"CPMultipleValuesMarker"; -CPNoSelectionMarker = @"CPNoSelectionMarker"; -CPNotApplicableMarker = @"CPNotApplicableMarker"; -CPNullMarker = @"CPNullMarker"; +CPNoSelectionMarker = [[_CPStateMarker alloc] initWithName:@"NO SELECTION MARKER"]; +CPMultipleValuesMarker = [[_CPStateMarker alloc] initWithName:@"MULTIPLE VALUES MARKER"]; +CPNotApplicableMarker = [[_CPStateMarker alloc] initWithName:@"NOT APPLICABLE MARKER"]; +CPNullMarker = [[_CPStateMarker alloc] initWithName:@"NULL MARKER"]; // Binding name constants CPAlignmentBinding = @"alignment"; From 51e682335bb66c0ab163eb9fc48e41e43c3fac6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Wallstro=CC=88m?= Date: Thu, 7 Mar 2013 12:37:35 +0100 Subject: [PATCH 2/4] Use UID instead of hash. --- AppKit/CPKeyValueBinding.j | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index 705ec8be6..ab9a9f369 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -347,7 +347,7 @@ var CPBindingOperationAnd = 0, - (void)_placeholderForMarker:aMarker { - var placeholder = _placeholderForMarker[[aMarker hash]]; + var placeholder = _placeholderForMarker[[aMarker UID]]; if (placeholder) return placeholder['value']; @@ -359,14 +359,14 @@ var CPBindingOperationAnd = 0, { if (isDefault) { - var existingPlaceholder = _placeholderForMarker[[aMarker hash]]; + var existingPlaceholder = _placeholderForMarker[[aMarker UID]]; // Don't overwrite an explicitly set placeholder with a default. if (existingPlaceholder && !existingPlaceholder['isDefault']) return; } - _placeholderForMarker[[aMarker hash]] = { 'isDefault': isDefault, 'value': aPlaceholder }; + _placeholderForMarker[[aMarker UID]] = { 'isDefault': isDefault, 'value': aPlaceholder }; } @end From 455ff57eeca48c16f865bd054bbefbc72a65187a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Wallstro=CC=88m?= Date: Thu, 7 Mar 2013 12:39:04 +0100 Subject: [PATCH 3/4] Fixed return type for _placeholderForMarker: --- AppKit/CPKeyValueBinding.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index ab9a9f369..96bc70687 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -345,7 +345,7 @@ var CPBindingOperationAnd = 0, [self _updatePlaceholdersWithOptions:options]; } -- (void)_placeholderForMarker:aMarker +- (JSObject)_placeholderForMarker:aMarker { var placeholder = _placeholderForMarker[[aMarker UID]]; From bd269501ace03d37117e031fef44820bad077440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Wallstro=CC=88m?= Date: Thu, 7 Mar 2013 12:49:19 +0100 Subject: [PATCH 4/4] Fixed parameter type for _placeholderForMarker: --- AppKit/CPKeyValueBinding.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index 96bc70687..524f7e0dd 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -345,7 +345,7 @@ var CPBindingOperationAnd = 0, [self _updatePlaceholdersWithOptions:options]; } -- (JSObject)_placeholderForMarker:aMarker +- (JSObject)_placeholderForMarker:(id)aMarker { var placeholder = _placeholderForMarker[[aMarker UID]];