From 79544cf7ff38cb3d235a09c9e1eca3e5b5f0ccad Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sun, 30 Jun 2024 12:14:48 +0200 Subject: [PATCH] Add back artworks copy & paste --- .../PropertyView/MovieViewController.swift | 42 +++++++------------ MP42Foundation | 2 +- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/Classes/PropertyView/MovieViewController.swift b/Classes/PropertyView/MovieViewController.swift index de82c65..ca4162c 100644 --- a/Classes/PropertyView/MovieViewController.swift +++ b/Classes/PropertyView/MovieViewController.swift @@ -1000,9 +1000,6 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie } } - /** Dragging Source Support - Required for multi-image drag and drop. - Return a custom object that implements NSPasteboardWriting (or simply use NSPasteboardItem), or nil to prevent dragging for the item. - */ func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting? { var provider: NSFilePromiseProvider? @@ -1091,7 +1088,6 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie // Look only for image urls. if let urls = pasteboard.readObjects(forClasses: [NSURL.self], options: options), !urls.isEmpty { // One or more of the URLs in this drag is image file. - // The sample allows for this; a user may be able to drag in a mix of files, any one of them being an image file. dragOperation = [.copy] } } @@ -1256,31 +1252,25 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie } func collectionViewCopy(in collectionView: NSCollectionView) { - // pasteboard.declareTypes([artworksPBoardType, .tiff], owner: nil) - // - // for image in itemIndexes.map({ artworks[$0] }).compactMap({ $0.imageValue }) { - // if let representations = image.image?.representations { - // let bitmapData = NSBitmapImageRep.representationOfImageReps(in: representations, using: .tiff, properties: [:]) - // pasteboard.setData(bitmapData, forType: .tiff) - // } - // pasteboard.setData(NSKeyedArchiver.archivedData(withRootObject: image), forType: artworksPBoardType) - // } - // - // return itemIndexes.count + let indexes = artworksView.selectionIndexes + if indexes.isEmpty { return } + + let pasteboard = NSPasteboard.general + pasteboard.clearContents() + + let items = indexes.compactMap { artworks[$0].imageValue } + pasteboard.writeObjects(items) } func collectionViewPaste(to collectionView: NSCollectionView) { - // let pb = NSPasteboard.general - // - // if let archivedImageData = pb.data(forType: artworksPBoardType), let image = NSKeyedUnarchiver.unarchiveObject(with: archivedImageData) as? MP42Image { - // _ = add(artworks: [image]) - // } else { - // let classes = [NSURL.classForCoder(), NSImage.classForCoder()] - // let options = [NSPasteboard.ReadingOptionKey.urlReadingContentsConformToTypes: NSImage.imageTypes] - // if let items = pb.readObjects(forClasses: classes, options: options) as [AnyObject]? { - // _ = add(artworks: items) - // } - // } + let pasteboard = NSPasteboard.general + + let classes = [MP42Image.classForCoder(), NSURL.classForCoder(), NSImage.classForCoder()] + let options = [NSPasteboard.ReadingOptionKey.urlReadingContentsConformToTypes: NSImage.imageTypes] + + if let items = pasteboard.readObjects(forClasses: classes, options: options) as [AnyObject]? { + _ = add(artworks: items, toIndexPath:IndexPath(index: 0)) + } } } diff --git a/MP42Foundation b/MP42Foundation index 23ac1a3..5555a95 160000 --- a/MP42Foundation +++ b/MP42Foundation @@ -1 +1 @@ -Subproject commit 23ac1a3256b2240c141e1b02e19e2873c0b0609c +Subproject commit 5555a95ee60a250fdd165d834169b6580541c761