// // KMNCollectionView.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/10/27. // import Cocoa class KMNThumbnailCollectionView: NSCollectionView { var menuClickedAction: ((_ clickPoint: NSPoint) -> NSMenu)? var collectionSelectChanges: (() -> Void)? override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func menu(for event: NSEvent) -> NSMenu? { let point = event.locationInWindow let rightIndex = indexPathForItem(at: convert(point, from: nil)) if rightIndex != nil { let cellView = item(at: rightIndex!) as? KMNThumbnailCollectionViewItem if(cellView != nil) { if(cellView?.isSelected == true) { } else { self.selectionIndexPaths = NSMutableSet() as! Set var indexPaths: Set = [] indexPaths.insert(rightIndex!) self.selectionIndexPaths = indexPaths } } else { self.selectionIndexPaths = NSMutableSet() as! Set } } else { self.selectionIndexPaths = NSMutableSet() as! Set } if menuClickedAction != nil { let menu = menuClickedAction!(point) return menu } return super.menu(for: event) } override var selectionIndexPaths: Set { didSet { collectionSelectChanges?() } } }