Revision: 3625
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3625&view=rev
Author:   hofman
Date:     2008-04-04 14:39:38 -0700 (Fri, 04 Apr 2008)

Log Message:
-----------
Reorganize some code.

Modified Paths:
--------------
    trunk/SKPDFView.m

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2008-04-04 20:38:31 UTC (rev 3624)
+++ trunk/SKPDFView.m   2008-04-04 21:39:38 UTC (rev 3625)
@@ -2774,35 +2774,27 @@
     if (activeAnnotation != newActiveAnnotation)
         [self setActiveAnnotation:newActiveAnnotation];
     
-    if (newActiveAnnotation == nil) {
-        //[super mouseDown:theEvent];
-    } else if ([theEvent clickCount] == 2 && [[activeAnnotation type] 
isEqualToString:SKFreeTextString]) {
-        [self editActiveAnnotation:self];
-        // probably we should use the note window for Text annotations
+    if (newActiveAnnotation) {
         
-    } else if ([theEvent clickCount] == 2 && [[activeAnnotation type] 
isEqualToString:SKNoteString]) {
-        
-               [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFViewAnnotationDoubleClickedNotification object:self 
-            userInfo:[NSDictionary 
dictionaryWithObjectsAndKeys:activeAnnotation, @"annotation", nil]];
-        
-    } else { 
-        // Old (current) annotation location.
-        wasBounds = [activeAnnotation bounds];
-        
-        if ([[activeAnnotation type] isEqualToString:SKLineString]) {
-            wasStartPoint = [(SKPDFAnnotationLine *)activeAnnotation 
startPoint];
-            wasEndPoint = [(SKPDFAnnotationLine *)activeAnnotation endPoint];
-        }
-        
-        // Hit-test for resize box.
-        dragMask = 0;
-        if ([[activeAnnotation type] isEqualToString:SKLineString]) {
-            if (NSPointInRect(pagePoint, 
SKRectFromCenterAndSize(SKAddPoints(wasBounds.origin, [(SKPDFAnnotationLine 
*)activeAnnotation endPoint]), SKMakeSquareSize(8.0))))
-                dragMask = BDSKMaxXEdgeMask;
-            else if (NSPointInRect(pagePoint, 
SKRectFromCenterAndSize(SKAddPoints(wasBounds.origin, [(SKPDFAnnotationLine 
*)activeAnnotation startPoint]), SKMakeSquareSize(8.0))))
-                dragMask = BDSKMinXEdgeMask;
-        }  else {
-            if ([activeAnnotation isResizable]) {
+        if ([theEvent clickCount] == 2 && ([[activeAnnotation type] 
isEqualToString:SKFreeTextString] || [[activeAnnotation type] 
isEqualToString:SKNoteString])) {
+            [self editActiveAnnotation:self];
+        } else { 
+            // Old (current) annotation location.
+            wasBounds = [activeAnnotation bounds];
+            
+            if ([[activeAnnotation type] isEqualToString:SKLineString]) {
+                wasStartPoint = [(SKPDFAnnotationLine *)activeAnnotation 
startPoint];
+                wasEndPoint = [(SKPDFAnnotationLine *)activeAnnotation 
endPoint];
+            }
+            
+            // Hit-test for resize box.
+            dragMask = 0;
+            if ([[activeAnnotation type] isEqualToString:SKLineString]) {
+                if (NSPointInRect(pagePoint, 
SKRectFromCenterAndSize(SKAddPoints(wasBounds.origin, [(SKPDFAnnotationLine 
*)activeAnnotation endPoint]), SKMakeSquareSize(8.0))))
+                    dragMask = BDSKMaxXEdgeMask;
+                else if (NSPointInRect(pagePoint, 
SKRectFromCenterAndSize(SKAddPoints(wasBounds.origin, [(SKPDFAnnotationLine 
*)activeAnnotation startPoint]), SKMakeSquareSize(8.0))))
+                    dragMask = BDSKMinXEdgeMask;
+            }  else if ([activeAnnotation isResizable]) {
                 if (NSWidth(wasBounds) < 2.0) {
                     dragMask |= BDSKMinXEdgeMask | BDSKMaxXEdgeMask;
                 } else if ([page rotation] < 180) {
@@ -2830,34 +2822,38 @@
                         dragMask |= BDSKMaxYEdgeMask;
                 }
             }
-        }
-        if (dragMask)
-            [self setNeedsDisplayForAnnotation:activeAnnotation];
-        
-        if ([activeAnnotation isMovable]) {
-            BOOL draggedAnnotation = NO;
-            while (YES) {
-                theEvent = [[self window] nextEventMatchingMask: 
NSLeftMouseUpMask | NSLeftMouseDraggedMask];
-                if ([theEvent type] == NSLeftMouseUp)
-                    break;
-                [self dragAnnotationWithEvent:theEvent];
-                draggedAnnotation = YES;
+            if (dragMask)
+                [self setNeedsDisplayForAnnotation:activeAnnotation];
+            
+            if ([activeAnnotation isMovable]) {
+                // we move or resize the annotation in an event loop, which 
ensures it's enclosed in a single undo group
+                BOOL draggedAnnotation = NO;
+                while (YES) {
+                    theEvent = [[self window] nextEventMatchingMask: 
NSLeftMouseUpMask | NSLeftMouseDraggedMask];
+                    if ([theEvent type] == NSLeftMouseUp)
+                        break;
+                    [self dragAnnotationWithEvent:theEvent];
+                    draggedAnnotation = YES;
+                }
+                if (toolMode == SKNoteToolMode && NSEqualSizes(wasBounds.size, 
NSZeroSize) && [[activeAnnotation type] isEqualToString:SKFreeTextString])
+                    [self editActiveAnnotation:self];   
+                if (draggedAnnotation && 
+                    [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableUpdateContentsFromEnclosedTextKey] == NO &&
+                    ([[activeAnnotation type] isEqualToString:SKCircleString] 
|| [[activeAnnotation type] isEqualToString:SKSquareString])) {
+                    NSString *selString = [[[[activeAnnotation page] 
selectionForRect:[activeAnnotation bounds]] string] 
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+                    [activeAnnotation setString:selString];
+                }
+                [self setNeedsDisplayForAnnotation:activeAnnotation];
+                mouseDownInAnnotation = NO;
+                dragMask = 0;
             }
-            if (toolMode == SKNoteToolMode && NSEqualSizes(wasBounds.size, 
NSZeroSize) && [[activeAnnotation type] isEqualToString:SKFreeTextString])
-                [self editActiveAnnotation:self];       
-            if (draggedAnnotation && 
-                [[NSUserDefaults standardUserDefaults] 
boolForKey:SKDisableUpdateContentsFromEnclosedTextKey] == NO &&
-                ([[activeAnnotation type] isEqualToString:SKCircleString] || 
[[activeAnnotation type] isEqualToString:SKSquareString])) {
-                NSString *selString = [[[[activeAnnotation page] 
selectionForRect:[activeAnnotation bounds]] string] 
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
-                [activeAnnotation setString:selString];
-            }
-            [self setNeedsDisplayForAnnotation:activeAnnotation];
-            mouseDownInAnnotation = NO;
-            dragMask = 0;
         }
+        
+        return YES;
+    } else {
+        // no new active annotation
+        return NO;
     }
-    
-    return newActiveAnnotation != nil;
 }
 
 - (void)dragAnnotationWithEvent:(NSEvent *)theEvent {


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

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to