Revision: 5580
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5580&view=rev
Author:   hofman
Date:     2009-08-24 16:57:00 +0000 (Mon, 24 Aug 2009)

Log Message:
-----------
simplify line inspector updating, use a single action method and notification 
to notify any change, add an accessor for the current change action.

Modified Paths:
--------------
    trunk/SKLineInspector.h
    trunk/SKLineInspector.m
    trunk/SKLineWell.h
    trunk/SKLineWell.m
    trunk/SKMainWindowController_Actions.m

Modified: trunk/SKLineInspector.h
===================================================================
--- trunk/SKLineInspector.h     2009-08-24 11:01:59 UTC (rev 5579)
+++ trunk/SKLineInspector.h     2009-08-24 16:57:00 UTC (rev 5580)
@@ -40,12 +40,18 @@
 #import <Cocoa/Cocoa.h>
 #import <Quartz/Quartz.h>
 
-extern NSString *SKLineInspectorLineWidthDidChangeNotification;
-extern NSString *SKLineInspectorLineStyleDidChangeNotification;
-extern NSString *SKLineInspectorDashPatternDidChangeNotification;
-extern NSString *SKLineInspectorStartLineStyleDidChangeNotification;
-extern NSString *SKLineInspectorEndLineStyleDidChangeNotification;
+extern NSString *SKLineInspectorLineAttributeDidChangeNotification;
 
+enum {
+    SKNoLineChangeAction,
+    SKLineWidthLineChangeAction,
+    SKStyleLineChangeAction,
+    SKDashPatternLineChangeAction,
+    SKStartLineStyleLineChangeAction,
+    SKEndLineStyleLineChangeAction
+};
+typedef NSUInteger SKLineChangeAction;
+
 @class SKLineWell;
 
 @interface SKLineInspector : NSWindowController {
@@ -61,6 +67,7 @@
     NSArray *dashPattern;
     PDFLineStyle startLineStyle;
     PDFLineStyle endLineStyle;
+    SKLineChangeAction currentLineChangeAction;
 }
 
 + (id)sharedLineInspector;
@@ -80,15 +87,11 @@
 
 - (void)setAnnotationStyle:(PDFAnnotation *)annotation;
 
+- (SKLineChangeAction)currentLineChangeAction;
+
 @end
 
 
 @interface NSObject (SKLineInspectorDelegate)
-
-- (void)changeLineWidth:(id)sender;
-- (void)changeLineStyle:(id)sender;
-- (void)changeDashPattern:(id)sender;
-- (void)changeStartLineStyle:(id)sender;
-- (void)changeEndLineStyle:(id)sender;
-
+- (void)changeLineAttribute:(id)sender;
 @end

Modified: trunk/SKLineInspector.m
===================================================================
--- trunk/SKLineInspector.m     2009-08-24 11:01:59 UTC (rev 5579)
+++ trunk/SKLineInspector.m     2009-08-24 16:57:00 UTC (rev 5580)
@@ -42,17 +42,14 @@
 #import "NSSegmentedControl_SKExtensions.h"
 #import "SKNumberArrayFormatter.h"
 
-NSString *SKLineInspectorLineWidthDidChangeNotification = 
@"SKLineInspectorLineWidthDidChangeNotification";
-NSString *SKLineInspectorLineStyleDidChangeNotification = 
@"SKLineInspectorLineStyleDidChangeNotification";
-NSString *SKLineInspectorDashPatternDidChangeNotification = 
@"SKLineInspectorDashPatternDidChangeNotification";
-NSString *SKLineInspectorStartLineStyleDidChangeNotification = 
@"SKLineInspectorStartLineStyleDidChangeNotification";
-NSString *SKLineInspectorEndLineStyleDidChangeNotification = 
@"SKLineInspectorEndLineStyleDidChangeNotification";
+NSString *SKLineInspectorLineAttributeDidChangeNotification = 
@"SKLineInspectorLineAttributeDidChangeNotification";
 
 #define LINEWIDTH_KEY       @"lineWidth"
 #define STYLE_KEY           @"style"
 #define DASHPATTERN_KEY     @"dashPattern"
 #define STARTLINESTYLE_KEY  @"startLineStyle"
 #define ENDLINESTYLE_KEY    @"endLineStyle"
+#define ACTION_KEY          @"action"
 
 #define SKLineInspectorFrameAutosaveName @"SKLineInspector"
 
@@ -81,6 +78,7 @@
         dashPattern = nil;
         startLineStyle = kPDFLineStyleNone;
         endLineStyle = kPDFLineStyleNone;
+        currentLineChangeAction = SKNoLineChangeAction;
     }
     return sharedLineInspector;
 }
@@ -417,7 +415,10 @@
        [image release];
 }
 
-- (void)sendActionToTarget:(SEL)selector {
+- (void)notifyChangeAction:(SKLineChangeAction)action {
+    currentLineChangeAction = action;
+    
+    SEL selector = @selector(changeLineAttribute:);
     NSWindow *mainWindow = [NSApp mainWindow];
     NSResponder *responder = [mainWindow firstResponder];
     
@@ -425,19 +426,23 @@
         responder = [responder nextResponder];
     
     [responder performSelector:selector withObject:self];
+    
+    NSDictionary *userInfo = [NSDictionary 
dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:action], ACTION_KEY, nil];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKLineInspectorLineAttributeDidChangeNotification 
object:self userInfo:userInfo];
+    
+    currentLineChangeAction = SKNoLineChangeAction;
 }
 
 #pragma mark Accessors
 
 - (CGFloat)lineWidth {
-    return  lineWidth;
+    return lineWidth;
 }
 
 - (void)setLineWidth:(CGFloat)width {
     if (SKAbs(lineWidth - width) > 0.00001) {
         lineWidth = width;
-        [self sendActionToTarget:@selector(changeLineWidth:)];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKLineInspectorLineWidthDidChangeNotification object:self];
+        [self notifyChangeAction:SKLineWidthLineChangeAction];
     }
 }
 
@@ -448,8 +453,7 @@
 - (void)setStyle:(PDFBorderStyle)newStyle {
     if (newStyle != style) {
         style = newStyle;
-        [self sendActionToTarget:@selector(changeLineStyle:)];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKLineInspectorLineStyleDidChangeNotification object:self];
+        [self notifyChangeAction:SKStyleLineChangeAction];
     }
 }
 
@@ -461,8 +465,7 @@
     if ([pattern isEqualToArray:dashPattern] == NO && (pattern || 
dashPattern)) {
         [dashPattern release];
         dashPattern = [pattern copy];
-        [self sendActionToTarget:@selector(changeDashPattern:)];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKLineInspectorDashPatternDidChangeNotification 
object:self];
+        [self notifyChangeAction:SKDashPatternLineChangeAction];
     }
 }
 
@@ -473,8 +476,7 @@
 - (void)setStartLineStyle:(PDFLineStyle)newStyle {
     if (newStyle != startLineStyle) {
         startLineStyle = newStyle;
-        [self sendActionToTarget:@selector(changeStartLineStyle:)];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKLineInspectorStartLineStyleDidChangeNotification 
object:self];
+        [self notifyChangeAction:SKStartLineStyleLineChangeAction];
     }
 }
 
@@ -485,8 +487,7 @@
 - (void)setEndLineStyle:(PDFLineStyle)newStyle {
     if (newStyle != endLineStyle) {
         endLineStyle = newStyle;
-        [self sendActionToTarget:@selector(changeEndLineStyle:)];
-        [[NSNotificationCenter defaultCenter] 
postNotificationName:SKLineInspectorEndLineStyleDidChangeNotification 
object:self];
+        [self notifyChangeAction:SKEndLineStyleLineChangeAction];
     }
 }
 
@@ -503,6 +504,10 @@
     }
 }
 
+- (SKLineChangeAction)currentLineChangeAction {
+    return currentLineChangeAction;
+}
+
 - (void)setNilValueForKey:(NSString *)key {
     if ([key isEqualToString:LINEWIDTH_KEY]) {
         [self setValue:[NSNumber numberWithFloat:0.0] forKey:key];

Modified: trunk/SKLineWell.h
===================================================================
--- trunk/SKLineWell.h  2009-08-24 11:01:59 UTC (rev 5579)
+++ trunk/SKLineWell.h  2009-08-24 16:57:00 UTC (rev 5580)
@@ -102,10 +102,6 @@
 - (PDFLineStyle)endLineStyle;
 - (void)setEndLineStyle:(PDFLineStyle)newStyle;
 
-- (void)lineInspectorLineWidthChanged:(NSNotification *)notification;
-- (void)lineInspectorLineStyleChanged:(NSNotification *)notification;
-- (void)lineInspectorDashPatternChanged:(NSNotification *)notification;
-- (void)lineInspectorStartLineStyleChanged:(NSNotification *)notification;
-- (void)lineInspectorEndLineStyleChanged:(NSNotification *)notification;
+- (void)lineInspectorLineAttributeChanged:(NSNotification *)notification;
 
 @end

Modified: trunk/SKLineWell.m
===================================================================
--- trunk/SKLineWell.m  2009-08-24 11:01:59 UTC (rev 5579)
+++ trunk/SKLineWell.m  2009-08-24 16:57:00 UTC (rev 5580)
@@ -437,18 +437,8 @@
                    name:SKLineWellWillBecomeActiveNotification object:nil];
         [nc addObserver:self selector:@selector(lineInspectorWindowWillClose:)
                    name:NSWindowWillCloseNotification object:[inspector 
window]];
-        [nc addObserver:self selector:@selector(lineInspectorLineWidthChanged:)
-                   name:SKLineInspectorLineWidthDidChangeNotification 
object:inspector];
-        [nc addObserver:self selector:@selector(lineInspectorLineStyleChanged:)
-                   name:SKLineInspectorLineStyleDidChangeNotification 
object:inspector];
-        [nc addObserver:self 
selector:@selector(lineInspectorDashPatternChanged:)
-                   name:SKLineInspectorDashPatternDidChangeNotification 
object:inspector];
-        if ([self displayStyle] == SKLineWellDisplayStyleLine) {
-            [nc addObserver:self 
selector:@selector(lineInspectorStartLineStyleChanged:)
-                       name:SKLineInspectorStartLineStyleDidChangeNotification 
object:inspector];
-            [nc addObserver:self 
selector:@selector(lineInspectorEndLineStyleChanged:)
-                       name:SKLineInspectorEndLineStyleDidChangeNotification 
object:inspector];
-        } 
+        [nc addObserver:self 
selector:@selector(lineInspectorLineAttributeChanged:)
+                   name:SKLineInspectorLineAttributeDidChangeNotification 
object:inspector];
         
         lwFlags.active = 1;
         
@@ -521,19 +511,6 @@
 - (void)setDisplayStyle:(SKLineWellDisplayStyle)newStyle {
     if (lwFlags.displayStyle != newStyle) {
         lwFlags.displayStyle = newStyle;
-        if ([self isActive]) {
-            NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
-            SKLineInspector *inspector = [SKLineInspector sharedLineInspector];
-            if ([self displayStyle] == SKLineWellDisplayStyleLine) {
-                [nc addObserver:self 
selector:@selector(lineInspectorStartLineStyleChanged:)
-                          
name:SKLineInspectorStartLineStyleDidChangeNotification object:inspector];
-                [nc addObserver:self 
selector:@selector(lineInspectorEndLineStyleChanged:)
-                          
name:SKLineInspectorEndLineStyleDidChangeNotification object:inspector];
-            } else {
-                [nc removeObserver:self 
name:SKLineInspectorStartLineStyleDidChangeNotification object:inspector];
-                [nc removeObserver:self 
name:SKLineInspectorEndLineStyleDidChangeNotification object:inspector];
-            }
-        }
         [self setNeedsDisplay:YES];
     }
 }
@@ -606,31 +583,34 @@
 
 #pragma mark Notification handlers
 
-- (void)lineInspectorChangedValueForKey:(NSString *)key {
-    [self takeValueForKey:key from:[SKLineInspector sharedLineInspector]];
-    [self sendAction:[self action] to:[self target]];
+- (void)lineInspectorLineAttributeChanged:(NSNotification *)notification {
+    SKLineInspector *inspector = [notification object];
+    NSString *key = nil;
+    switch ([inspector currentLineChangeAction]) {
+        case SKLineWidthLineChangeAction:
+            key = SKLineWellLineWidthKey;
+            break;
+        case SKStyleLineChangeAction:
+            key = SKLineWellStyleKey;
+            break;
+        case SKDashPatternLineChangeAction:
+            key = SKLineWellDashPatternKey;
+            break;
+        case SKStartLineStyleLineChangeAction:
+            if ([self displayStyle] == SKLineWellDisplayStyleLine)
+                key = SKLineWellStartLineStyleKey;
+            break;
+        case SKEndLineStyleLineChangeAction:
+            if ([self displayStyle] == SKLineWellDisplayStyleLine)
+                key = SKLineWellEndLineStyleKey;
+            break;
+    }
+    if (key) {
+        [self takeValueForKey:key from:inspector];
+        [self sendAction:[self action] to:[self target]];
+    }
 }
 
-- (void)lineInspectorLineWidthChanged:(NSNotification *)notification {
-    [self lineInspectorChangedValueForKey:SKLineWellLineWidthKey];
-}
-
-- (void)lineInspectorLineStyleChanged:(NSNotification *)notification {
-    [self lineInspectorChangedValueForKey:SKLineWellStyleKey];
-}
-
-- (void)lineInspectorDashPatternChanged:(NSNotification *)notification {
-    [self lineInspectorChangedValueForKey:SKLineWellDashPatternKey];
-}
-
-- (void)lineInspectorStartLineStyleChanged:(NSNotification *)notification {
-    [self lineInspectorChangedValueForKey:SKLineWellStartLineStyleKey];
-}
-
-- (void)lineInspectorEndLineStyleChanged:(NSNotification *)notification {
-    [self lineInspectorChangedValueForKey:SKLineWellEndLineStyleKey];
-}
-
 #pragma mark NSDraggingSource protocol 
 
 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {

Modified: trunk/SKMainWindowController_Actions.m
===================================================================
--- trunk/SKMainWindowController_Actions.m      2009-08-24 11:01:59 UTC (rev 
5579)
+++ trunk/SKMainWindowController_Actions.m      2009-08-24 16:57:00 UTC (rev 
5580)
@@ -61,6 +61,7 @@
 #import "BDSKEdgeView.h"
 #import "SKSplitView.h"
 #import "SKPDFOutline.h"
+#import "SKLineInspector.h"
 
 
 @implementation SKMainWindowController (Actions)
@@ -122,50 +123,34 @@
     }
 }
 
-- (void)changeLineWidth:(id)sender {
+- (void)changeLineAttribute:(id)sender {
+    SKLineChangeAction action = [sender currentLineChangeAction];
     PDFAnnotation *annotation = [pdfView activeAnnotation];
-    NSString *type = [annotation type];
-    if (mwcFlags.updatingLine == 0 && [annotation isSkimNote] && ([type 
isEqualToString:SKNFreeTextString] || [type isEqualToString:SKNCircleString] || 
[type isEqualToString:SKNSquareString] || [type isEqualToString:SKNLineString] 
|| [type isEqualToString:SKNInkString])) {
-        [annotation setLineWidth:[sender lineWidth]];
-    }
-}
-
-- (void)changeLineStyle:(id)sender {
-    PDFAnnotation *annotation = [pdfView activeAnnotation];
-    NSString *type = [annotation type];
-    if (mwcFlags.updatingLine == 0 && [annotation isSkimNote] && ([type 
isEqualToString:SKNFreeTextString] || [type isEqualToString:SKNCircleString] || 
[type isEqualToString:SKNSquareString] || [type isEqualToString:SKNLineString] 
|| [type isEqualToString:SKNInkString])) {
-        [annotation setBorderStyle:[sender style]];
-    }
-}
-
-- (void)changeDashPattern:(id)sender {
-    PDFAnnotation *annotation = [pdfView activeAnnotation];
-    NSString *type = [annotation type];
-    if (mwcFlags.updatingLine == 0 && [annotation isSkimNote] && ([type 
isEqualToString:SKNFreeTextString] || [type isEqualToString:SKNCircleString] || 
[type isEqualToString:SKNSquareString] || [type isEqualToString:SKNLineString] 
|| [type isEqualToString:SKNInkString])) {
-        [annotation setDashPattern:[sender dashPattern]];
-    }
-}
-
-- (void)changeStartLineStyle:(id)sender {
-    PDFAnnotation *annotation = [pdfView activeAnnotation];
-    NSString *type = [annotation type];
-    if (mwcFlags.updatingLine == 0 && [annotation isSkimNote] && [type 
isEqualToString:SKNLineString]) {
+    if (mwcFlags.updatingLine == 0 && [annotation isSkimNote] && [[annotation 
keysForValuesToObserveForUndo] containsObject:SKNPDFAnnotationBorderKey]) {
         mwcFlags.updatingLine = 1;
-        [(PDFAnnotationLine *)annotation setStartLineStyle:[sender 
startLineStyle]];
+        switch (action) {
+            case SKLineWidthLineChangeAction:
+                [annotation setLineWidth:[sender lineWidth]];
+                break;
+            case SKStyleLineChangeAction:
+                [annotation setBorderStyle:[sender style]];
+                break;
+            case SKDashPatternLineChangeAction:
+                [annotation setDashPattern:[sender dashPattern]];
+                break;
+            case SKStartLineStyleLineChangeAction:
+                if ([[annotation type] isEqualToString:SKNLineString])
+                    [(PDFAnnotationLine *)annotation setStartLineStyle:[sender 
startLineStyle]];
+                break;
+            case SKEndLineStyleLineChangeAction:
+                if ([[annotation type] isEqualToString:SKNLineString])
+                    [(PDFAnnotationLine *)annotation setEndLineStyle:[sender 
endLineStyle]];
+                break;
+        }
         mwcFlags.updatingLine = 0;
     }
 }
 
-- (void)changeEndLineStyle:(id)sender {
-    PDFAnnotation *annotation = [pdfView activeAnnotation];
-    NSString *type = [annotation type];
-    if (mwcFlags.updatingLine == 0 && [annotation isSkimNote] && [type 
isEqualToString:SKNLineString]) {
-        mwcFlags.updatingLine = 1;
-        [(PDFAnnotationLine *)annotation setEndLineStyle:[sender 
endLineStyle]];
-        mwcFlags.updatingLine = 0;
-    }
-}
-
 - (IBAction)createNewNote:(id)sender{
     if ([pdfView hideNotes] == NO) {
         NSInteger type = [sender 
respondsToSelector:@selector(selectedSegment)] ? [sender selectedSegment] : 
[sender tag];


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to