Revision: 15044
          http://sourceforge.net/p/skim-app/code/15044
Author:   hofman
Date:     2025-03-29 16:13:28 +0000 (Sat, 29 Mar 2025)
Log Message:
-----------
enumerate ussing block

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

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2025-03-29 16:05:56 UTC (rev 15043)
+++ trunk/SKColorSwatch.m       2025-03-29 16:13:28 UTC (rev 15044)
@@ -477,13 +477,12 @@
 }
 
 - (void)setColors:(NSArray *)newColors {
-    NSUInteger i, iMax = [newColors count];
-    BOOL changeSize = iMax != [itemViews count];
-    if (selectedIndex != -1 && (selectedIndex >= (NSInteger)iMax || 
[[newColors objectAtIndex:selectedIndex] isEqual:[[itemViews 
objectAtIndex:selectedIndex] color]] == NO))
+    NSUInteger count = [newColors count], oldCount = [itemViews count];
+    if (selectedIndex != -1 && (selectedIndex >= (NSInteger)count || 
[[newColors objectAtIndex:selectedIndex] isEqual:[[itemViews 
objectAtIndex:selectedIndex] color]] == NO))
         [self deactivate];
-    for (i = 0; i < iMax; i++) {
+    [newColors enumerateObjectsUsingBlock:^(NSColor *color, NSUInteger i, BOOL 
*stop){
         SKColorSwatchItemView *itemView;
-        if (i < [itemViews count]) {
+        if (i < oldCount) {
             itemView = [itemViews objectAtIndex:i];
         } else {
             itemView = [[SKColorSwatchItemView alloc] initWithFrame:[self 
frameForItemViewAtIndex:i]];
@@ -491,20 +490,20 @@
             [self addSubview:itemView];
             [itemViews addObject:itemView];
         }
-        [itemView setColor:[newColors objectAtIndex:i]];
+        [itemView setColor:color];
+    }];
+    while ([itemViews count] > count) {
+        [[itemViews objectAtIndex:count] removeFromSuperview];
+        [itemViews removeObjectAtIndex:count];
     }
-    while ([itemViews count] > iMax) {
-        [[itemViews objectAtIndex:iMax] removeFromSuperview];
-        [itemViews removeObjectAtIndex:iMax];
-    }
-    if (changeSize) {
+    if (count != oldCount) {
         if (autoResizes)
             [self sizeToFit];
         [self setBezelWidth:[self contentWidth]];
     }
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKColorSwatchColorsChangedNotification object:self];
-    if (focusedIndex >= (NSInteger)iMax)
-        focusedIndex = iMax - 1;
+    if (focusedIndex >= (NSInteger)count)
+        focusedIndex = count - 1;
 }
 
 - (NSColor *)color {

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to