diff --git a/ChangeLog b/ChangeLog index 4144ec17c..41efc291a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-03-12 Fred Kiefer + + * Source/NSCollectionView.m (-newItemForRepresentedObject:): Don't + autorelease the returned object as this method starts with "new". + * Source/NSCollectionViewItem.m (-copyWithZone:): Add call to new + method to copy over the bindings from the old view hierarchy to + the new. + 2015-03-11 Germán Arias * Headers/AppKit/NSCursor.h: diff --git a/Source/NSCollectionView.m b/Source/NSCollectionView.m index 87cee63b7..f6b2ef8a1 100644 --- a/Source/NSCollectionView.m +++ b/Source/NSCollectionView.m @@ -474,6 +474,7 @@ static NSString *placeholderItem = nil; [item setSelected: YES]; } [self addSubview: [item view]]; + RELEASE(item); } return item; } @@ -486,7 +487,7 @@ static NSString *placeholderItem = nil; collectionItem = [itemPrototype copy]; [collectionItem setRepresentedObject: object]; } - return AUTORELEASE (collectionItem); + return collectionItem; } - (void) _removeItemsViews diff --git a/Source/NSCollectionViewItem.m b/Source/NSCollectionViewItem.m index 152d8e95b..d8242c29d 100644 --- a/Source/NSCollectionViewItem.m +++ b/Source/NSCollectionViewItem.m @@ -26,11 +26,13 @@ */ #import +#import #import #import "AppKit/NSCollectionView.h" #import "AppKit/NSCollectionViewItem.h" #import "AppKit/NSImageView.h" +#import "AppKit/NSKeyValueBinding.h" #import "AppKit/NSTextField.h" @implementation NSCollectionViewItem @@ -149,11 +151,50 @@ } } +- (void) copyBindingsTo: (NSCollectionViewItem*)newItem + from: (NSView*)view + onto: (NSView*)newView +{ + NSArray *exposedBindings = [view exposedBindings]; + NSEnumerator *e = [exposedBindings objectEnumerator]; + NSString *binding = nil; + while ((binding = [e nextObject]) != nil) + { + NSDictionary *info = [view infoForBinding: binding]; + if (info != nil) + { + NSObject *target = [info objectForKey: NSObservedObjectKey]; + if (target == self) + { + [newView bind: binding + toObject: newItem + withKeyPath: [info objectForKey: NSObservedKeyPathKey] + options: [info objectForKey: NSOptionsKey]]; + } + } + } + + NSView *sub1 = nil; + NSEnumerator *e1 = [[view subviews] objectEnumerator]; + NSView *sub2 = nil; + NSEnumerator *e2 = [[newView subviews] objectEnumerator]; + while ((sub1 = [e1 nextObject]) != nil) + { + sub2 = [e2 nextObject]; + [self copyBindingsTo: newItem from: sub1 onto: sub2]; + } + } + - (id) copyWithZone: (NSZone *)zone { + // FIXME: Cache this data, as we need a lot of copies NSData *itemAsData = [NSKeyedArchiver archivedDataWithRootObject: self]; NSCollectionViewItem *newItem = [NSKeyedUnarchiver unarchiveObjectWithData: itemAsData]; + + // Try to copy bindings too + [self copyBindingsTo: newItem from: [self view] onto: [newItem view]]; + return RETAIN(newItem); }