Skip to content
Browse files

Merge branch 'master' of github.com:cappuccino/cappuccino into cappuc…

…cino
  • Loading branch information...
2 parents 3ddab9e + d2f3cea commit 5893b339620bee54a86131785fe93282bc1f4a74 @aparajita aparajita committed Mar 27, 2012
View
2 AppKit/CPCheckBox.j
@@ -140,6 +140,8 @@ CPCheckBoxImageOffset = 4.0;
[_source setAllowsMixedState:NO];
}
}
+ else
+ newValue = [self transformValue:newValue withOptions:options];
[_source setState:newValue];
}
View
8 AppKit/CPTableColumn.j
@@ -678,8 +678,11 @@ CPTableColumnUserResizingMask = 1 << 1;
bindingInfo = binding._info,
destination = [bindingInfo objectForKey:CPObservedObjectKey],
keyPath = [bindingInfo objectForKey:CPObservedKeyPathKey],
+ options = [bindingInfo objectForKey:CPOptionsKey],
dotIndex = keyPath.lastIndexOf(".");
+ newValue = [binding reverseTransformValue:newValue withOptions:options];
+
if (dotIndex === CPNotFound)
[[destination valueForKeyPath:keyPath] replaceObjectAtIndex:aRow withObject:newValue];
else
@@ -696,11 +699,6 @@ CPTableColumnUserResizingMask = 1 << 1;
}
}
-//- (void)objectValue
-//{
-// return nil;
-//}
-
@end
var CPTableColumnIdentifierKey = @"CPTableColumnIdentifierKey",
View
3 AppKit/CPView.j
@@ -369,6 +369,9 @@ var CPViewFlags = { },
/* @ignore */
- (void)_insertSubview:(CPView)aSubview atIndex:(int)anIndex
{
+ if (aSubview === self)
+ [CPException raise:CPInvalidArgumentException reason:"can't add a view as a subview of itself"];
+
// We will have to adjust the z-index of all views starting at this index.
var count = _subviews.length;
View
16 Foundation/CPKeyValueObserving.j
@@ -69,8 +69,24 @@
[self[KVOProxyKey] _removeObserver:anObserver forKeyPath:aPath];
}
+/*!
+ Whether -willChangeValueForKey/-didChangeValueForKey should automatically be invoked when the
+ setter of the given key is used. The default is YES. If you override this method to return NO
+ for some key, you will need to call -willChangeValueForKey/-didChangeValueForKey manually to
+ be KVO compliant.
+
+ The default implementation of this method will check if the receiving class implements
+ `+ (BOOL)automaticallyNotifiesObserversOf<aKey>` and return the response of that method if it
+ exists.
+*/
+ (BOOL)automaticallyNotifiesObserversForKey:(CPString)aKey
{
+ var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1),
+ selector = "automaticallyNotifiesObserversOf" + capitalizedKey;
+
+ if ([[self class] respondsToSelector:selector])
+ return objj_msgSend([self class], selector);
+
return YES;
}
View
24 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
+
View
2 Tests/AppKit/CPPopUpButtonTest.j
@@ -178,7 +178,7 @@
withKeyPath:@"weight"
options:nil];
- [self assert:20 equals:[button selectedTag]];
+ [self assert:20 equals:[[button selectedItem] tag]];
[button selectItemAtIndex:1];
// simulate selection by the user (this fails because we don't reverse set the value)
View
26 Tests/Foundation/CPKeyValueObservingTest.j
@@ -193,11 +193,37 @@
notSame:class_getInstanceMethod([object class], removeSelector)];
}
+- (void)testAutomaticallyNotifiesObserversOf
+{
+ var test = [ObservingTester new];
+
+ [test addObserver:self forKeyPath:@"cheese" options:0 context:nil];
+ [test addObserver:self forKeyPath:@"astronaut" options:0 context:nil];
+
+ // Cheese shouldn't have been affected.
+ [test setCheese:@"changed cheese"];
+ [self assert:@"cheese" equals:_lastKeyPath]
+ [self assert:test equals:_lastObject];
+
+ // Cheese shouldn't have been affected.
+ [test setAstronaut:@"Armstrong"];
+ // Nothing should have been observed because we don't automatically notify
+ // and we didn't call will/didChange.
+ [self assert:@"cheese" equals:_lastKeyPath message:"no observation when automatically notifies is off"];
+ [self assert:test equals:_lastObject];
+}
+
@end
@implementation ObservingTester : CPObject
{
id cheese;
+ id astronaut @accessors;
+}
+
++ (BOOL)automaticallyNotifiesObserversOfAstronaut
+{
+ return NO;
}
+ (id)testerWithCheese:(id)aCheese
View
2 Tools/nib2cib/NSAppKit.j
@@ -37,7 +37,6 @@
@import "NSCustomView.j"
@import "NSEvent.j"
@import "NSFont.j"
-@import "NSFormatter.j"
@import "NSIBObjectData.j"
@import "NSImage.j"
@import "NSImageView.j"
@@ -46,7 +45,6 @@
@import "NSMenu.j"
@import "NSMenuItem.j"
@import "NSNibConnector.j"
-@import "NSNumberFormatter.j"
@import "NSObjectController.j"
@import "NSOutlineView.j"
@import "NSPopUpButton.j"
View
2 Tools/nib2cib/NSFoundation.j
@@ -24,6 +24,8 @@
@import "NSAttributedString.j"
@import "NSDictionary.j"
@import "NSExpression.j"
+@import "NSFormatter.j"
@import "NSMutableString.j"
+@import "NSNumberFormatter.j"
@import "NSSet.j"
View
2 bootstrap.sh
@@ -139,7 +139,7 @@ install_directory=""
tmp_zip="/tmp/cappuccino.zip"
github_user="cappuccino"
-github_ref="0.9.6"
+github_ref="v0.9.6-RC1"
noprompt=""
install_capp=""

0 comments on commit 5893b33

Please sign in to comment.
Something went wrong with that request. Please try again.