Revision: 3692
http://skim-app.svn.sourceforge.net/skim-app/?rev=3692&view=rev
Author: hofman
Date: 2008-04-10 07:28:48 -0700 (Thu, 10 Apr 2008)
Log Message:
-----------
Send KVO notifications when color changes and auto-resize when number of colors
change, depending on a flag.
Modified Paths:
--------------
trunk/SKColorSwatch.h
trunk/SKColorSwatch.m
Modified: trunk/SKColorSwatch.h
===================================================================
--- trunk/SKColorSwatch.h 2008-04-10 12:53:08 UTC (rev 3691)
+++ trunk/SKColorSwatch.h 2008-04-10 14:28:48 UTC (rev 3692)
@@ -51,6 +51,8 @@
SEL action;
id target;
+ BOOL autoResizes;
+
NSMutableDictionary *bindingInfo;
}
@@ -60,6 +62,9 @@
- (int)clickedColorIndex;
- (NSColor *)color;
+- (BOOL)autoResizes;
+- (void)setAutoResizes:(BOOL)flag;
+
- (int)colorIndexAtPoint:(NSPoint)point;
@end
Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m 2008-04-10 12:53:08 UTC (rev 3691)
+++ trunk/SKColorSwatch.m 2008-04-10 14:28:48 UTC (rev 3692)
@@ -63,6 +63,7 @@
focusedIndex = 0;
clickedIndex = -1;
draggedIndex = -1;
+ autoResizes = YES;
bindingInfo = [[NSMutableDictionary alloc] init];
[self registerForDraggedTypes:[NSArray
arrayWithObjects:NSColorPboardType, nil]];
@@ -302,9 +303,20 @@
}
- (void)setColors:(NSArray *)newColors {
+ BOOL shouldResize = autoResizes && [newColors count] != [colors count];
[colors setArray:newColors];
+ if (shouldResize)
+ [self sizeToFit];
}
+- (BOOL)autoResizes {
+ return autoResizes;
+}
+
+- (void)setAutoResizes:(BOOL)flag {
+ autoResizes = flag;
+}
+
- (int)clickedColorIndex {
return clickedIndex;
}
@@ -398,8 +410,11 @@
- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint
operation:(NSDragOperation)operation {
if ((operation & NSDragOperationDelete) != 0) {
if (draggedIndex != -1 && [self isEnabled]) {
+ [self willChangeValueForKey:@"colors"];
[colors removeObjectAtIndex:draggedIndex];
- [self sizeToFit];
+ if (autoResizes)
+ [self sizeToFit];
+ [self didChangeValueForKey:@"colors"];
NSDictionary *info = [self infoForBinding:@"colors"];
id observedObject = [info objectForKey:NSObservedObjectKey];
@@ -478,12 +493,15 @@
int i = isCopy ? [self insertionIndexAtPoint:mouseLoc] : [self
colorIndexAtPoint:mouseLoc];
if (i != -1 && color) {
+ [self willChangeValueForKey:@"colors"];
if (isCopy) {
[colors insertObject:color atIndex:i];
- [self sizeToFit];
+ if (autoResizes)
+ [self sizeToFit];
} else {
[colors replaceObjectAtIndex:i withObject:color];
}
+ [self didChangeValueForKey:@"colors"];
NSDictionary *info = [self infoForBinding:@"colors"];
id observedObject = [info objectForKey:NSObservedObjectKey];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit