diff --git a/AppKit/CPDragServer.j b/AppKit/CPDragServer.j index 9d3344b09..bc67ee490 100644 --- a/AppKit/CPDragServer.j +++ b/AppKit/CPDragServer.j @@ -270,10 +270,10 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0, { if ([scrollView hasVerticalScroller]) { - if (eventLocation.y < CGRectGetMinY(insetBounds)) - deltaY = CGRectGetMinY(insetBounds) - eventLocation.y; - else if (eventLocation.y > CGRectGetMaxY(insetBounds)) - deltaY = CGRectGetMaxY(insetBounds) - eventLocation.y; + if (eventLocation.y < _CGRectGetMinY(insetBounds)) + deltaY = _CGRectGetMinY(insetBounds) - eventLocation.y; + else if (eventLocation.y > _CGRectGetMaxY(insetBounds)) + deltaY = _CGRectGetMaxY(insetBounds) - eventLocation.y; if (deltaY < -insetBounds.size.height) deltaY = -insetBounds.size.height; if (deltaY > insetBounds.size.height) @@ -282,17 +282,21 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0, if ([scrollView hasHorizontalScroller]) { - if (eventLocation.x < CGRectGetMinX(insetBounds)) - deltaX = CGRectGetMinX(insetBounds) - eventLocation.x; - else if (eventLocation.x > CGRectGetMaxX(insetBounds)) - deltaX = CGRectGetMaxX(insetBounds) - eventLocation.x; + if (eventLocation.x < _CGRectGetMinX(insetBounds)) + deltaX = _CGRectGetMinX(insetBounds) - eventLocation.x; + else if (eventLocation.x > _CGRectGetMaxX(insetBounds)) + deltaX = _CGRectGetMaxX(insetBounds) - eventLocation.x; if (deltaX < -insetBounds.size.width) deltaX = -insetBounds.size.width; if (deltaX > insetBounds.size.width) deltaX = insetBounds.size.width; } - [contentView scrollToPoint:CGPointMake(bounds.origin.x - deltaX, bounds.origin.y - deltaY)]; + var scrollPoint = _CGPointMake(bounds.origin.x - deltaX, bounds.origin.y - deltaY); + + [contentView scrollToPoint:scrollPoint]; + [[scrollView _headerView] scrollPoint:scrollPoint]; + } } } diff --git a/Foundation/CPArray/CPMutableArray.j b/Foundation/CPArray/CPMutableArray.j index bf0874224..e9588dd51 100644 --- a/Foundation/CPArray/CPMutableArray.j +++ b/Foundation/CPArray/CPMutableArray.j @@ -332,7 +332,7 @@ [self replaceObjectAtIndex:otherIndex withObject:temporary]; } -- (CPArray)sortUsingDescriptors:(CPArray)descriptors +- (void)sortUsingDescriptors:(CPArray)descriptors { [self sortUsingFunction:compareObjectsUsingDescriptors context:descriptors]; } diff --git a/Foundation/CPKeyValueObserving.j b/Foundation/CPKeyValueObserving.j index fbac24c09..ee72d91fc 100644 --- a/Foundation/CPKeyValueObserving.j +++ b/Foundation/CPKeyValueObserving.j @@ -678,6 +678,14 @@ var kvoNewAndOld = CPKeyValueObservingOptionNew | CPKeyValueObservingOpti { var observers = _observersForKey[aPath]; + if (!observers) + { + CPLog.warn(@"Cannot remove an observer %@ for the key path \"%@\" from %@ because it is not registered as an observer.", + _targetObject, aPath, anObserver); + + return; + } + if (aPath.indexOf('.') != CPNotFound) { var forwarder = [observers objectForKey:[anObserver UID]].forwarder; diff --git a/Foundation/CPURL.j b/Foundation/CPURL.j index 1b60010a0..810677c7e 100644 --- a/Foundation/CPURL.j +++ b/Foundation/CPURL.j @@ -227,7 +227,7 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; return self.setResourcePropertyForKey(aKey, anObject); } -- (CPString)staticResourceData +- (CPData)staticResourceData { return self.staticResourceData(); } diff --git a/Tests/AppKit/CPKeyValueObservingTest.j b/Tests/AppKit/CPKeyValueObservingTest.j deleted file mode 100644 index 67e3cd07b..000000000 --- a/Tests/AppKit/CPKeyValueObservingTest.j +++ /dev/null @@ -1,106 +0,0 @@ -@import - -@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]; -} - -@end diff --git a/Tests/Foundation/CPKeyValueObservingTest.j b/Tests/Foundation/CPKeyValueObservingTest.j index 5d43fc8da..2d409618f 100644 --- a/Tests/Foundation/CPKeyValueObservingTest.j +++ b/Tests/Foundation/CPKeyValueObservingTest.j @@ -22,6 +22,45 @@ return [theClass new]; } +- (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]; +} + - (void)testOnlyInsertObject_AtKeyIndex_Implemented { var insertSelector = @selector(insertObject:inObjectsAtIndex:), @@ -155,3 +194,59 @@ } @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]; +} + +@end