From ca60e501283b558f34ea556ad23213b962b5c0a2 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Mon, 22 Nov 2010 17:47:03 +0100 Subject: [PATCH] small bindings fix in CPObjectController CPObjectController would attempt to remove observations from the new selection in stead of the old selection. This would throw an error when binding to longer compound key paths like selection.customer.name Fixes #967 --- AppKit/CPObjectController.j | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/AppKit/CPObjectController.j b/AppKit/CPObjectController.j index bc4acfca3..bd5fb2793 100644 --- a/AppKit/CPObjectController.j +++ b/AppKit/CPObjectController.j @@ -503,11 +503,13 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb @implementation CPControllerSelectionProxy : CPObject { - id _controller; - id _keys; + id _controller; + id _keys; - CPDictionary _cachedValues; - CPArray _observationProxies; + CPDictionary _cachedValues; + CPArray _observationProxies; + + _CPObservableArray _observedObjects; } - (id)initWithController:(id)aController @@ -610,7 +612,10 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb [proxy setNotifyObject:YES]; [_observationProxies addObject:proxy]; - [[_controller selectedObjects] addObserver:proxy forKeyPath:aKeyPath options:options context:context]; + // We keep are reference to the observed objects + // because the removeObserver: will be called after the selection changes + _observedObjects = [_controller selectedObjects]; + [_observedObjects addObserver:proxy forKeyPath:aKeyPath options:options context:context]; } - (void)removeObserver:(id)anObject forKeyPath:(CPString)aKeyPath @@ -618,8 +623,10 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb var proxy = [[_CPObservationProxy alloc] initWithKeyPath:aKeyPath observer:anObject object:self], index = [_observationProxies indexOfObject:proxy]; - [[_controller selectedObjects] removeObserver:[_observationProxies objectAtIndex:index] forKeyPath:aKeyPath]; + [_observedObjects removeObserver:[_observationProxies objectAtIndex:index] forKeyPath:aKeyPath]; [_observationProxies removeObjectAtIndex:index]; + + _observedObjects = nil; } @end