KMNoteReplyHanddler.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 replyA = self.fetchMarkAnnotation(anno) else {
  12. anno?.createReplyStateAnnotation(.marked)
  13. return
  14. }
  15. if replyA.getAnnotState() == .unMarked {
  16. replyA.setAnnotState(.marked)
  17. }
  18. }
  19. func unMarkAnnotation(_ anno: CPDFAnnotation?) {
  20. guard let replyA = self.fetchMarkAnnotation(anno) else {
  21. return
  22. }
  23. if replyA.getAnnotState() == .marked {
  24. replyA.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 fetchReplyAnnotations(_ anno: CPDFAnnotation?) -> [CPDFAnnotation]? {
  34. guard let theAnno = anno else {
  35. return nil
  36. }
  37. var annos: [CPDFAnnotation] = []
  38. for a in theAnno.replyAnnotations ?? [] {
  39. if a.replyAnnotationType == .reply {
  40. annos.append(a)
  41. }
  42. }
  43. return annos
  44. }
  45. func fetchMarkAnnotation(_ anno: CPDFAnnotation?) -> CPDFAnnotation? {
  46. guard let theAnno = anno else {
  47. return nil
  48. }
  49. for replyA in theAnno.replyAnnotations ?? [] {
  50. if replyA.replyAnnotationType == .mark {
  51. return replyA
  52. }
  53. }
  54. return nil
  55. }
  56. }