From feffd2522989fa45d8b50ef112fa051dffad9d12 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 2 Jul 2024 17:49:11 +0200 Subject: [PATCH] Remove artworks when they are dragged to the Trash --- .../PropertyView/MovieViewController.swift | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Classes/PropertyView/MovieViewController.swift b/Classes/PropertyView/MovieViewController.swift index 869c124..2325d42 100644 --- a/Classes/PropertyView/MovieViewController.swift +++ b/Classes/PropertyView/MovieViewController.swift @@ -1227,6 +1227,33 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie return true } + func collectionView(_ collectionView: NSCollectionView, + draggingSession session: NSDraggingSession, + endedAt screenPoint: NSPoint, + dragOperation operation: NSDragOperation) { + if operation == .delete, let items = session.draggingPasteboard.pasteboardItems { + // User dragged the artwork to the Finder's trash. + var indexes = Set() + + for pasteboardItem in items { + do { + if let indexPathData = pasteboardItem.data(forType: .artworkDragType), + let itemIndexPath = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(indexPathData) as? IndexPath { + indexes.insert(itemIndexPath) + } + } catch { + Swift.debugPrint("failed to unarchive indexPath for dropped item.") + } + } + + if indexes.isEmpty == false { + let itemIndexes = indexes.compactMap { $0.last } + let draggedItems = itemIndexes.map { artworks[$0] } + remove(metadataArtworks: draggedItems) + } + } + } + @IBAction func zoomSliderDidChange(_ sender: NSControl) { let floatValue = CGFloat(sender.floatValue) if let layout = artworksView.collectionViewLayout as? NSCollectionViewFlowLayout {