1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // 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<IndexPath>
- var indexPaths: Set<IndexPath> = []
- indexPaths.insert(rightIndex!)
- self.selectionIndexPaths = indexPaths
- }
- } else {
- self.selectionIndexPaths = NSMutableSet() as! Set<IndexPath>
- }
- } else {
- self.selectionIndexPaths = NSMutableSet() as! Set<IndexPath>
- }
-
- if menuClickedAction != nil {
- let menu = menuClickedAction!(point)
- return menu
- }
-
- return super.menu(for: event)
- }
-
- override var selectionIndexPaths: Set<IndexPath> {
- didSet {
- collectionSelectChanges?()
- }
- }
-
- }
|