Revision: 14572
          http://sourceforge.net/p/skim-app/code/14572
Author:   hofman
Date:     2024-10-23 22:12:42 +0000 (Wed, 23 Oct 2024)
Log Message:
-----------
paste image as anchored note drawing the image

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

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2024-10-23 09:31:10 UTC (rev 14571)
+++ trunk/SKPDFView.m   2024-10-23 22:12:42 UTC (rev 14572)
@@ -42,6 +42,7 @@
 #import "PDFAnnotation_SKExtensions.h"
 #import "PDFAnnotationMarkup_SKExtensions.h"
 #import "PDFAnnotationInk_SKExtensions.h"
+#import "SKNPDFAnnotationNote_SKExtensions.h"
 #import "PDFPage_SKExtensions.h"
 #import "NSString_SKExtensions.h"
 #import "NSCursor_SKExtensions.h"
@@ -1271,10 +1272,55 @@
             if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
                 [self setCurrentAnnotation:newAnnotation];
             
-        } else {
+        } else if (isPlainText == NO) {
             
-            NSBeep();
+            NSImage *image = [[pboard readObjectsForClasses:@[[NSImage class]] 
options:@{}] firstObject];
             
+            if (image) {
+                
+                // First try the current mouse position
+                NSPoint center = [self convertPoint:[[self window] 
mouseLocationOutsideOfEventStream] fromView:nil];
+                
+                // if the mouse was in the toolbar and there is a page below 
the toolbar, we get a point outside of the visible rect
+                page = NSMouseInRect(center, [self visibleContentRect], [self 
isFlipped]) ? [self pageForPoint:center nearest:NO] : nil;
+                
+                if (page == nil) {
+                    // Get center of the PDFView.
+                    NSRect viewFrame = [self frame];
+                    center = SKCenterPoint(viewFrame);
+                    page = [self pageForPoint: center nearest: YES];
+                }
+                
+                // Convert to "page space".
+                center = [self convertPoint: center toPage: page];
+                
+                NSRect bounds = SKRectFromCenterAndSize(center, [image size]);
+                bounds.origin = SKIntegralPoint(bounds.origin);
+                bounds = SKConstrainRect(bounds, [page boundsForBox:[self 
displayBox]]);
+                
+                NSString *text = nil;
+                if ([[NSUserDefaults standardUserDefaults] 
integerForKey:SKDisableUpdateContentsFromEnclosedTextKey] < 2)
+                    text = [[self currentSelection] cleanedString];
+                
+                PDFAnnotation *newAnnotation = [PDFAnnotation 
newSkimNoteWithBounds:bounds forType:SKNNoteString];
+                [(SKNPDFAnnotationNote *)newAnnotation setImage:image];
+                [(SKNPDFAnnotationNote *)newAnnotation 
setExtendedIconType:kSKNPDFTextAnnotationIconImage];
+                if ([text length] > 0)
+                    [newAnnotation setString:text];
+                
+                [newAnnotation registerUserName];
+                [self beginNewUndoGroupIfNeededWithCommit:YES];
+                [[self document] addAnnotation:newAnnotation toPage:page];
+                [self setUndoActionName:NSLocalizedString(@"Add Note", @"Undo 
action name")];
+
+                if (toolMode == SKToolModeText || toolMode == SKToolModeNote)
+                    [self setCurrentAnnotation:newAnnotation];
+                
+            } else {
+                
+                NSBeep();
+                
+            }
         }
     }
 }
@@ -2002,7 +2048,7 @@
             [menu insertItemWithTitle:NSLocalizedString(@"Remove Current 
Note", @"Menu item title") action:@selector(removeCurrentAnnotation:) 
target:self atIndex:0];
         }
         
-        if ([[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[PDFAnnotation class], [NSString class]] 
options:@{}]) {
+        if ([[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[PDFAnnotation class], [NSString class], [NSImage 
class]] options:@{}]) {
             [menu insertItemWithTitle:NSLocalizedString(@"Paste", @"Menu item 
title") action:@selector(paste:) keyEquivalent:@"" atIndex:0];
             item = [menu insertItemWithTitle:NSLocalizedString(@"Paste", 
@"Menu item title") action:@selector(alternatePaste:) keyEquivalent:@"" 
atIndex:1];
             [item setKeyEquivalentModifierMask:NSEventModifierFlagOption];
@@ -3105,9 +3151,9 @@
             return YES;
         return NO;
     } else if (action == @selector(paste:)) {
-        return [self canSelectNote] && [[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[PDFAnnotation class], [NSString class]] options:@{}];
+        return [self canSelectNote] && [[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[PDFAnnotation class], [NSString class], [NSImage 
class]] options:@{}];
     } else if (action == @selector(alternatePaste:)) {
-        return [self canSelectNote] && [[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[PDFAnnotation class], [NSAttributedString class], 
[NSString class]] options:@{}];
+        return [self canSelectNote] && [[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[PDFAnnotation class], [NSAttributedString class], 
[NSString class], [NSImage class]] options:@{}];
     } else if (action == @selector(pasteAsPlainText:)) {
         return [self canSelectNote] && [[NSPasteboard generalPasteboard] 
canReadObjectForClasses:@[[NSAttributedString class], [NSString class]] 
options:@{}];
     } else if (action == @selector(delete:)) {

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to