KMNoteReplyHanddler.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // KMNoteReplyHanddler.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/9/19.
  6. //
  7. import Cocoa
  8. // 注释回复处理类
  9. class KMNoteReplyHanddler: NSObject {
  10. func markAnnotation(_ anno: CPDFAnnotation?) {
  11. guard let state = self.fetchAnnoState(anno) else {
  12. anno?.createReplyStateAnnotation(.marked)
  13. return
  14. }
  15. if state == .unMarked {
  16. anno?.setAnnotState(.marked)
  17. }
  18. }
  19. func unMarkAnnotation(_ anno: CPDFAnnotation?) {
  20. guard let state = self.fetchAnnoState(anno) else {
  21. return
  22. }
  23. if state == .marked {
  24. anno?.setAnnotState(.unMarked)
  25. }
  26. }
  27. func fetchAnnoState(_ anno: CPDFAnnotation?) -> CPDFAnnotationState? {
  28. guard let replyA = self.fetchMarkAnnotation(anno) else {
  29. return nil
  30. }
  31. return replyA.getAnnotState()
  32. }
  33. func fetchMarkAnnotation(_ anno: CPDFAnnotation?) -> CPDFAnnotation? {
  34. guard let theAnno = anno else {
  35. return nil
  36. }
  37. for replyA in theAnno.replyAnnotations ?? [] {
  38. if replyA.replyAnnotationType == .mark {
  39. return replyA
  40. }
  41. }
  42. return nil
  43. }
  44. }