KMNThumbnailCollectionView.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // KMNCollectionView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/10/27.
  6. //
  7. import Cocoa
  8. class KMNThumbnailCollectionView: NSCollectionView {
  9. var menuClickedAction: ((_ clickPoint: NSPoint) -> NSMenu)?
  10. override func draw(_ dirtyRect: NSRect) {
  11. super.draw(dirtyRect)
  12. // Drawing code here.
  13. }
  14. override func menu(for event: NSEvent) -> NSMenu? {
  15. let point = event.locationInWindow
  16. let rightIndex = indexPathForItem(at: convert(point, from: nil))
  17. if rightIndex != nil {
  18. let cellView = item(at: rightIndex!) as? KMNThumbnailCollectionViewItem
  19. if(cellView != nil) {
  20. if(cellView?.isSelected == true) {
  21. } else {
  22. self.selectionIndexPaths = NSMutableSet() as! Set<IndexPath>
  23. var indexPaths: Set<IndexPath> = []
  24. indexPaths.insert(rightIndex!)
  25. self.selectionIndexPaths = indexPaths
  26. }
  27. } else {
  28. self.selectionIndexPaths = NSMutableSet() as! Set<IndexPath>
  29. }
  30. } else {
  31. self.selectionIndexPaths = NSMutableSet() as! Set<IndexPath>
  32. }
  33. if menuClickedAction != nil {
  34. let menu = menuClickedAction!(point)
  35. return menu
  36. }
  37. return super.menu(for: event)
  38. }
  39. }