Revision: 15050
          http://sourceforge.net/p/skim-app/code/15050
Author:   hofman
Date:     2025-03-30 09:03:40 +0000 (Sun, 30 Mar 2025)
Log Message:
-----------
Update color in panel in method that may do it

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

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2025-03-29 22:38:53 UTC (rev 15049)
+++ trunk/SKColorSwatch.m       2025-03-30 09:03:40 UTC (rev 15050)
@@ -110,7 +110,7 @@
 @property (nonatomic, readonly) CGFloat contentWidth;
 @property (nonatomic) CGFloat bezelWidth;
 - (NSRect)frameForItemViewAtIndex:(NSInteger)anIndex;
-- (void)setColor:(NSColor *)color atIndex:(NSInteger)i 
updatePanel:(BOOL)updatePanel;
+- (void)_setColor:(NSColor *)color atIndex:(NSInteger)i;
 @end
 
 @implementation SKColorSwatch
@@ -337,7 +337,7 @@
 - (void)handleColorPanelColorChanged:(NSNotification *)note {
     if (selectedIndex != -1) {
         NSColor *color = [[NSColorPanel sharedColorPanel] color];
-        [self setColor:color atIndex:selectedIndex updatePanel:NO];
+        [self _setColor:color atIndex:selectedIndex];
     }
 }
 
@@ -589,28 +589,28 @@
     }
 }
 
-- (void)setColor:(NSColor *)color atIndex:(NSInteger)i 
updatePanel:(BOOL)updatePanel {
-    if (color && i >= 0 && i < (NSInteger)[itemViews count]) {
+- (void)_setColor:(NSColor *)color atIndex:(NSInteger)i {
+    if (i >= 0 && i <= (NSInteger)[itemViews count]) {
         [self willChangeColors];
         [[itemViews objectAtIndex:i] setColor:color];
         NSAccessibilityPostNotification([itemViews objectAtIndex:i], 
NSAccessibilityValueChangedNotification);
         [self didChangeColors];
-        if (updatePanel) {
-            NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
-            NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
-            [nc removeObserver:self 
name:NSColorPanelColorDidChangeNotification object:colorPanel];
-            [colorPanel setColor:color];
-            [nc addObserver:self 
selector:@selector(handleColorPanelColorChanged:) 
name:NSColorPanelColorDidChangeNotification object:colorPanel];
-        }
     }
 }
 
 - (void)setColor:(NSColor *)color atIndex:(NSInteger)i {
-    [self setColor:color atIndex:i updatePanel:selectedIndex == i];
+    [self _setColor:color atIndex:i];
+    if (i >= 0 && i < (NSInteger)[itemViews count] && selectedIndex == i) {
+        NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
+        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+        [nc removeObserver:self name:NSColorPanelColorDidChangeNotification 
object:colorPanel];
+        [colorPanel setColor:color];
+        [nc addObserver:self selector:@selector(handleColorPanelColorChanged:) 
name:NSColorPanelColorDidChangeNotification object:colorPanel];
+    }
 }
 
 - (void)insertColor:(NSColor *)color atIndex:(NSInteger)i {
-    if (color && i >= 0 && i <= (NSInteger)[itemViews count]) {
+    if (i >= 0 && i <= (NSInteger)[itemViews count]) {
         [self willChangeColors];
         bezelWidth = [self contentWidth];
         SKColorSwatchItemView *itemView = [[SKColorSwatchItemView alloc] 
initWithFrame:[self frameForCollapsedItemViewAtIndex:i]];

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