Revision: 4441
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4441&view=rev
Author:   hofman
Date:     2008-08-22 11:58:26 +0000 (Fri, 22 Aug 2008)

Log Message:
-----------
Simplify binding of fontwell. Only notify binding hen changed from a drop or 
the font panel.

Modified Paths:
--------------
    trunk/SKFontWell.h
    trunk/SKFontWell.m

Modified: trunk/SKFontWell.h
===================================================================
--- trunk/SKFontWell.h  2008-08-22 11:14:03 UTC (rev 4440)
+++ trunk/SKFontWell.h  2008-08-22 11:58:26 UTC (rev 4441)
@@ -50,9 +50,6 @@
     SEL action;
     
     NSMutableDictionary *bindingInfo;
-    
-    BOOL updatingFromFontPanel;
-    BOOL updatingFromBinding;
 }
 
 - (void)activate;

Modified: trunk/SKFontWell.m
===================================================================
--- trunk/SKFontWell.m  2008-08-22 11:14:03 UTC (rev 4440)
+++ trunk/SKFontWell.m  2008-08-22 11:58:26 UTC (rev 4441)
@@ -58,7 +58,7 @@
 
 @interface SKFontWell (SKPrivate)
 - (void)changeActive:(id)sender;
-- (void)updateTitle;
+- (void)fontChanged;
 @end
 
 
@@ -90,12 +90,9 @@
 - (void)commonInit {
     if ([self font] == nil)
         [self setFont:[NSFont systemFontOfSize:0.0]];
-    else
-        [self updateTitle];
+    [self fontChanged];
     [super setAction:@selector(changeActive:)];
     [super setTarget:self];
-    updatingFromFontPanel = NO;
-    updatingFromBinding = NO;
     bindingInfo = [[NSMutableDictionary alloc] init];
     [self registerForDraggedTypes:[NSArray 
arrayWithObjects:SKNSFontPanelDescriptorsPboardType, 
SKNSFontPanelFamiliesPboardType, nil]];
 }
@@ -168,26 +165,31 @@
     [self deactivate];
 }
 
-- (void)changeActive:(id)sender {
-    if ([self isEnabled]) {
-        if ([self isActive])
-            [self activate];
-        else
-            [self deactivate];
-    }
+- (void)notifyBinding {
+    NSDictionary *info = [self infoForBinding:SKFontWellFontNameKey];
+    [[info objectForKey:NSObservedObjectKey] setValue:[self fontName] 
forKeyPath:[info objectForKey:NSObservedKeyPathKey]];
+    info = [self infoForBinding:SKFontWellFontSizeKey];
+    [[info objectForKey:NSObservedObjectKey] setValue:[NSNumber 
numberWithFloat:[self fontSize]] forKeyPath:[info 
objectForKey:NSObservedKeyPathKey]];
 }
 
 - (void)changeFontFromFontManager {
     if ([self isActive]) {
         NSFontManager *fm = [NSFontManager sharedFontManager];
-        BOOL savedUpdatingFromFontPanel = updatingFromFontPanel;
-        updatingFromFontPanel = YES;
         [self setFont:[fm convertFont:[self font]]];
+        [self notifyBinding];
         [self sendAction:[self action] to:[self target]];
-        updatingFromFontPanel = savedUpdatingFromFontPanel;
     }
 }
 
+- (void)changeActive:(id)sender {
+    if ([self isEnabled]) {
+        if ([self isActive])
+            [self activate];
+        else
+            [self deactivate];
+    }
+}
+
 - (void)activate {
     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
     NSFontManager *fm = [NSFontManager sharedFontManager];
@@ -214,19 +216,10 @@
     [self setNeedsDisplay:YES];
 }
 
-- (void)updateTitle {
-    [self setTitle:[[[self font] displayName] stringByAppendingFormat:@" %i", 
(int)[[self font] pointSize]]];
-}
-
-- (void)updateFont {
-    if (updatingFromBinding == NO) {
-        NSDictionary *info = [self infoForBinding:SKFontWellFontNameKey];
-               [[info objectForKey:NSObservedObjectKey] setValue:[self 
fontName] forKeyPath:[info objectForKey:NSObservedKeyPathKey]];
-               info = [self infoForBinding:SKFontWellFontSizeKey];
-        [[info objectForKey:NSObservedObjectKey] setValue:[NSNumber 
numberWithFloat:[self fontSize]] forKeyPath:[info 
objectForKey:NSObservedKeyPathKey]];
-    }
-    if ([self isActive] && updatingFromFontPanel == NO)
+- (void)fontChanged {
+    if ([self isActive])
         [[NSFontManager sharedFontManager] setSelectedFont:[self font] 
isMultiple:NO];
+    [self setTitle:[NSString stringWithFormat:@"%@ %i", [self fontName], 
(int)[self fontSize]]];
     [self setNeedsDisplay:YES];
 }
 
@@ -259,10 +252,8 @@
 - (void)setFont:(NSFont *)newFont {
     BOOL didChange = [[self font] isEqual:newFont] == NO;
     [super setFont:newFont];
-    if (didChange) {
-        [self updateTitle];
-        [self updateFont];
-    }
+    if (didChange)
+        [self fontChanged];
 }
 
 - (NSString *)fontName {
@@ -271,10 +262,8 @@
 
 - (void)setFontName:(NSString *)fontName {
     NSFont *newFont = [NSFont fontWithName:fontName size:[[self font] 
pointSize]];
-    if (newFont) {
+    if (newFont)
         [self setFont:newFont];
-        [self updateFont];
-    }
 }
 
 - (float)fontSize {
@@ -283,10 +272,8 @@
 
 - (void)setFontSize:(float)pointSize {
     NSFont *newFont = [NSFont fontWithName:[[self font] fontName] 
size:pointSize];
-    if (newFont) {
+    if (newFont)
         [self setFont:newFont];
-        [self updateFont];
-    }
 }
 
 #pragma mark Binding support
@@ -336,11 +323,8 @@
     if (key) {
         NSDictionary *info = [self infoForBinding:key];
                id value = [[info objectForKey:NSObservedObjectKey] 
valueForKeyPath:[info objectForKey:NSObservedKeyPathKey]];
-               if (NSIsControllerMarker(value) == NO) {
-            updatingFromBinding = YES;
+               if (NSIsControllerMarker(value) == NO)
             [self setValue:value forKey:key];
-            updatingFromBinding = NO;
-               }
     } else {
         [super observeValueForKeyPath:keyPath ofObject:object change:change 
context:context];
     }
@@ -405,6 +389,7 @@
     
     if (droppedFont) {
         [self setFont:droppedFont];
+        [self notifyBinding];
         [self sendAction:[self action] to:[self target]];
     }
     


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