From e4950bd831116ac5c8582dff0a709460c7448a5e Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sat, 28 May 2011 01:26:28 -0400 Subject: [PATCH] Fixed: duplicate observer notification for array controller addObject: (on arrangedObjects). --- AppKit/CPArrayController.j | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index d98f159d7..0d9fe2b49 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -70,7 +70,8 @@ + (CPSet)keyPathsForValuesAffectingArrangedObjects { - return [CPSet setWithObjects:"content", "filterPredicate", "sortDescriptors"]; + // Also depends on "filterPredicate" but we'll handle that manually. + return [CPSet setWithObjects:"content", "sortDescriptors"]; } + (CPSet)keyPathsForValuesAffectingSelection @@ -488,7 +489,14 @@ */ - (void)setFilterPredicate:(CPPredicate)value { + if (_filterPredicate === value) + return; + + // __setFilterPredicate will call _rearrangeObjects without + // sending notifications, so we must send them instead. + [self willChangeValueForKey:@"arrangedObjects"]; [self __setFilterPredicate:value]; + [self didChangeValueForKey:@"arrangedObjects"]; } /* @@ -501,8 +509,7 @@ return; _filterPredicate = value; - // Use the non-notification version since arrangedObjects already depends - // on filterPredicate. + // Use the non-notification version. [self _rearrangeObjects]; } @@ -745,6 +752,7 @@ else [self _rearrangeObjects]; + // This will also send notificaitons for arrangedObjects. [self didChangeValueForKey:@"content"]; if (_clearsFilterPredicateOnInsertion) [self didChangeValueForKey:@"filterPredicate"];