KMLeftSideViewController+Note.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // KMLeftSideViewController+Note.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/12/23.
  6. //
  7. import Foundation
  8. // Menu
  9. extension KMLeftSideViewController {
  10. @IBAction func note_expandAllComments(_ sender: AnyObject?) {
  11. if (self.foldType == .unfold) {
  12. return
  13. }
  14. self.foldType = .unfold
  15. self.loadUnfoldDate(.none)
  16. self.noteOutlineView.reloadData()
  17. }
  18. @IBAction func note_foldAllComments(_ sender: AnyObject?) {
  19. if (self.foldType == .fold) {
  20. return
  21. }
  22. self.foldType = .fold
  23. self.loadUnfoldDate(.none)
  24. self.noteOutlineView.reloadData()
  25. }
  26. @IBAction func noteShowNoteAction(_ sender: AnyObject?) {
  27. let item = sender as? NSMenuItem
  28. let tag = item?.tag ?? 0
  29. if (tag == 100) {
  30. // BOOL isType = [[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue];
  31. // [self.noteTypeDict setObject:[NSNumber numberWithBool:!isType] forKey:@"kKMNoteFilterAnnotationTypeKey"];
  32. } else if (tag == 101) {
  33. let isPage = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false
  34. self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] = isPage
  35. } else if (tag == 102) {
  36. let isTime = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false
  37. self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] = isTime
  38. } else if (tag == 103) {
  39. let isAuther = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false
  40. self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] = isAuther
  41. }
  42. UserDefaults.standard.set(self.noteTypeDict, forKey: "KMNoteOutlineViewTableColumnKey")
  43. UserDefaults.standard.synchronize()
  44. let selectRow = self.noteOutlineView.selectedRow
  45. self.noteOutlineView.reloadData()
  46. self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  47. }
  48. @objc func exportAnnotationNotes(_ sender: AnyObject?) {
  49. let doc = self.view.window?.windowController?.document as? NSDocument
  50. doc?.saveTo(sender)
  51. }
  52. @objc func leftSideEmptyAnnotationClick_DeleteAnnotation(_ sender: AnyObject?) {
  53. guard let doc = self.listView.document else {
  54. return
  55. }
  56. Task {
  57. let response = await KMAlertTool.runModel(message: KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?", nil), buttons: [KMLocalizedString("Yes", nil), KMLocalizedString("No", nil)])
  58. if response == .alertFirstButtonReturn {
  59. var annotations = NSMutableArray()
  60. for i in 0 ..< doc.pageCount {
  61. let page = self.listView.document.page(at: i)
  62. for anno in page?.annotations ?? [] {
  63. if anno is CPDFTextWidgetAnnotation || anno is CPDFButtonWidgetAnnotation || anno is CPDFChoiceWidgetAnnotation {
  64. continue
  65. }
  66. // if (@available(macOS 10.13, *)) {
  67. // if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  68. // continue;
  69. // }
  70. // }
  71. // if anno is CPDFInkAnnotation {
  72. // continue
  73. // }
  74. annotations.add(anno)
  75. }
  76. }
  77. for anno in annotations {
  78. if let data = anno as? CPDFAnnotation {
  79. self.listView.remove(data)
  80. }
  81. }
  82. self.reloadAnnotation()
  83. self.noteOutlineView.reloadData()
  84. }
  85. }
  86. }
  87. @objc func unfoldNoteAction(_ sender: NSMenuItem) {
  88. if sender.state == .on {
  89. return
  90. }
  91. let row = self.noteOutlineView.clickedRow
  92. let foldNote = self.allAnnotations[row]
  93. if self.allFoldNotes.contains(foldNote) == false {
  94. self.allFoldNotes.append(foldNote)
  95. }
  96. if self.allFoldNotes.count == self.canFoldNotes.count {
  97. self.foldType = .unfold
  98. } else {
  99. self.foldType = .none
  100. }
  101. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
  102. (viewS as? KMNoteTableViewCell)?.isFold = false
  103. }
  104. @objc func foldNoteAction(_ sender: NSMenuItem) {
  105. // if sender.state == .on {
  106. // return
  107. // }
  108. let row = self.noteOutlineView.clickedRow
  109. let foldNote = self.allAnnotations[row]
  110. if self.allFoldNotes.contains(foldNote) == false {
  111. self.allFoldNotes.append(foldNote)
  112. }
  113. if (self.allFoldNotes.count == 0) {
  114. self.foldType = .fold
  115. } else {
  116. self.foldType = .none
  117. }
  118. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
  119. (viewS as? KMNoteTableViewCell)?.isFold = true
  120. }
  121. @objc func deleteNotes(_ sender: NSMenuItem) {
  122. self.outlineView(self.noteOutlineView, deleteItems: sender.representedObject as! [Any])
  123. }
  124. @objc func removeAllAnnotations(_ sender: AnyObject?) {
  125. self.leftSideEmptyAnnotationClick_DeleteAnnotation(nil)
  126. }
  127. @objc func editNoteTextFromTable(_ sender: NSMenuItem) {
  128. // PDFAnnotation *annotation = [sender representedObject];
  129. guard let annotation = sender.representedObject as? CPDFAnnotation else {
  130. return
  131. }
  132. self.listView.scrollAnnotationToVisible(annotation)
  133. // self.listView.activeAnnotation = annotation
  134. // [self showNote:annotation];
  135. // SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
  136. // [[noteController window] makeFirstResponder:[noteController textView]];
  137. // [[noteController textView] selectAll:nil];
  138. }
  139. @objc func editThisAnnotation(_ sender: AnyObject?) {
  140. KMPrint("editThisAnnotation ...")
  141. }
  142. @objc func editNoteFromTable(_ sender: AnyObject?) {
  143. KMPrint("editNoteFromTable ...")
  144. }
  145. }