Author: fredkiefer
Date: Thu Mar 12 23:13:42 2015
New Revision: 38405

URL: http://svn.gna.org/viewcvs/gnustep?rev=38405&view=rev
Log:
        * 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.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Source/NSCollectionView.m
    libs/gui/trunk/Source/NSCollectionViewItem.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=38405&r1=38404&r2=38405&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Thu Mar 12 23:13:42 2015
@@ -1,3 +1,11 @@
+2015-03-12 Fred Kiefer <[email protected]>
+
+       * 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 <[email protected]>
 
        * Headers/AppKit/NSCursor.h:

Modified: libs/gui/trunk/Source/NSCollectionView.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSCollectionView.m?rev=38405&r1=38404&r2=38405&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSCollectionView.m    (original)
+++ libs/gui/trunk/Source/NSCollectionView.m    Thu Mar 12 23:13:42 2015
@@ -474,6 +474,7 @@
           [item setSelected: YES];
         }
       [self addSubview: [item view]];
+      RELEASE(item);
     }
   return item;
 }
@@ -486,7 +487,7 @@
       collectionItem = [itemPrototype copy];
       [collectionItem setRepresentedObject: object];
     }
-  return AUTORELEASE (collectionItem);
+  return collectionItem;
 }
 
 - (void) _removeItemsViews

Modified: libs/gui/trunk/Source/NSCollectionViewItem.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSCollectionViewItem.m?rev=38405&r1=38404&r2=38405&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSCollectionViewItem.m        (original)
+++ libs/gui/trunk/Source/NSCollectionViewItem.m        Thu Mar 12 23:13:42 2015
@@ -26,11 +26,13 @@
 */
 
 #import <Foundation/NSArray.h>
+#import <Foundation/NSDictionary.h>
 #import <Foundation/NSKeyedArchiver.h>
 
 #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);
 }
 


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to