Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[FIX] -setContent: should check which items should be added or remove…

…d from the view, rather than just adding everything again.
  • Loading branch information...
commit b0863e13016bba874d82b2f101edbacf0d769118 1 parent 4292f24
Matt Ball authored March 28, 2009
71  English.lproj/MainMenu.xib
@@ -1114,7 +1114,7 @@
1114 1114
 			<object class="NSWindowTemplate" id="972006081">
1115 1115
 				<int key="NSWindowStyleMask">15</int>
1116 1116
 				<int key="NSWindowBacking">2</int>
1117  
-				<string key="NSWindowRect">{{335, 521}, {623, 229}}</string>
  1117
+				<string key="NSWindowRect">{{335, 501}, {623, 249}}</string>
1118 1118
 				<int key="NSWTFlags">1946157056</int>
1119 1119
 				<string key="NSWindowTitle">Window</string>
1120 1120
 				<string key="NSWindowClass">NSWindow</string>
@@ -1128,12 +1128,40 @@
1128 1128
 						<object class="NSCustomView" id="260292442">
1129 1129
 							<reference key="NSNextResponder" ref="439893737"/>
1130 1130
 							<int key="NSvFlags">286</int>
1131  
-							<string key="NSFrameSize">{623, 229}</string>
  1131
+							<string key="NSFrame">{{0, 20}, {623, 229}}</string>
1132 1132
 							<reference key="NSSuperview" ref="439893737"/>
1133 1133
 							<string key="NSClassName">MBCoverFlowView</string>
1134 1134
 						</object>
  1135
+						<object class="NSButton" id="184616755">
  1136
+							<reference key="NSNextResponder" ref="439893737"/>
  1137
+							<int key="NSvFlags">292</int>
  1138
+							<string key="NSFrame">{{6, 0}, {33, 19}}</string>
  1139
+							<reference key="NSSuperview" ref="439893737"/>
  1140
+							<bool key="NSEnabled">YES</bool>
  1141
+							<object class="NSButtonCell" key="NSCell" id="18111438">
  1142
+								<int key="NSCellFlags">-2080244224</int>
  1143
+								<int key="NSCellFlags2">134217728</int>
  1144
+								<string key="NSContents">Round Rect Button</string>
  1145
+								<object class="NSFont" key="NSSupport">
  1146
+									<string key="NSName">LucidaGrande</string>
  1147
+									<double key="NSSize">1.200000e+01</double>
  1148
+									<int key="NSfFlags">16</int>
  1149
+								</object>
  1150
+								<reference key="NSControlView" ref="184616755"/>
  1151
+								<int key="NSButtonFlags">-2033958657</int>
  1152
+								<int key="NSButtonFlags2">164</int>
  1153
+								<object class="NSCustomResource" key="NSNormalImage">
  1154
+									<string key="NSClassName">NSImage</string>
  1155
+									<string key="NSResourceName">NSAddTemplate</string>
  1156
+								</object>
  1157
+								<string key="NSAlternateContents"/>
  1158
+								<string key="NSKeyEquivalent"/>
  1159
+								<int key="NSPeriodicDelay">400</int>
  1160
+								<int key="NSPeriodicInterval">75</int>
  1161
+							</object>
  1162
+						</object>
1135 1163
 					</object>
1136  
-					<string key="NSFrameSize">{623, 229}</string>
  1164
+					<string key="NSFrameSize">{623, 249}</string>
1137 1165
 					<reference key="NSSuperview"/>
1138 1166
 				</object>
1139 1167
 				<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
@@ -1685,6 +1713,14 @@
1685 1713
 					</object>
1686 1714
 					<int key="connectionID">452</int>
1687 1715
 				</object>
  1716
+				<object class="IBConnectionRecord">
  1717
+					<object class="IBActionConnection" key="connection">
  1718
+						<string key="label">addItem:</string>
  1719
+						<reference key="source" ref="593156221"/>
  1720
+						<reference key="destination" ref="184616755"/>
  1721
+					</object>
  1722
+					<int key="connectionID">455</int>
  1723
+				</object>
1688 1724
 			</object>
1689 1725
 			<object class="IBMutableOrderedSet" key="objectRecords">
1690 1726
 				<object class="NSArray" key="orderedObjects">
@@ -2272,6 +2308,7 @@
2272 2308
 						<object class="NSMutableArray" key="children">
2273 2309
 							<bool key="EncodedWithXMLCoder">YES</bool>
2274 2310
 							<reference ref="260292442"/>
  2311
+							<reference ref="184616755"/>
2275 2312
 						</object>
2276 2313
 						<reference key="parent" ref="972006081"/>
2277 2314
 					</object>
@@ -2595,6 +2632,20 @@
2595 2632
 						<reference key="object" ref="593156221"/>
2596 2633
 						<reference key="parent" ref="1049"/>
2597 2634
 					</object>
  2635
+					<object class="IBObjectRecord">
  2636
+						<int key="objectID">453</int>
  2637
+						<reference key="object" ref="184616755"/>
  2638
+						<object class="NSMutableArray" key="children">
  2639
+							<bool key="EncodedWithXMLCoder">YES</bool>
  2640
+							<reference ref="18111438"/>
  2641
+						</object>
  2642
+						<reference key="parent" ref="439893737"/>
  2643
+					</object>
  2644
+					<object class="IBObjectRecord">
  2645
+						<int key="objectID">454</int>
  2646
+						<reference key="object" ref="18111438"/>
  2647
+						<reference key="parent" ref="184616755"/>
  2648
+					</object>
2598 2649
 				</object>
2599 2650
 			</object>
2600 2651
 			<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2789,6 +2840,8 @@
2789 2840
 					<string>420.IBPluginDependency</string>
2790 2841
 					<string>450.IBPluginDependency</string>
2791 2842
 					<string>451.IBPluginDependency</string>
  2843
+					<string>453.IBPluginDependency</string>
  2844
+					<string>454.IBPluginDependency</string>
2792 2845
 					<string>5.IBPluginDependency</string>
2793 2846
 					<string>5.ImportedFromIB2</string>
2794 2847
 					<string>56.IBPluginDependency</string>
@@ -2959,8 +3012,8 @@
2959 3012
 					<reference ref="9"/>
2960 3013
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2961 3014
 					<reference ref="9"/>
2962  
-					<string>{{139, 478}, {623, 229}}</string>
2963  
-					<string>{{139, 478}, {623, 229}}</string>
  3015
+					<string>{{139, 458}, {623, 249}}</string>
  3016
+					<string>{{139, 458}, {623, 249}}</string>
2964 3017
 					<reference ref="9"/>
2965 3018
 					<string>{{33, 99}, {480, 360}}</string>
2966 3019
 					<string>{3.40282e+38, 3.40282e+38}</string>
@@ -3016,6 +3069,8 @@
3016 3069
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3017 3070
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3018 3071
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  3072
+					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  3073
+					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3019 3074
 					<reference ref="9"/>
3020 3075
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3021 3076
 					<reference ref="9"/>
@@ -3072,7 +3127,7 @@
3072 3127
 				</object>
3073 3128
 			</object>
3074 3129
 			<nil key="sourceID"/>
3075  
-			<int key="maxID">452</int>
  3130
+			<int key="maxID">455</int>
3076 3131
 		</object>
3077 3132
 		<object class="IBClassDescriber" key="IBDocument.Classes">
3078 3133
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3088,6 +3143,10 @@
3088 3143
 				<object class="IBPartialClassDescription">
3089 3144
 					<string key="className">MBCoverFlowViewController</string>
3090 3145
 					<string key="superclassName">NSViewController</string>
  3146
+					<object class="NSMutableDictionary" key="actions">
  3147
+						<string key="NS.key.0">addItem:</string>
  3148
+						<string key="NS.object.0">id</string>
  3149
+					</object>
3091 3150
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
3092 3151
 						<string key="majorKey">IBProjectSource</string>
3093 3152
 						<string key="minorKey">MBCoverFlowViewController.h</string>
52  MBCoverFlowView.m
@@ -62,7 +62,8 @@ @interface MBCoverFlowView ()
62 62
 - (float)_positionOfSelectedItem;
63 63
 - (CALayer *)_newLayer;
64 64
 - (void)_scrollerChange:(MBCoverFlowScroller *)scroller;
65  
-- (void)_refreshImagesWithOldContent:(NSArray *)oldContent;
  65
+- (void)_refreshLayers;
  66
+- (CALayer *)_layerForObject:(id)object;
66 67
 @end
67 68
 
68 69
 
@@ -341,7 +342,7 @@ - (void)resizeSubviewsWithOldSize:(NSSize)oldSize
341 342
 #pragma mark Loading Data
342 343
 
343 344
 - (void)setContent:(NSArray *)newContents
344  
-{
  345
+{	
345 346
 	NSArray *oldContent = [self.content retain];
346 347
 	
347 348
 	if (_content) {
@@ -353,8 +354,30 @@ - (void)setContent:(NSArray *)newContents
353 354
 		_content = [newContents copy];
354 355
 	}
355 356
 	
356  
-	[self _refreshImagesWithOldContent:oldContent];
  357
+	// Add any new items
  358
+	NSMutableArray *itemsToAdd = [NSMutableArray arrayWithArray:self.content];
  359
+	[itemsToAdd removeObjectsInArray:oldContent];
  360
+	
  361
+	for (NSObject *object in itemsToAdd) {
  362
+		CALayer *layer = [self _newLayer];
  363
+		[layer setValue:object forKey:@"representedObject"];
  364
+	}
  365
+	
  366
+	// Remove any items which are no longer present
  367
+	NSMutableArray *itemsToRemove = [NSMutableArray arrayWithArray:oldContent];
  368
+	[itemsToRemove removeObjectsInArray:self.content];
  369
+	for (NSObject *object in itemsToRemove) {
  370
+		CALayer *layer = [self _layerForObject:object];
  371
+		[layer removeFromSuperlayer];
  372
+	}
  373
+	
357 374
 	[oldContent release];
  375
+	
  376
+	// Update the images and indexes
  377
+	[self _refreshLayers];
  378
+	
  379
+	[_scroller setNumberOfIncrements:([self.content count]-1)];
  380
+	self.selectionIndex = self.selectionIndex;
358 381
 }
359 382
 
360 383
 #pragma mark Setting Display Attributes
@@ -601,13 +624,17 @@ - (void)_scrollerChange:(MBCoverFlowScroller *)sender
601 624
 	}
602 625
 }
603 626
 
604  
-- (void)_refreshImagesWithOldContent:(NSArray *)oldContent
  627
+- (void)_refreshLayers
605 628
 {	
606  
-	for (NSObject *object in self.content) {
607  
-		CALayer *layer = [self _newLayer];
  629
+	for (CALayer *layer in [_scrollLayer sublayers]) {
608 630
 		CALayer *imageLayer = [[layer sublayers] objectAtIndex:0];
609 631
 		CALayer *reflectionLayer = [[imageLayer sublayers] objectAtIndex:0];
610 632
 		
  633
+		NSObject *object = [layer valueForKey:@"representedObject"];
  634
+		NSInteger index = [self.content indexOfObject:object];
  635
+		
  636
+		[layer setValue:[NSNumber numberWithInteger:index] forKey:@"index"];
  637
+		
611 638
 		@try {
612 639
 			NSImage *image;
613 640
 			
@@ -628,9 +655,16 @@ - (void)_refreshImagesWithOldContent:(NSArray *)oldContent
628 655
 			continue;
629 656
 		}
630 657
 	}
631  
-	
632  
-	[_scroller setNumberOfIncrements:([self.content count]-1)];
633  
-	self.selectionIndex = self.selectionIndex;
  658
+}
  659
+
  660
+- (CALayer *)_layerForObject:(id)object
  661
+{
  662
+	for (CALayer *layer in [_scrollLayer sublayers]) {
  663
+		if ([object isEqual:[layer valueForKey:@"representedObject"]]) {
  664
+			return layer;
  665
+		}
  666
+	}
  667
+	return nil;
634 668
 }
635 669
 
636 670
 #pragma mark -
4  MBCoverFlowViewController.h
@@ -28,7 +28,9 @@
28 28
 
29 29
 
30 30
 @interface MBCoverFlowViewController : NSViewController {
31  
-
  31
+	NSArray *items;
32 32
 }
33 33
 
  34
+- (void)addItem:(id)sender;
  35
+
34 36
 @end
20  MBCoverFlowViewController.m
@@ -49,9 +49,11 @@ - (void)awakeFromNib
49 49
 		count++;
50 50
 	}
51 51
 	
52  
-	[(MBCoverFlowView *)self.view setContent:images];
  52
+	items = [images copy];
53 53
 	
54  
-	NSViewController *labelViewController = [[NSViewController alloc] initWithNibName:nil bundle:nil];
  54
+//	[(MBCoverFlowView *)self.view setContent:images];
  55
+	
  56
+/*	NSViewController *labelViewController = [[NSViewController alloc] initWithNibName:nil bundle:nil];
55 57
 	NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)];
56 58
 	[label setBordered:NO];
57 59
 	[label setBezeled:NO];
@@ -65,9 +67,21 @@ - (void)awakeFromNib
65 67
 	[labelViewController setView:label];
66 68
 	[label release];
67 69
 	[(MBCoverFlowView *)self.view setAccessoryController:labelViewController];
68  
-	[labelViewController release];
  70
+	[labelViewController release];*/
69 71
 	
70 72
 	[(MBCoverFlowView *)self.view setShowsScrollbar:YES];
71 73
 }
72 74
 
  75
+- (void)dealloc
  76
+{
  77
+	[items release];
  78
+	[super dealloc];
  79
+}
  80
+
  81
+- (void)addItem:(id)sender
  82
+{
  83
+	NSArray *content = [items subarrayWithRange:NSMakeRange(0, [[(MBCoverFlowView *)self.view content] count]+1)];
  84
+	[(MBCoverFlowView *)self.view setContent:content];
  85
+}
  86
+
73 87
 @end

0 notes on commit b0863e1

Please sign in to comment.
Something went wrong with that request. Please try again.