Revision: 4810
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4810&view=rev
Author:   hofman
Date:     2008-10-17 16:17:30 +0000 (Fri, 17 Oct 2008)

Log Message:
-----------
Change font color in font well

Modified Paths:
--------------
    trunk/English.lproj/PreferenceWindow.nib/classes.nib
    trunk/English.lproj/PreferenceWindow.nib/info.nib
    trunk/English.lproj/PreferenceWindow.nib/keyedobjects.nib
    trunk/SKFontWell.h
    trunk/SKFontWell.m
    trunk/SKPreferenceController.m

Modified: trunk/English.lproj/PreferenceWindow.nib/classes.nib
===================================================================
--- trunk/English.lproj/PreferenceWindow.nib/classes.nib        2008-10-17 
12:11:15 UTC (rev 4809)
+++ trunk/English.lproj/PreferenceWindow.nib/classes.nib        2008-10-17 
16:17:30 UTC (rev 4810)
@@ -13,22 +13,6 @@
                        <string>NSController</string>
                </dict>
                <dict>
-                       <key>CLASS</key>
-                       <string>NSView</string>
-                       <key>LANGUAGE</key>
-                       <string>ObjC</string>
-                       <key>SUPERCLASS</key>
-                       <string>NSResponder</string>
-               </dict>
-               <dict>
-                       <key>CLASS</key>
-                       <string>NSMenuItem</string>
-                       <key>LANGUAGE</key>
-                       <string>ObjC</string>
-                       <key>SUPERCLASS</key>
-                       <string>NSObject</string>
-               </dict>
-               <dict>
                        <key>ACTIONS</key>
                        <dict>
                                <key>changeDiscreteThumbnailSizes</key>
@@ -86,14 +70,6 @@
                </dict>
                <dict>
                        <key>CLASS</key>
-                       <string>NSMenu</string>
-                       <key>LANGUAGE</key>
-                       <string>ObjC</string>
-                       <key>SUPERCLASS</key>
-                       <string>NSObject</string>
-               </dict>
-               <dict>
-                       <key>CLASS</key>
                        <string>NSWindowController</string>
                        <key>LANGUAGE</key>
                        <string>ObjC</string>
@@ -101,13 +77,8 @@
                        <string>NSResponder</string>
                </dict>
                <dict>
-                       <key>ACTIONS</key>
-                       <dict>
-                               <key></key>
-                               <string>id</string>
-                       </dict>
                        <key>CLASS</key>
-                       <string>FirstResponder</string>
+                       <string>NSMenu</string>
                        <key>LANGUAGE</key>
                        <string>ObjC</string>
                        <key>SUPERCLASS</key>
@@ -134,35 +105,69 @@
                </dict>
                <dict>
                        <key>CLASS</key>
-                       <string>NSCell</string>
+                       <string>NSWindow</string>
                        <key>LANGUAGE</key>
                        <string>ObjC</string>
                        <key>SUPERCLASS</key>
-                       <string>NSObject</string>
+                       <string>NSResponder</string>
                </dict>
                <dict>
+                       <key>ACTIONS</key>
+                       <dict>
+                               <key>changeAttributesFromFontManager</key>
+                               <string>id</string>
+                       </dict>
                        <key>CLASS</key>
-                       <string>NSWindow</string>
+                       <string>SKFontWell</string>
                        <key>LANGUAGE</key>
                        <string>ObjC</string>
+                       <key>OUTLETS</key>
+                       <dict>
+                               <key>target</key>
+                               <string>id</string>
+                       </dict>
                        <key>SUPERCLASS</key>
+                       <string>NSButton</string>
+               </dict>
+               <dict>
+                       <key>CLASS</key>
+                       <string>NSView</string>
+                       <key>LANGUAGE</key>
+                       <string>ObjC</string>
+                       <key>SUPERCLASS</key>
                        <string>NSResponder</string>
                </dict>
                <dict>
                        <key>CLASS</key>
-                       <string>SKFontWell</string>
+                       <string>NSMenuItem</string>
                        <key>LANGUAGE</key>
                        <string>ObjC</string>
-                       <key>OUTLETS</key>
+                       <key>SUPERCLASS</key>
+                       <string>NSObject</string>
+               </dict>
+               <dict>
+                       <key>ACTIONS</key>
                        <dict>
-                               <key>target</key>
+                               <key></key>
                                <string>id</string>
                        </dict>
+                       <key>CLASS</key>
+                       <string>FirstResponder</string>
+                       <key>LANGUAGE</key>
+                       <string>ObjC</string>
                        <key>SUPERCLASS</key>
-                       <string>NSButton</string>
+                       <string>NSObject</string>
                </dict>
                <dict>
                        <key>CLASS</key>
+                       <string>NSCell</string>
+                       <key>LANGUAGE</key>
+                       <string>ObjC</string>
+                       <key>SUPERCLASS</key>
+                       <string>NSObject</string>
+               </dict>
+               <dict>
+                       <key>CLASS</key>
                        <string>NSResponder</string>
                        <key>LANGUAGE</key>
                        <string>ObjC</string>

Modified: trunk/English.lproj/PreferenceWindow.nib/info.nib
===================================================================
--- trunk/English.lproj/PreferenceWindow.nib/info.nib   2008-10-17 12:11:15 UTC 
(rev 4809)
+++ trunk/English.lproj/PreferenceWindow.nib/info.nib   2008-10-17 16:17:30 UTC 
(rev 4810)
@@ -3,14 +3,14 @@
 <plist version="1.0">
 <dict>
        <key>IBFramework Version</key>
-       <string>672</string>
+       <string>677</string>
        <key>IBLastKnownRelativeProjectPath</key>
        <string>../Skim.xcodeproj</string>
        <key>IBOldestOS</key>
        <integer>5</integer>
        <key>IBOpenObjects</key>
        <array>
-               <integer>170</integer>
+               <integer>6</integer>
        </array>
        <key>IBSystem Version</key>
        <string>9F33</string>

Modified: trunk/English.lproj/PreferenceWindow.nib/keyedobjects.nib
===================================================================
(Binary files differ)

Modified: trunk/SKFontWell.h
===================================================================
--- trunk/SKFontWell.h  2008-10-17 12:11:15 UTC (rev 4809)
+++ trunk/SKFontWell.h  2008-10-17 16:17:30 UTC (rev 4810)
@@ -40,6 +40,7 @@
 
 extern NSString *SKFontWellFontNameKey;
 extern NSString *SKFontWellFontSizeKey;
+extern NSString *SKFontWellTextColorKey;
 
 extern NSString *SKFontWellFontKey;
 extern NSString *SKFontWellActionKey;
@@ -63,10 +64,27 @@
 - (float)fontSize;
 - (void)setFontSize:(float)pointSize;
 
-- (void)changeFontFromFontManager;
+- (NSColor *)textColor;
+- (void)setTextColor:(NSColor *)newTextColor;
 
+- (BOOL)hasTextColor;
+- (void)setHasTextColor:(BOOL)newHasTextColor;
+
+- (void)changeFontFromFontManager:(id)sender;
+- (void)changeAttributesFromFontManager:(id)sender;
+
 @end
 
 
[EMAIL PROTECTED] SKFontWellCell : NSButtonCell
[EMAIL PROTECTED] SKFontWellCell : NSButtonCell {
+    NSColor *textColor;
+    BOOL hasTextColor;
+}
+
+- (NSColor *)textColor;
+- (void)setTextColor:(NSColor *)newTextColor;
+
+- (BOOL)hasTextColor;
+- (void)setHasTextColor:(BOOL)newHasTextColor;
+
 @end

Modified: trunk/SKFontWell.m
===================================================================
--- trunk/SKFontWell.m  2008-10-17 12:11:15 UTC (rev 4809)
+++ trunk/SKFontWell.m  2008-10-17 16:17:30 UTC (rev 4810)
@@ -47,6 +47,7 @@
 
 NSString *SKFontWellFontNameKey = @"fontName";
 NSString *SKFontWellFontSizeKey = @"fontSize";
+NSString *SKFontWellTextColorKey = @"textColor";
 
 NSString *SKFontWellFontKey = @"font";
 NSString *SKFontWellActionKey = @"action";
@@ -67,6 +68,7 @@
 + (void)initialize {
     [self exposeBinding:SKFontWellFontNameKey];
     [self exposeBinding:SKFontWellFontSizeKey];
+    [self exposeBinding:SKFontWellTextColorKey];
     
     [self setKeys:[NSArray arrayWithObjects:SKFontWellFontKey, nil] 
triggerChangeNotificationsForDependentKey:SKFontWellFontNameKey];
     [self setKeys:[NSArray arrayWithObjects:SKFontWellFontKey, nil] 
triggerChangeNotificationsForDependentKey:SKFontWellFontSizeKey];
@@ -83,6 +85,8 @@
         return [NSString class];
     else if ([binding isEqualToString:SKFontWellFontNameKey])
         return [NSNumber class];
+    else if ([binding isEqualToString:SKFontWellTextColorKey])
+        return [NSColor class];
     else
         return [super valueClassForBinding:binding];
 }
@@ -172,15 +176,35 @@
     [[info objectForKey:NSObservedObjectKey] setValue:[NSNumber 
numberWithFloat:[self fontSize]] forKeyPath:[info 
objectForKey:NSObservedKeyPathKey]];
 }
 
-- (void)changeFontFromFontManager {
+- (void)notifyTextColorBinding {
+    NSDictionary *info = [self infoForBinding:SKFontWellTextColorKey];
+    if (info) {
+        id value = [self textColor];
+        NSString *transformerName = [[info objectForKey:NSOptionsKey] 
objectForKey:NSValueTransformerNameBindingOption];
+        if (transformerName) {
+            NSValueTransformer *valueTransformer = [NSValueTransformer 
valueTransformerForName:transformerName];
+            value = [valueTransformer reverseTransformedValue:value]; 
+        }
+        [[info objectForKey:NSObservedObjectKey] setValue:value 
forKeyPath:[info objectForKey:NSObservedKeyPathKey]];
+    }
+}
+
+- (void)changeFontFromFontManager:(id)sender {
     if ([self isActive]) {
-        NSFontManager *fm = [NSFontManager sharedFontManager];
-        [self setFont:[fm convertFont:[self font]]];
+        [self setFont:[sender convertFont:[self font]]];
         [self notifyBinding];
         [self sendAction:[self action] to:[self target]];
     }
 }
 
+- (void)changeAttributesFromFontManager:(id)sender {
+    if ([self isActive] && [self hasTextColor]) {
+        [self setTextColor:[[sender convertAttributes:[NSDictionary 
dictionaryWithObjectsAndKeys:[self textColor], NSForegroundColorAttributeName, 
nil]] valueForKey:NSForegroundColorAttributeName]];
+        [self notifyTextColorBinding];
+        [self sendAction:[self action] to:[self target]];
+    }
+}
+
 - (void)changeActive:(id)sender {
     if ([self isEnabled]) {
         if ([self isActive])
@@ -276,6 +300,28 @@
         [self setFont:newFont];
 }
 
+- (NSColor *)textColor {
+    return [[self cell] textColor];
+}
+
+- (void)setTextColor:(NSColor *)newTextColor {
+    BOOL didChange = [[self textColor] isEqual:newTextColor] == NO;
+    [[self cell] setTextColor:newTextColor];
+    if (didChange)
+        [self setNeedsDisplay:YES];
+}
+
+- (BOOL)hasTextColor {
+    return [[self cell] hasTextColor];
+}
+
+- (void)setHasTextColor:(BOOL)newHasTextColor {
+    if ([self hasTextColor] != newHasTextColor) {
+        [[self cell] setHasTextColor:newHasTextColor];
+        [self setNeedsDisplay:YES];
+    }
+}
+
 #pragma mark Binding support
 
 - (void)bind:(NSString *)bindingName toObject:(id)observableController 
withKeyPath:(NSString *)keyPath options:(NSDictionary *)options {       
@@ -406,6 +452,7 @@
 @implementation SKFontWellCell
 
 - (void)commonInit {
+    [self setTextColor:[NSColor blackColor]];
     [self setBezelStyle:NSShadowlessSquareBezelStyle]; // this is mainly to 
make it selectable
     [self setButtonType:NSPushOnPushOffButton];
     [self setState:NSOffState];
@@ -425,6 +472,11 @@
        return self;
 }
 
+- (void)dealloc {
+    [textColor release];
+    [super dealloc];
+}
+
 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView {
     [NSGraphicsContext saveGraphicsState];
     
@@ -458,4 +510,35 @@
     }
 }
 
+- (NSAttributedString *)attributedTitle {
+    if ([self hasTextColor]) {
+        NSMutableAttributedString *attrString = [[[super attributedTitle] 
mutableCopy] autorelease];
+        [attrString addAttribute:NSForegroundColorAttributeName value:[self 
textColor] range:NSMakeRange(0, [attrString length])];
+        return attrString;
+    } else {
+        return [super attributedTitle];
+    }
+}
+
+- (NSColor *)textColor {
+    return textColor;
+}
+
+- (void)setTextColor:(NSColor *)newTextColor {
+    if (textColor != newTextColor) {
+        [textColor release];
+        textColor = [newTextColor copy];
+    }
+}
+
+- (BOOL)hasTextColor {
+    return hasTextColor;
+}
+
+- (void)setHasTextColor:(BOOL)newHasTextColor {
+    if (hasTextColor != newHasTextColor) {
+        hasTextColor = newHasTextColor;
+    }
+}
+
 @end

Modified: trunk/SKPreferenceController.m
===================================================================
--- trunk/SKPreferenceController.m      2008-10-17 12:11:15 UTC (rev 4809)
+++ trunk/SKPreferenceController.m      2008-10-17 16:17:30 UTC (rev 4810)
@@ -152,6 +152,10 @@
     [freehandLineWell bind:SKLineWellStyleKey toObject:sudc 
withKeyPath:VALUES_KEY_PATH(SKInkNoteLineStyleKey) options:nil];
     [freehandLineWell bind:SKLineWellDashPatternKey toObject:sudc 
withKeyPath:VALUES_KEY_PATH(SKInkNoteDashPatternKey) options:nil];
     [freehandLineWell setDisplayStyle:SKLineWellDisplayStyleSimpleLine];
+    
+    NSDictionary *options = [NSDictionary 
dictionaryWithObjectsAndKeys:NSUnarchiveFromDataTransformerName, 
NSValueTransformerNameBindingOption, nil];
+    [textNoteFontWell setHasTextColor:YES];
+    [textNoteFontWell bind:SKFontWellTextColorKey toObject:sudc 
withKeyPath:VALUES_KEY_PATH(SKFreeTextNoteFontColorKey) options:options];
 }
 
 - (void)windowDidResignMain:(NSNotification *)notification {
@@ -248,9 +252,13 @@
 }
 
 - (IBAction)changeFont:(id)sender {
-    [[[[self window] contentView] activeFontWellSubview] 
changeFontFromFontManager];
+    [[[[self window] contentView] activeFontWellSubview] 
changeFontFromFontManager:sender];
 }
 
+- (IBAction)changeAttributes:(id)sender {
+    [[[[self window] contentView] activeFontWellSubview] 
changeAttributesFromFontManager:sender];
+}
+
 - (IBAction)resetAll:(id)sender {
     NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Reset 
all preferences to their original values?", @"Message in alert dialog when 
pressing Reset All button") 
                                      defaultButton:NSLocalizedString(@"Reset", 
@"Button title")


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 Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to