From a98def4326f5bc74d0d73bad25753029f5fac03e Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 8 Mar 2013 14:47:08 +0100 Subject: [PATCH 1/3] Added doc for -setItemPrototype: explaining how to setup the item prototype when you want to use bindings for the view. --- AppKit/CPCollectionView.j | 73 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index caa414c96..f29571de2 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -20,8 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#import "../Foundation/CPRange.h" -#import "../Foundation/Ref.h" +//#import "../Foundation/CPRange.h" +//#import "../Foundation/Ref.h" @import @import @@ -35,7 +35,7 @@ @import "CPPasteboard.j" @import "CPView.j" -@class CPClipView +//@class CPClipView /*! @@ -176,50 +176,47 @@ var HORIZONTAL_MARGIN = 2; /*! Sets the item prototype to \c anItem + @param anItem the new item prototype. - The item prototype should implement the CPCoding protocol - because the item is copied by archiving and unarchiving the - prototypal view. + @note + - If anItem is located in an external cib file, representedObject, outlets, and bindings will be automatically restored when an item is created. + - If anItem and its view belong to the same cib as the collection view, the item prototype should implement the CPCoding protocol because the item is copied by archiving and unarchiving the prototypal view. + @note + Bindings won't be restored through archiving, instead you need to subclass the -representedObject: method and update the view there. - Example: + @par Example: -
-      @implement MyCustomView : CPCollectionViewItem
-      {
-          CPArray   items   @accessors;
-      }
+@code
+@implementation MyCustomPrototypeItem: CPCollectionViewItem
+{
+    @outlet CPTextField textField;
+}
 
-      - (id)initWithFrame:(CGRect)aFrame
-      {
-        self = [super initWithFrame:aFrame];
-        if (self)
-        {
-          items = [];
-        }
-        return self;
-      }
+- (id)initWithCoder:(CPCoder)aCoder
+{
+    self = [super initWithCoder:aCoder];
 
-      - (id)initWithCoder:(CPCoder)aCoder
-      {
-        self = [super initWithCoder:aCoder];
-        items = [aCoder decodeObjectForKey:@"KEY"];
-        return self;
-      }
+    textField = [aCoder decodeObjectForKey:@"TextField"];
 
-      - (void)encodeWithCoder:(CPCoder)aCoder
-      {
-        [aCoder encodeObject:items forKey:@"KEY"];
-        [super encodeWithCoder:aCoder];
-      }
+    return self;
+}
 
-      @end
-    
+- (void)encodeWithCoder:(CPCoder)aCoder +{ + [super encodeWithCoder:aCoder]; + [aCoder encodeConditionalObject:textField forKey:@"TextField"]; +} - This will allow the collection view to create multiple 'clean' copies - of the item prototype which will maintain the original values for item - and all of the properties archived by the super class. +- (void)setRepresentedObject:(id)anObject +{ + [super setRepresentedObject:anObject]; + [textField setStringValue:[anObject objectForKey:@"value"]]; + [[self view] setColor:[anObject objectForKey:@"color"]]; +} + +@end +@endcode - @param anItem the new item prototype */ - (void)setItemPrototype:(CPCollectionViewItem)anItem { From 0e4f5e9203317366d1a6c6370be7458ef783bce5 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Mon, 11 Mar 2013 17:14:00 +0100 Subject: [PATCH 2/3] Uncomment import --- AppKit/CPCollectionView.j | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index f29571de2..1f382515b 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -20,8 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -//#import "../Foundation/CPRange.h" -//#import "../Foundation/Ref.h" +#import "../Foundation/CPRange.h" @import @import From 0d168a45189b9feb8b02bacf9c23c659f0adc665 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Mon, 11 Mar 2013 17:52:21 +0100 Subject: [PATCH 3/3] Remove //@class CPClipView --- AppKit/CPCollectionView.j | 3 --- 1 file changed, 3 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 1f382515b..ba9e61d17 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -34,9 +34,6 @@ @import "CPPasteboard.j" @import "CPView.j" -//@class CPClipView - - /*! @ingroup appkit @class CPCollectionView