From 7ee51541ddb0da8c69b76e0754fa92cd95cb0e83 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sun, 30 Jun 2024 12:47:51 +0200 Subject: [PATCH] Properly enable the copy menu item --- Classes/PropertyView/MovieViewController.swift | 12 ++++++------ CollectionView.swift | 2 +- MP42Foundation | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Classes/PropertyView/MovieViewController.swift b/Classes/PropertyView/MovieViewController.swift index ca4162c..324804a 100644 --- a/Classes/PropertyView/MovieViewController.swift +++ b/Classes/PropertyView/MovieViewController.swift @@ -62,7 +62,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie private let standardSize = NSSize(width: 154, height: 192) @IBOutlet var removeArtworkButton: NSButton! - @IBOutlet var artworksView: NSCollectionView! + @IBOutlet var artworksView: CollectionView! override var nibName: NSNib.Name? { return "MovieView" @@ -125,11 +125,11 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie artworksView.register(ArtworkSelectorViewItem.self, forItemWithIdentifier: ArtworkSelectorController.itemView) artworksView.registerForDraggedTypes(NSFilePromiseReceiver.readableDraggedTypes.map { NSPasteboard.PasteboardType($0)}) artworksView.registerForDraggedTypes([.fileURL, .artworkDragType]) + artworksView.pasteboardTypes = [.fileURL, .tiff, .MP42PasteboardTypeArtwork] // Determine the kind of source drag originating from this app. // Note, if you want to allow your app to drag items to the Finder's trash can, add ".delete". artworksView.setDraggingSourceOperationMask([.copy, .delete], forLocal: false) - artworksView.setDraggingSourceOperationMask([.copy, .move], forLocal: true) reloadData() } @@ -866,7 +866,6 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie } private func replace(metadataArtworks items: [MP42MetadataItem], withItems newItems: [MP42MetadataItem]) { - metadata.removeItems(items) metadata.addItems(newItems) @@ -882,12 +881,14 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie updateArtworksArray() artworksView.reloadData() + updateSelection() } @IBAction func removeArtwork(_ sender: Any?) { let selectedIndexes = artworksView.selectionIndexes artworks = IndexSet(artworks.indices).subtracting(selectedIndexes).map {artworks[$0]} artworksView.deleteItems(at: artworksView.selectionIndexPaths) + updateSelection() } private func add(artworks: [Any], toIndexPath: IndexPath) -> Bool { @@ -914,6 +915,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie return false } else { add(metadataArtworks: items) + updateSelection() return true } } @@ -1246,9 +1248,7 @@ class MovieViewController: PropertyView, NSTableViewDataSource, ExpandedTableVie } func collectionViewDelete(in collectionView: NSCollectionView) { - let itemIndexes = collectionView.selectionIndexPaths.compactMap { $0.last } - let items = itemIndexes.map { artworks[$0] } - remove(metadataArtworks: items) + removeArtwork(self) } func collectionViewCopy(in collectionView: NSCollectionView) { diff --git a/CollectionView.swift b/CollectionView.swift index 954d623..4019dcf 100644 --- a/CollectionView.swift +++ b/CollectionView.swift @@ -120,7 +120,7 @@ class CollectionView: NSCollectionView, NSMenuItemValidation { return false } case #selector(paste(_:)): - if isSelectionEmpty || implements(selector: #selector(CollectionViewDelegate.collectionViewPaste(to:))) == false { + if pasteboardHasSupportedType == false || implements(selector: #selector(CollectionViewDelegate.collectionViewPaste(to:))) == false { return false } default: diff --git a/MP42Foundation b/MP42Foundation index 5555a95..cb51493 160000 --- a/MP42Foundation +++ b/MP42Foundation @@ -1 +1 @@ -Subproject commit 5555a95ee60a250fdd165d834169b6580541c761 +Subproject commit cb5149390f17d0e21f66d4b95f99ba230342f2d7