Revision: 12145
          http://sourceforge.net/p/skim-app/code/12145
Author:   hofman
Date:     2021-03-01 10:46:50 +0000 (Mon, 01 Mar 2021)
Log Message:
-----------
Reuse color swatch item views when setting colors array

Modified Paths:
--------------
    trunk/SKColorSwatch.m

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2021-03-01 09:46:17 UTC (rev 12144)
+++ trunk/SKColorSwatch.m       2021-03-01 10:46:50 UTC (rev 12145)
@@ -482,15 +482,21 @@
     [colors setArray:newColors];
     if (autoResizes && [newColors count] != [oldColors count])
         [self sizeToFit];
-    [itemViews makeObjectsPerformSelector:@selector(removeFromSuperview)];
-    [itemViews removeAllObjects];
     for (i = 0; i < iMax; i++) {
-        SKColorSwatchItemView *itemView = [[SKColorSwatchItemView alloc] init];
+        SKColorSwatchItemView *itemView;
+        if (i < [itemViews count]) {
+            itemView = [itemViews objectAtIndex:i];
+        } else {
+            itemView = [[[SKColorSwatchItemView alloc] init] autorelease];
+            [self addSubview:itemView];
+            [itemViews addObject:itemView];
+        }
         [itemView setColor:[newColors objectAtIndex:i]];
-        [self addSubview:itemView];
-        [itemViews addObject:itemView];
-        [itemView release];
     }
+    while ([itemViews count] > iMax) {
+        [[itemViews objectAtIndex:iMax] removeFromSuperview];
+        [itemViews removeObjectAtIndex:iMax];
+    }
     [self updateSubviewLayout];
     [self invalidateIntrinsicContentSize];
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKColorSwatchColorsChangedNotification object:self];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to