mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-25 07:55:52 +00:00
Merge branch 'master' of git://github.com/280north/cappuccino
This commit is contained in:
commit
ca0ed0ccb9
4 files changed
+128
-10
No files matched your search
@@ -260,10 +260,6 @@ CPDeleteForwardKeyCode = 46;
|
||||
[[self nextResponder] insertNewline:aSender];
|
||||
}
|
||||
|
||||
- (void)cancel:(id)sender
|
||||
{
|
||||
}
|
||||
|
||||
- (void)insertTab:(id)sender
|
||||
{
|
||||
}
|
||||
@@ -303,7 +299,7 @@ CPDeleteForwardKeyCode = 46;
|
||||
*/
|
||||
- (BOOL)tryToPerform:(SEL)aSelector with:(id)anObject
|
||||
{
|
||||
if([self respondsToSelector:aSelector])
|
||||
if ([self respondsToSelector:aSelector])
|
||||
{
|
||||
[self performSelector:aSelector withObject:anObject];
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
+ (CPSet)keyPathsForValuesAffectingValueForKey:(CPString)aKey
|
||||
{
|
||||
var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1);
|
||||
var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1),
|
||||
selector = "keyPathsForValuesAffecting" + capitalizedKey;
|
||||
|
||||
if ([[self class] respondsToSelector:selector])
|
||||
@@ -173,7 +173,7 @@ CPKeyValueChangeInsertion = 2;
|
||||
CPKeyValueChangeRemoval = 3;
|
||||
CPKeyValueChangeReplacement = 4;
|
||||
|
||||
var kvoNewAndOld = CPKeyValueObservingOptionNew|CPKeyValueObservingOptionOld,
|
||||
var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOptionOld,
|
||||
DependentKeysKey = "$KVODEPENDENT",
|
||||
KVOProxyKey = "$KVOPROXY";
|
||||
|
||||
@@ -325,7 +325,25 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew|CPKeyValueObservingOptionOld,
|
||||
}
|
||||
|
||||
[affectedKeys addObject:aKey];
|
||||
[self _replaceSetterForKey:affectingKey];
|
||||
|
||||
// Observe key paths of objects other then ourselves, so ware notified of the changes
|
||||
if (affectingKey.indexOf(@".") !== -1)
|
||||
[_targetObject addObserver:self forKeyPath:affectingKey options:0 context:nil];
|
||||
else
|
||||
[self _replaceSetterForKey:affectingKey];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(CPString)theKeyPath ofObject:(id)theObject change:(CPDictionary)theChanges context:(id)theContext
|
||||
{
|
||||
// Fire change events for the dependent keys
|
||||
var dependentKeysForClass = _nativeClass[DependentKeysKey],
|
||||
dependantKeys = [dependentKeysForClass[theKeyPath] allObjects];
|
||||
|
||||
for (var i = 0; i < [dependantKeys count]; i++)
|
||||
{
|
||||
var dependantKey = [dependantKeys objectAtIndex:i];
|
||||
[self _sendNotificationsForKey:dependantKey changeOptions:theChanges isBefore:NO];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +378,7 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew|CPKeyValueObservingOptionOld,
|
||||
newValue = [CPNull null];
|
||||
|
||||
var changes = [CPDictionary dictionaryWithObject:newValue forKey:CPKeyValueChangeNewKey];
|
||||
[anObserver observeValueForKeyPath:aPath ofObject:self change:changes context:aContext];
|
||||
[anObserver observeValueForKeyPath:aPath ofObject:_targetObject change:changes context:aContext];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ CPLog(@"Got some class: %@", inst);
|
||||
|
||||
if (signature)
|
||||
{
|
||||
invocation = [CPInvocation invocationWithMethodSignature:signature];
|
||||
var invocation = [CPInvocation invocationWithMethodSignature:signature];
|
||||
|
||||
[invocation setTarget:self];
|
||||
[invocation setSelector:aSelector];
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
@import <Foundation/CPKeyValueObserving.j>
|
||||
|
||||
@implementation CPKeyValueObservingTest : OJTestCase
|
||||
{
|
||||
CPString _lastKeyPath;
|
||||
id _lastObject;
|
||||
CPDictionary _lastChange;
|
||||
id _lastContext;
|
||||
}
|
||||
|
||||
- (void)setup
|
||||
{
|
||||
_lastKeyPath = _lastObject = _lastChange = _lastContext = nil;
|
||||
}
|
||||
|
||||
- (void)testInitialObserving
|
||||
{
|
||||
var tester = [ObservingTester testerWithCheese:@"CHEESE!"];
|
||||
[tester addObserver:self forKeyPath:@"cheese" options:CPKeyValueObservingOptionNew | CPKeyValueObservingOptionInitial context:nil];
|
||||
|
||||
[self assert:@"cheese" equals:_lastKeyPath];
|
||||
[self assert:tester equals:_lastObject];
|
||||
[self assert:[CPDictionary dictionaryWithObject:@"CHEESE!" forKey:CPKeyValueChangeNewKey] equals:_lastChange];
|
||||
[self assert:nil equals:_lastContext];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(CPString)aKeyPath
|
||||
ofObject:(id)anObject
|
||||
change:(CPDictionary)aChange
|
||||
context:(id)aContext
|
||||
{
|
||||
_lastKeyPath = aKeyPath;
|
||||
_lastObject = anObject;
|
||||
_lastChange = aChange;
|
||||
_lastContext = aContext;
|
||||
}
|
||||
|
||||
- (void)testSendNotificationsForDependantKeyPaths
|
||||
{
|
||||
var observingTester = [ObservingTester testerWithCheese:@"cheese"],
|
||||
dependantKeyPathTester = [DependantKeyPathsTester testerWithObservingTester:observingTester];
|
||||
|
||||
[dependantKeyPathTester addObserver:self forKeyPath:@"observedCheese" options:CPKeyValueObservingOptionNew context:nil];
|
||||
[observingTester setCheese:@"changed cheese"];
|
||||
|
||||
[self assert:@"observedCheese" equals:_lastKeyPath]
|
||||
[self assert:dependantKeyPathTester equals:_lastObject];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ObservingTester : CPObject
|
||||
{
|
||||
id cheese;
|
||||
}
|
||||
|
||||
+ (id)testerWithCheese:(id)aCheese
|
||||
{
|
||||
var tester = [[self alloc] init];
|
||||
[tester setCheese:aCheese];
|
||||
return tester;
|
||||
}
|
||||
|
||||
- (void)setCheese:(id)aCheese
|
||||
{
|
||||
cheese = aCheese;
|
||||
}
|
||||
|
||||
- (id)cheese
|
||||
{
|
||||
return cheese;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation DependantKeyPathsTester: CPObject
|
||||
{
|
||||
ObservingTester _observingTester @accessors(property=observingTester);
|
||||
}
|
||||
|
||||
+ (CPSet)keyPathsForValuesAffectingObservedCheese
|
||||
{
|
||||
return [CPSet setWithObjects:@"observingTester.cheese"];
|
||||
}
|
||||
|
||||
+ (id)testerWithObservingTester:(ObservingTester)theObservingTester
|
||||
{
|
||||
return [[self alloc] initWithObservingTester:theObservingTester];
|
||||
}
|
||||
|
||||
- (id)initWithObservingTester:(ObservingTester)theObservingTester
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_observingTester = theObservingTester;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPString)observedCheese
|
||||
{
|
||||
return [[self observingTester] cheese];
|
||||
}
|
||||
Reference in new issue
Block a user