12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // KMNCollectionView.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/10/27.
- //
- import Cocoa
- class KMNThumbnailCollectionView: NSCollectionView {
- var menuClickedAction: ((_ clickPoint: NSPoint) -> NSMenu)?
-
-
- 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)
- }
-
- }
|