Revision: 15052
http://sourceforge.net/p/skim-app/code/15052
Author: hofman
Date: 2025-03-30 09:10:20 +0000 (Sun, 30 Mar 2025)
Log Message:
-----------
macro for ecurring check
Modified Paths:
--------------
trunk/SKColorSwatch.m
Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m 2025-03-30 09:07:04 UTC (rev 15051)
+++ trunk/SKColorSwatch.m 2025-03-30 09:10:20 UTC (rev 15052)
@@ -589,8 +589,10 @@
}
}
+#define VALID_INDEX(i) (i >= 0 && i <= (NSInteger)[itemViews count])
+
- (void)_setColor:(NSColor *)color atIndex:(NSInteger)i {
- if (i >= 0 && i <= (NSInteger)[itemViews count]) {
+ if (VALID_INDEX(i)) {
[self willChangeColors];
[[itemViews objectAtIndex:i] setColor:color];
NSAccessibilityPostNotification([itemViews objectAtIndex:i],
NSAccessibilityValueChangedNotification);
@@ -600,7 +602,7 @@
- (void)setColor:(NSColor *)color atIndex:(NSInteger)i {
[self _setColor:color atIndex:i];
- if (i >= 0 && i < (NSInteger)[itemViews count] && selectedIndex == i) {
+ if (VALID_INDEX(i) && selectedIndex == i) {
NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:NSColorPanelColorDidChangeNotification
object:colorPanel];
@@ -610,7 +612,7 @@
}
- (void)insertColor:(NSColor *)color atIndex:(NSInteger)i {
- if (i >= 0 && i <= (NSInteger)[itemViews count]) {
+ if (VALID_INDEX(i)) {
[self willChangeColors];
bezelWidth = [self contentWidth];
SKColorSwatchItemView *itemView = [[SKColorSwatchItemView alloc]
initWithFrame:[self frameForCollapsedItemViewAtIndex:i]];
@@ -641,7 +643,7 @@
}
- (void)removeColorAtIndex:(NSInteger)i {
- if (i >= 0 && i < (NSInteger)[itemViews count]) {
+ if (VALID_INDEX(i)) {
if (selectedIndex == i)
[self deactivate];
[self willChangeColors];
@@ -673,7 +675,7 @@
}
- (void)moveColorAtIndex:(NSInteger)from toIndex:(NSInteger)to {
- if (from >= 0 && to >= 0 && from != to) {
+ if (VALID_INDEX(from) && VALID_INDEX(from) && from != to) {
[self willChangeColors];
SKColorSwatchItemView *itemView = [itemViews objectAtIndex:from];
[itemViews removeObjectAtIndex:from];
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