From 14e9e4fd339bfd00c26c61d5ec38aedc0287661c Mon Sep 17 00:00:00 2001 From: Mikhail Rubanov Date: Wed, 1 May 2024 17:08:03 -0300 Subject: [PATCH] =?UTF-8?q?Recognize=20images=20during=20drag=E2=80=99n?= =?UTF-8?q?=E2=80=99drop=20when=20pasteboard=20contains=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonUIAppKit/DragNDropImageView.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/VoiceOver Designer/Features/Sources/CommonUIAppKit/DragNDropImageView.swift b/VoiceOver Designer/Features/Sources/CommonUIAppKit/DragNDropImageView.swift index f54ec896..4acd91e4 100644 --- a/VoiceOver Designer/Features/Sources/CommonUIAppKit/DragNDropImageView.swift +++ b/VoiceOver Designer/Features/Sources/CommonUIAppKit/DragNDropImageView.swift @@ -146,6 +146,17 @@ open class DragNDropImageView: NSView { foundDocument = true } + for url in pasteboard.imageURLs { + if let image = NSImage(contentsOf: url) { + delegate?.didDrag(image: image, + locationInWindow: sender.draggingLocation, + name: image.name() + ) + + foundDocument = true + } + } + for url in pasteboard.VODesignURLs { delegate?.didDrag(path: url) foundDocument = true @@ -271,6 +282,13 @@ extension NSPasteboard { } ?? [] } + var imageURLs: [URL] { + readObjects(forClasses: [NSURL.self], options: nil)? + .compactMap { + $0 as? URL + } ?? [] + } + var images: [NSImage] { readObjects(forClasses: [NSImage.self], options: nil)? .compactMap {