KMLeftSideViewController+Note.swift 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. //
  2. // KMLeftSideViewController+Note.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/12/23.
  6. //
  7. import Foundation
  8. extension KMLeftSideViewController.Key {
  9. static let noteAscendSortKey = "KMLeftSideViewAscendSortBoolKey"
  10. static let noteSortTypeKey = "KMLeftSideViewNoteSortTypeKey"
  11. static let noteTableColumn = "KMNoteOutlineViewTableColumnKey"
  12. static let noteFilterPage = "kKMNoteFilterAnnotationPageKey"
  13. static let noteFilterTime = "kKMNoteFilterAnnotationTimeKey"
  14. static let noteFilterAuther = "kKMNoteFilterAnnotationAutherKey"
  15. }
  16. // MARK: - Action
  17. extension KMLeftSideViewController {
  18. func note_initSubViews() {
  19. self.noteSearchField.backgroundColor = KMAppearance.Layout.l_1Color()
  20. self.noteSearchField.wantsLayer = true
  21. self.noteSearchField.layer?.backgroundColor = KMAppearance.Layout.l_1Color().cgColor
  22. self.noteSearchField.layer?.borderWidth = 1.0
  23. self.noteMoreButton.target = self
  24. self.noteMoreButton.tag = 304
  25. self.noteMoreButton.action = #selector(leftSideViewMoreButtonAction)
  26. self.moreButtonLayer = KMButtonLayer()
  27. self.noteMoreButton.layer?.addSublayer(self.moreButtonLayer!)
  28. self.moreButtonLayer?.frame = NSMakeRect(0, 0, NSWidth(self.noteMoreButton.bounds), NSHeight(self.noteMoreButton.bounds))
  29. self.noteFilterButton.target = self
  30. self.noteFilterButton.action = #selector(noteFilterAction)
  31. self.filterButtonLayer = NSView()
  32. self.noteFilterButton.addSubview(self.filterButtonLayer!)
  33. self.filterButtonLayer?.frame = NSMakeRect(14, 2, 8, 8)
  34. self.noteDoneButton.action = #selector(leftSideViewDoneButtonAction)
  35. self.noteDoneButton.target = self
  36. self.noteDoneButton.tag = 311
  37. self.noteDoneButton.isHidden = true
  38. self.noteSearchField.delegate = self
  39. self.noteSearchField.isHidden = true
  40. self.noteSearchField.endEditCallBack = { [weak self] isEndEdit in
  41. // if (isEndEdit) {
  42. // self.noteSearchField.isHidden = true
  43. // self.noteSearchButton.isHidden = false
  44. // self.noteTitleLabel.isHidden = false
  45. // }
  46. }
  47. self.sortTypeBox.downCallback = { [unowned self] downEntered, mouseBox, _ in
  48. if (downEntered) {
  49. let menu = NSMenu()
  50. let timeItem = menu.addItem(title: KMLocalizedString("Time", nil), action: #selector(sortTypeAction), target: self)
  51. timeItem?.representedObject = self
  52. timeItem?.tag = 0
  53. let pageItem = menu.addItem(title: KMLocalizedString("Page", nil), action: #selector(sortTypeAction), target: self)
  54. pageItem?.representedObject = self
  55. timeItem?.tag = 1
  56. if (self.noteSortType == .time) {
  57. timeItem?.state = .on
  58. pageItem?.state = .off
  59. } else if (self.noteSortType == .page) {
  60. timeItem?.state = .off
  61. pageItem?.state = .on
  62. }
  63. menu.popUp(positioning: nil, at: NSMakePoint(-10, 0), in: self.sortTypeBox)
  64. }
  65. }
  66. self.noteOutlineView.delegate = self
  67. self.noteOutlineView.dataSource = self
  68. self.noteOutlineView.botaDelegate = self
  69. self.noteOutlineView.botaDataSource = self
  70. self.noteOutlineView.noteDelegate = self
  71. self.noteOutlineView.menu = NSMenu()
  72. self.noteOutlineView.menu?.delegate = self
  73. self.noteOutlineView.typeSelectHelper = SKTypeSelectHelper(matchOption: .SKSubstringMatch)
  74. self.noteOutlineView.registerForDraggedTypes(NSColor.readableTypes(for: NSPasteboard(name: .drag)))
  75. self.noteOutlineView.target = self
  76. self.noteOutlineView.doubleAction = #selector(selectSelectedNote)
  77. }
  78. func note_initDefalutValue() {
  79. self.noteView.wantsLayer = true
  80. self.noteView.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  81. let sud = UserDefaults.standard
  82. if let dict = sud.dictionary(forKey: Self.Key.noteTableColumn) {
  83. self.noteTypeDict = dict
  84. } else {
  85. self.noteTypeDict = [Self.Key.noteFilterPage : false,
  86. Self.Key.noteFilterTime : false,
  87. Self.Key.noteFilterAuther : false]
  88. sud.sync_setValue(self.noteTypeDict, forKey: Self.Key.noteTableColumn)
  89. }
  90. self.caseInsensitiveNoteSearch = sud.bool(forKey: SKCaseInsensitiveNoteSearchKey)
  91. self.isAscendSort = KMDataManager.ud_bool(forKey: Self.Key.noteAscendSortKey)
  92. self.noteTitleLabel.stringValue = KMLocalizedString("Notes", nil);
  93. self.noteTitleLabel.textColor = KMAppearance.Layout.h0Color()
  94. self.noteSearchField.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
  95. self.noteMoreButton.wantsLayer = true
  96. self.moreButtonLayer?.layerType = .none
  97. self.moreButtonLayer?.isHidden = true
  98. self.noteFilterButton.toolTip = KMLocalizedString("Sort", nil)
  99. self.noteFilterButton.wantsLayer = true
  100. self.filterButtonLayer?.isHidden = true
  101. self.filterButtonLayer?.wantsLayer = true
  102. self.filterButtonLayer?.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  103. self.filterButtonLayer?.layer?.cornerRadius = 4.0
  104. if (self.isAscendSort) {
  105. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  106. self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  107. } else {
  108. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  109. self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  110. }
  111. self.noteSearchButton.toolTip = KMLocalizedString("Search", nil)
  112. self.noteDoneButton.title = KMLocalizedString("Done", nil)
  113. self.noteDoneButton.toolTip = KMLocalizedString("Done", nil)
  114. self.noteDoneButton.setTitleColor(KMAppearance.Layout.w0Color())
  115. self.noteDoneButton.wantsLayer = true
  116. self.noteDoneButton.layer?.backgroundColor = KMAppearance.Interactive.a0Color().cgColor
  117. self.noteDoneButton.layer?.cornerRadius = 4.0
  118. self.noteHeaderView.wantsLayer = true
  119. self.noteHeaderView.layer?.backgroundColor = KMAppearance.Else.textTagColor().cgColor
  120. self.noteHeaderView.layer?.cornerRadius = 1.0
  121. let sortType = KMDataManager.ud_integer(forKey: Self.Key.noteSortTypeKey)
  122. if (sortType == 1) {
  123. self.noteSortType = KMNoteSortType(rawValue: sortType) ?? .none
  124. if (self.noteSortType == .time) {
  125. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  126. self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
  127. } else if (self.noteSortType == .page) {
  128. self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
  129. self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
  130. }
  131. } else {
  132. self.noteSortType = .time
  133. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  134. }
  135. self.sortTypeLabel.textColor = KMAppearance.Layout.h1Color()
  136. self.noteOutlineView.backgroundColor = KMAppearance.Layout.l0Color()
  137. self.noteOutlineView.autoresizesOutlineColumn = false
  138. self.noteOutlineView.indentationPerLevel = 0
  139. }
  140. func annoListIsShowPage() -> Bool {
  141. return !(self.noteTypeDict[Self.Key.noteFilterPage] as? Bool ?? false)
  142. }
  143. func annoListIsShowTime() -> Bool {
  144. return !(self.noteTypeDict[Self.Key.noteFilterTime] as? Bool ?? false)
  145. }
  146. func annoListIsShowAnther() -> Bool {
  147. return !(self.noteTypeDict[Self.Key.noteFilterAuther] as? Bool ?? false)
  148. }
  149. }
  150. // MARK: - Menu
  151. extension KMLeftSideViewController {
  152. func annoListMenu(_ menu: NSMenu) {
  153. var item: NSMenuItem?
  154. var items: NSArray?
  155. var rowIndexes = self.noteOutlineView.selectedRowIndexes
  156. let row = self.noteOutlineView.clickedRow
  157. if row == -1 {
  158. _ = self._addExportPDFMenu(menu)
  159. _ = self._addDeleteAllAnnoItem(menu)
  160. return
  161. }
  162. if rowIndexes.contains(row) == false {
  163. rowIndexes = IndexSet(integer: row)
  164. }
  165. items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
  166. guard let model = self.fetchAnnoModel(for: row) else {
  167. return
  168. }
  169. let isFold = model.isFold()
  170. item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
  171. item?.state = isFold ? .off : .on
  172. item?.representedObject = items
  173. item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
  174. item?.state = isFold ? .on : .off
  175. item?.representedObject = items
  176. menu.addItem(.separator())
  177. let hideNotes = self.hideNotes()
  178. if hideNotes == false && (items?.count ?? 0) == 1 {
  179. let annotation = self.noteItems(items!).lastObject as? CPDFAnnotation
  180. if let data = annotation?.isEditable(), data {
  181. if annotation?.type == nil {
  182. let isNote = annotation?.isNote() ?? false
  183. if isNote {
  184. // [NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis]
  185. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteTextFromTable), target: self)
  186. item?.representedObject = annotation
  187. }
  188. } else if let data = self.noteOutlineView.tableColumn(withIdentifier: NSUserInterfaceItemIdentifier("note"))?.isHidden, data {
  189. // [NSLocalizedString(@"Edit", @"Menu item title") stringByAppendingEllipsis]
  190. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
  191. item?.representedObject = annotation
  192. } else {
  193. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteFromTable), target: self)
  194. item?.representedObject = annotation
  195. item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
  196. item?.representedObject = annotation
  197. item?.keyEquivalentModifierMask = [.option]
  198. item?.isAlternate = true
  199. }
  200. }
  201. }
  202. if menu.numberOfItems > 0 {
  203. _ = self._addExportPDFMenu(menu)
  204. menu.addItem(.separator())
  205. if self.outlineView(self.noteOutlineView, canDeleteItems: items as? [Any] ?? []) {
  206. item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
  207. item?.representedObject = items
  208. }
  209. _ = self._addDeleteAllAnnoItem(menu)
  210. }
  211. }
  212. private func _addExportPDFMenu(_ menu: NSMenu) -> NSMenu {
  213. var item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "", comment: ""), action: nil, target: self)
  214. let subMenu = NSMenu()
  215. item?.submenu = subMenu
  216. item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  217. item?.tag = 0
  218. item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  219. item?.tag = 1
  220. item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  221. item?.tag = 2
  222. item = subMenu.addItem(title: NSLocalizedString("Notes as Text", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  223. item?.tag = 3
  224. item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  225. item?.tag = 4
  226. item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  227. item?.tag = 5
  228. item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  229. item?.tag = 6
  230. return menu
  231. }
  232. private func _addDeleteAllAnnoItem(_ menu: NSMenu) -> NSMenuItem? {
  233. return menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "", comment: ""), action: #selector(removeAllAnnotations), target: self)
  234. }
  235. func annoListMoreMenu(_ view: NSButton) {
  236. let menu = NSMenu()
  237. let object = KMPopupMenuObject()
  238. object.menuTag = 1001
  239. menu.delegate = object
  240. object.enterControllerCallback = { [weak self] isEnter in
  241. if (isEnter) {
  242. self?.moreButtonLayer?.isHidden = false
  243. } else {
  244. self?.moreButtonLayer?.isHidden = true
  245. }
  246. }
  247. let expandAllItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
  248. expandAllItem?.representedObject = self.noteOutlineView
  249. let foldAllItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
  250. foldAllItem?.representedObject = self.noteOutlineView
  251. let type = self.annoListModel?.foldType ?? .none
  252. expandAllItem?.state = type == .unfold ? .on : .off
  253. foldAllItem?.state = type == .fold ? .on : .off
  254. let showItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
  255. let subMenu = NSMenu()
  256. let pageItem = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
  257. pageItem?.state = self.annoListIsShowPage() ? .on : .off
  258. pageItem?.representedObject = self.noteOutlineView
  259. pageItem?.tag = 101
  260. let timeItem = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
  261. timeItem?.state = self.annoListIsShowTime() ? .on : .off
  262. timeItem?.representedObject = self.noteOutlineView
  263. timeItem?.tag = 102
  264. let authorItem = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
  265. authorItem?.state = self.annoListIsShowAnther() ? .on : .off
  266. authorItem?.representedObject = self.noteOutlineView
  267. authorItem?.tag = 103
  268. showItem?.submenu = subMenu
  269. menu.addItem(.separator())
  270. _ = self._addExportPDFMenu(menu)
  271. menu.addItem(.separator())
  272. _ = self._addDeleteAllAnnoItem(menu)
  273. if let data = NSApp.currentEvent {
  274. NSMenu.popUpContextMenu(menu, with: data, for: view, with: nil)
  275. }
  276. }
  277. func annoListValidateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  278. let action = menuItem.action
  279. if (action == #selector(note_expandAllComments) ||
  280. action == #selector(note_foldAllComments) ||
  281. action == #selector(exportAnnotationNotes) ||
  282. action == #selector(removeAllAnnotations)) {
  283. let cnt = self.annoListModel?.datas.count ?? 0
  284. return cnt > 0
  285. } else if (action == #selector(unfoldNoteAction) ||
  286. action == #selector(foldNoteAction)) {
  287. let row = self.noteOutlineView.clickedRow
  288. let foldNote = self.fetchNote(for: row)
  289. // SKNPDFAnnotationNote
  290. if foldNote is CPDFMarkupAnnotation || foldNote is CPDFTextAnnotation {
  291. return true
  292. } else {
  293. return false
  294. }
  295. } else if (action == #selector(editNoteFromTable)) {
  296. let row = self.noteOutlineView.clickedRow
  297. let foldNote = self.fetchNote(for: row)
  298. // if (@available(macOS 10.13, *)) {
  299. // if ([foldNote.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  300. // return NO;
  301. // }
  302. // }
  303. if foldNote is CPDFStampAnnotation || foldNote is KMAnnotationStamp || foldNote is CPDFListStampAnnotation {
  304. return false
  305. } else {
  306. return true
  307. }
  308. }
  309. return true
  310. }
  311. @IBAction func note_expandAllComments(_ sender: AnyObject?) {
  312. guard let model = self.annoListModel else {
  313. return
  314. }
  315. if (model.foldType == .unfold) { // 已全部展开
  316. return
  317. }
  318. model.foldType = .unfold
  319. self.noteOutlineView.reloadData()
  320. }
  321. @IBAction func note_foldAllComments(_ sender: AnyObject?) {
  322. guard let model = self.annoListModel else {
  323. return
  324. }
  325. if (model.foldType == .fold) {
  326. return
  327. }
  328. model.foldType = .fold
  329. self.noteOutlineView.reloadData()
  330. }
  331. @IBAction func noteShowNoteAction(_ sender: AnyObject?) {
  332. let item = sender as? NSMenuItem
  333. let tag = item?.tag ?? 0
  334. if (tag == 100) {
  335. } else if (tag == 101) {
  336. let isPage = !self.annoListIsShowPage()
  337. self.noteTypeDict[Self.Key.noteFilterPage] = !isPage
  338. } else if (tag == 102) {
  339. let isTime = !self.annoListIsShowTime()
  340. self.noteTypeDict[Self.Key.noteFilterTime] = !isTime
  341. } else if (tag == 103) {
  342. let isAuther = !self.annoListIsShowAnther()
  343. self.noteTypeDict[Self.Key.noteFilterAuther] = !isAuther
  344. }
  345. UserDefaults.standard.sync_setValue(self.noteTypeDict, forKey: Self.Key.noteTableColumn)
  346. // 更新数据
  347. var models: [KMBotaAnnotationModel] = []
  348. if self.noteSearchMode {
  349. models = self.noteSearchArray
  350. } else {
  351. models = self.annoListModel?.datas ?? []
  352. }
  353. for model in models {
  354. model.showPage = self.annoListIsShowPage()
  355. model.showTime = self.annoListIsShowTime()
  356. model.showAuthor = self.annoListIsShowAnther()
  357. }
  358. let selectRow = self.noteOutlineView.selectedRow
  359. self.noteOutlineView.reloadData()
  360. self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  361. }
  362. @objc func exportAnnotationNotes(_ sender: AnyObject?) {
  363. let doc = self.view.window?.windowController?.document as? NSDocument
  364. doc?.saveTo(sender)
  365. }
  366. // 展开
  367. @objc func unfoldNoteAction(_ sender: NSMenuItem) {
  368. if sender.state == .on {
  369. return
  370. }
  371. let row = self.noteOutlineView.clickedRow
  372. guard let model = self.fetchAnnoModel(for: row) else {
  373. return
  374. }
  375. model.foldType = .unfold
  376. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
  377. (viewS as? KMNoteTableViewCell)?.isFold = false
  378. }
  379. @objc func foldNoteAction(_ sender: NSMenuItem) {
  380. if sender.state == .on {
  381. return
  382. }
  383. let row = self.noteOutlineView.clickedRow
  384. guard let model = self.fetchAnnoModel(for: row) else {
  385. return
  386. }
  387. model.foldType = .fold
  388. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
  389. (viewS as? KMNoteTableViewCell)?.isFold = true
  390. }
  391. @objc func deleteNotes(_ sender: NSMenuItem) {
  392. self.outlineView(self.noteOutlineView, deleteItems: sender.representedObject as? [Any] ?? [])
  393. }
  394. @objc func removeAllAnnotations(_ sender: AnyObject?) {
  395. guard let doc = self.pdfDocument() else {
  396. return
  397. }
  398. Task {
  399. 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)])
  400. if response == .alertFirstButtonReturn {
  401. // var annos: [CPDFAnnotation] = []
  402. // for i in 0 ..< doc.pageCount {
  403. // let page = self.pdfDocument()?.page(at: i)
  404. // for anno in page?.annotations ?? [] {
  405. // if anno is CPDFTextWidgetAnnotation || anno is CPDFButtonWidgetAnnotation || anno is CPDFChoiceWidgetAnnotation {
  406. // continue
  407. // }
  408. // // if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) {
  409. // // continue;
  410. // // }
  411. // if anno is CPDFLinkAnnotation {
  412. // continue
  413. // }
  414. // annos.append(anno)
  415. // }
  416. // }
  417. self.dataUpdating = true
  418. // for anno in annos {
  419. // self.listView?.remove(anno)
  420. // }
  421. for model in self.annoListModel?.datas ?? [] {
  422. if let anno = model.anno {
  423. self.listView?.remove(anno)
  424. }
  425. }
  426. self.dataUpdating = false
  427. self.note_refrshUIIfNeed()
  428. }
  429. }
  430. }
  431. @objc func editNoteTextFromTable(_ sender: NSMenuItem) {
  432. // PDFAnnotation *annotation = [sender representedObject];
  433. guard let annotation = sender.representedObject as? CPDFAnnotation else {
  434. return
  435. }
  436. self.listView?.scrollAnnotationToVisible(annotation)
  437. // self.listView.activeAnnotation = annotation
  438. // [self showNote:annotation];
  439. // SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation];
  440. // [[noteController window] makeFirstResponder:[noteController textView]];
  441. // [[noteController textView] selectAll:nil];
  442. }
  443. @objc func editThisAnnotation(_ sender: AnyObject?) {
  444. guard let annotation = (sender as? NSMenuItem)?.representedObject as? CPDFAnnotation else {
  445. NSSound.beep()
  446. return
  447. }
  448. self.listView?.edit(annotation)
  449. }
  450. @objc func editNoteFromTable(_ sender: AnyObject?) {
  451. guard let annotation = (sender as? NSMenuItem)?.representedObject as? CPDFAnnotation else {
  452. NSSound.beep()
  453. return
  454. }
  455. let model = fetchAnnoModel(for: annotation)
  456. let row = self.noteOutlineView.row(forItem: model)
  457. self.noteOutlineView.km_safe_selectRowIndexes(.init(integer: row), byExtendingSelection: false)
  458. let noteIndex = self.noteOutlineView.column(withIdentifier: .init("note"))
  459. if (noteIndex >= 0) {
  460. self.noteOutlineView.scrollColumnToVisible(noteIndex)
  461. //
  462. self.isRenameNoteOutline = true
  463. // self.renamePDFOutline = [rightSideController.noteOutlineView itemAtRow:rightSideController.noteOutlineView.clickedRow];
  464. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true) as? KMNoteTableViewCell
  465. viewS!.isFold = false
  466. let targrtTextField = viewS?.noteContentLabel
  467. self.editNoteTextField = targrtTextField
  468. self.editNote = annotation
  469. targrtTextField?.delegate = self
  470. targrtTextField?.isEditable = true
  471. targrtTextField?.becomeFirstResponder()
  472. }
  473. }
  474. @IBAction func noteSortAction(_ sender: AnyObject?) {
  475. if (self.isAscendSort) {
  476. self.isAscendSort = false
  477. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  478. self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  479. } else {
  480. self.isAscendSort = true
  481. self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  482. self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  483. }
  484. KMDataManager.ud_set(self.isAscendSort, forKey: Self.Key.noteAscendSortKey)
  485. if self.noteSearchMode {
  486. self.reloadNoteForSearchMode()
  487. } else {
  488. self.reloadAnnotation()
  489. }
  490. }
  491. @IBAction func noteSearchAction(_ sender: NSButton) {
  492. self.noteSearchField.isHidden = false
  493. self.noteTitleLabel.isHidden = true
  494. self.noteSearchButton.isHidden = true
  495. self.noteDoneButton.isHidden = false
  496. self.noteFilterButton.isHidden = true
  497. self.noteMoreButton.isHidden = true
  498. self.noteSearchField.becomeFirstResponder()
  499. }
  500. @IBAction func noteFilterAction(_ sender: AnyObject?) {
  501. let button = sender as? NSButton
  502. let menu = NSMenu()
  503. let filterViewController = KMNoteOutlineFilterViewController()
  504. filterViewController.listView = self.listView
  505. filterViewController.view.layer?.backgroundColor = .clear
  506. filterViewController.setNotesArray(self.allAnnotations as NSArray)
  507. filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
  508. menu.cancelTracking()
  509. if (isEmpty) {
  510. self?.filterButtonLayer?.isHidden = true
  511. } else {
  512. self?.filterButtonLayer?.isHidden = false
  513. }
  514. self?.reloadAnnotation()
  515. }
  516. filterViewController.cancelCallback = { isCancel in
  517. if (isCancel) {
  518. menu.cancelTracking()
  519. }
  520. }
  521. let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
  522. item.target = self
  523. item.representedObject = filterViewController
  524. item.view = filterViewController.view
  525. menu.popUp(positioning: nil, at: NSMakePoint(-130, 30), in: button)
  526. }
  527. func fetchNote(for index: Int) -> CPDFAnnotation? {
  528. return self.fetchAnnoModel(for: index)?.anno
  529. }
  530. func fetchAnnoModel(for index: Int) -> KMBotaAnnotationModel? {
  531. if self.noteSearchMode { // 搜索模式
  532. return self.noteSearchArray.safe_element(for: index) as? KMBotaAnnotationModel
  533. } else { // 常规模式(非搜索)
  534. return self.annoListModel?.datas.safe_element(for: index) as? KMBotaAnnotationModel
  535. }
  536. }
  537. func fetchAnnoModel(for anno: CPDFAnnotation) -> KMBotaAnnotationModel? {
  538. if self.noteSearchMode { // 搜索模式
  539. for model in self.noteSearchArray {
  540. if anno.isEqual(to: model.anno) {
  541. return model
  542. }
  543. }
  544. } else { // 常规模式(非搜索)
  545. for model in self.annoListModel?.datas ?? [] {
  546. if anno.isEqual(to: model.anno) {
  547. return model
  548. }
  549. }
  550. }
  551. return nil
  552. }
  553. @IBAction @objc func sortTypeAction(_ sender: NSMenuItem) {
  554. let item = sender
  555. let tag = item.tag
  556. if (item.state == .on) {
  557. item.state = .off
  558. } else {
  559. item.state = .on
  560. }
  561. if (tag == 0) {
  562. self.noteSortType = .page
  563. self.sortTypeLabel.stringValue = KMLocalizedString("Page", nil)
  564. self.sortTypeBox.toolTip = KMLocalizedString("Page", nil)
  565. } else if (tag == 1) {
  566. self.noteSortType = .time
  567. self.sortTypeLabel.stringValue = KMLocalizedString("Time", nil)
  568. self.sortTypeBox.toolTip = KMLocalizedString("Time", nil)
  569. }
  570. KMDataManager.ud_set(self.noteSortType.rawValue, forKey: Self.Key.noteSortTypeKey)
  571. if self.noteSearchMode {
  572. self.reloadNoteForSearchMode()
  573. } else {
  574. self.reloadAnnotation()
  575. }
  576. }
  577. func showNoteEmptyView() {
  578. let view = self.noteOutlineView.enclosingScrollView?.documentView
  579. let viewFrame = view?.frame ?? .zero
  580. let emptyVcSize = self.leftSideEmptyVC.emptyAnnotationView.frame.size
  581. self.leftSideEmptyVC.emptyAnnotationView.frame = NSMakeRect((viewFrame.size.width-emptyVcSize.width)/2.0,(viewFrame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
  582. self.leftSideEmptyVC.emptyAnnotationView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
  583. self.noteOutlineView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.emptyAnnotationView)
  584. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = false
  585. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = false
  586. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  587. self.noteHeaderView.isHidden = true
  588. self.toolButtonBoxLayoutConstraint.constant = 40.0
  589. }
  590. }
  591. func hideNoteEmptyView() {
  592. self.leftSideEmptyVC.emptyAnnotationView.removeFromSuperview()
  593. self.leftSideEmptyVC.exportAnnotationBtn.isEnabled = true
  594. self.leftSideEmptyVC.deleteAnnotationBtn.isEnabled = true
  595. if (self.leftView.segmentedControl.selectedSegment == KMSelectedSegmentType.annotation.rawValue) {
  596. self.noteHeaderView.isHidden = false
  597. self.toolButtonBoxLayoutConstraint.constant = 64.0
  598. }
  599. }
  600. }
  601. // MARK: - Note
  602. extension KMLeftSideViewController {
  603. public func refreshUIForAddAnnotation(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  604. let need = self._annoList_needRefreshUI(annos: annos)
  605. if need == false {
  606. return
  607. }
  608. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  609. self.note_reloadDataIfNeed()
  610. }
  611. public func refreshUIForAnnoAttributeDidChange(_ anno: CPDFAnnotation?, attributes: [String : Any]?) {
  612. self.updateThumbnail(at: Int(anno?.page?.pageIndex() ?? 0))
  613. let need = self._annoList_needRefreshUI(annos: anno != nil ? [anno!] : [])
  614. if need == false {
  615. return
  616. }
  617. if let data = anno {
  618. self.note_reloadDataForAnnoIfNeed(anno: data)
  619. }
  620. }
  621. public func annoList_refreshUIForDeleteAnnotations(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  622. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  623. if self.type.methodType != .Annotation {
  624. return
  625. }
  626. let need = self._annoList_needRefreshUI(annos: annos)
  627. if need == false {
  628. return
  629. }
  630. for anno in annos ?? [] {
  631. if let model = self.fetchAnnoModel(for: anno) {
  632. self.noteSearchArray.removeObject(model)
  633. self.annoListModel?.datas.removeObject(model)
  634. if self.allAnnotations.contains(anno) {
  635. self.allAnnotations.removeObject(anno)
  636. }
  637. }
  638. }
  639. if self.dataUpdating == false {
  640. self.note_refrshUIIfNeed()
  641. }
  642. }
  643. func note_refrshUIIfNeed() {
  644. if self.type.methodType != .Annotation {
  645. return
  646. }
  647. Task { @MainActor in
  648. self.noteOutlineView.reloadData()
  649. }
  650. }
  651. func note_reloadDataIfNeed() {
  652. if self.type.methodType != .Annotation {
  653. return
  654. }
  655. self.reloadAnnotation()
  656. }
  657. func note_reloadDataForAnnoIfNeed(anno: CPDFAnnotation) {
  658. if self.type.methodType != .Annotation {
  659. return
  660. }
  661. if anno is CPDFLineAnnotation || anno is CPDFSquareAnnotation || anno is CPDFCircleAnnotation || anno is CPDFInkAnnotation {
  662. // 形状注释 + Ink 需要显示框住的内容【刷新】
  663. for item in self.annoListModel?.datas ?? [] {
  664. if anno.isEqual(to: item.anno) {
  665. self.noteOutlineView.reloadItem(item)
  666. break
  667. }
  668. }
  669. } else {
  670. for item in self.annoListModel?.datas ?? [] {
  671. if anno.isEqual(to: item.anno) {
  672. self.noteOutlineView.reloadItem(item)
  673. break
  674. }
  675. }
  676. }
  677. }
  678. func reloadAnnotation() {
  679. if self.listView != nil {
  680. let filterKey = self.pdfDocument()?.documentURL.path ?? ""
  681. let typeArr: [Any] = KMBotaTools.noteFilterAnnoTypes(key: filterKey)
  682. let colorArr: [Any] = KMBotaTools.noteFilterColors(key: filterKey)
  683. let authorArr: [Any] = KMBotaTools.noteFilterAuthors(key: filterKey)
  684. if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
  685. // self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
  686. self.filterButtonLayer?.isHidden = true
  687. } else {
  688. // self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")self.filterButtonLayer?.isHidden = true
  689. self.filterButtonLayer?.isHidden = false
  690. }
  691. var annotationArray: [CPDFAnnotation] = []
  692. var allAnnotation: [CPDFAnnotation] = []
  693. for i in 0 ..< self.pageCount() {
  694. let page = self.pdfDocument()?.page(at: UInt(i))
  695. var annos: [CPDFAnnotation] = []
  696. // 处理过滤
  697. let types = ["Highlight","Underline","Strikeout","Squiggly","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"/*, "table"*/,"Polyline","Polygon"]
  698. if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
  699. annos = KMOCToolClass.filterAnnotation(annotations: page?.annotations ?? [],types: types) as? [CPDFAnnotation] ?? []
  700. annotationArray += annos
  701. } else {
  702. var filterAnnos: [CPDFAnnotation] = page?.annotations ?? []
  703. let allAnnos = KMOCToolClass.filterAnnotation(annotations: filterAnnos,types: types) as? [CPDFAnnotation] ?? []
  704. annotationArray += allAnnos
  705. if typeArr.count > 0 {
  706. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos, types: typeArr) as? [CPDFAnnotation]) ?? []
  707. }
  708. if (colorArr.count > 0) {
  709. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,colors: colorArr) as? [CPDFAnnotation]) ?? []
  710. }
  711. if (authorArr.count > 0) {
  712. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,authors: authorArr) as? [CPDFAnnotation]) ?? []
  713. }
  714. if types.contains("Arrow_Measure") {
  715. } else {
  716. for anno in annos {
  717. if let data = anno as? CPDFLineAnnotation, data.isMeasure {
  718. annos.removeObject(anno)
  719. }
  720. }
  721. }
  722. annos = filterAnnos
  723. }
  724. //添加签名注释
  725. for annotation in page?.annotations ?? [] {
  726. if annotation.isKind(of: CPDFSignatureAnnotation.self) {
  727. annos.append(annotation)
  728. annotationArray.append(annotation)
  729. }
  730. }
  731. for annotation in annos {
  732. if annotation.isKind(of: KMTableAnnotation.self) {
  733. annos.removeObject(annotation)
  734. if annotationArray.contains(annotation) {
  735. annotationArray.removeObject(annotation)
  736. }
  737. } else if annotation.annotationShouldDisplay() == false {
  738. annos.removeObject(annotation)
  739. if annotationArray.contains(annotation) {
  740. annotationArray.removeObject(annotation)
  741. }
  742. } else if annotation.isKind(of: CPDFLinkAnnotation.self) {
  743. annos.removeObject(annotation)
  744. if annotationArray.contains(annotation) {
  745. annotationArray.removeObject(annotation)
  746. }
  747. }
  748. }
  749. // 添加刷选后的注释
  750. allAnnotation += annos
  751. //添加所有annotation 用于筛选
  752. // annotationArray += (page?.annotations ?? [])
  753. // annotationArray += annos
  754. }
  755. // 处理排序
  756. if self.noteSortType == .page {
  757. /// 排序(升序)
  758. if self.isAscendSort {
  759. allAnnotation.sort {
  760. let idx0 = $0.page?.pageIndex() ?? 0
  761. let idx1 = $1.page?.pageIndex() ?? 0
  762. return idx0 <= idx1
  763. }
  764. } else {
  765. allAnnotation.sort {
  766. let idx0 = $0.page?.pageIndex() ?? 0
  767. let idx1 = $1.page?.pageIndex() ?? 0
  768. return idx0 > idx1
  769. }
  770. }
  771. } else if self.noteSortType == .time {
  772. /// 排序(升序)
  773. if self.isAscendSort {
  774. allAnnotation.sort {
  775. if $0.modificationDate() == nil {
  776. return false
  777. }
  778. if $1.modificationDate() == nil {
  779. return false
  780. }
  781. return $0.modificationDate() <= $1.modificationDate()
  782. }
  783. } else {
  784. allAnnotation.sort {
  785. if $0.modificationDate() == nil {
  786. return false
  787. }
  788. if $1.modificationDate() == nil {
  789. return false
  790. }
  791. return $0.modificationDate() > $1.modificationDate()
  792. }
  793. }
  794. }
  795. // 数据模型\化
  796. let model = KMAnnotationListModel()
  797. var datas: [KMBotaAnnotationModel] = []
  798. for anno in allAnnotation {
  799. let item = KMBotaAnnotationModel()
  800. item.anno = anno
  801. item.showPage = self.annoListIsShowPage()
  802. item.showTime = self.annoListIsShowTime()
  803. item.showAuthor = self.annoListIsShowAnther()
  804. datas.append(item)
  805. }
  806. model.datas = datas
  807. self.annoListModel = model
  808. // 转换对象,用于数据显示
  809. self.allAnnotations = annotationArray
  810. self.noteFilterButton.isEnabled = self.allAnnotations.count >= 1
  811. }
  812. self.note_refrshUIIfNeed()
  813. }
  814. func reloadNoteForSearchMode() {
  815. if self.noteSearchMode == false {
  816. return
  817. }
  818. // 处理排序
  819. if self.noteSortType == .page {
  820. if self.isAscendSort { /// 排序(升序)
  821. self.noteSearchArray.sort {
  822. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  823. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  824. return idx0 <= idx1
  825. }
  826. } else {
  827. self.noteSearchArray.sort {
  828. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  829. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  830. return idx0 > idx1
  831. }
  832. }
  833. } else if self.noteSortType == .time {
  834. if self.isAscendSort { /// 排序(升序)
  835. self.noteSearchArray.sort {
  836. if $0.anno?.modificationDate() == nil {
  837. return false
  838. }
  839. if $1.anno?.modificationDate() == nil {
  840. return false
  841. }
  842. return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
  843. }
  844. } else {
  845. self.noteSearchArray.sort {
  846. if $0.anno?.modificationDate() == nil {
  847. return false
  848. }
  849. if $1.anno?.modificationDate() == nil {
  850. return false
  851. }
  852. return $0.anno!.modificationDate() > $1.anno!.modificationDate()
  853. }
  854. }
  855. }
  856. self.note_refrshUIIfNeed()
  857. }
  858. // 搜索 Action
  859. func updateNoteFilterPredicate() {
  860. var stringValue = self.noteSearchField.stringValue
  861. // 清空数据
  862. self.noteSearchArray.removeAll()
  863. if stringValue.isEmpty {
  864. for model in self.annoListModel?.datas ?? [] {
  865. guard let _ = model.anno else {
  866. continue
  867. }
  868. self.noteSearchArray.append(model)
  869. }
  870. } else {
  871. // 忽略大小写
  872. let caseInsensite = self.caseInsensitiveNoteSearch
  873. if caseInsensite {
  874. stringValue = stringValue.lowercased()
  875. }
  876. for model in self.annoListModel?.datas ?? [] {
  877. guard let note = model.anno else {
  878. continue
  879. }
  880. var noteString = ""
  881. if let anno = note as? CPDFMarkupAnnotation {
  882. noteString = anno.markupContent()
  883. } else {
  884. noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
  885. }
  886. if caseInsensite {
  887. noteString = noteString.lowercased()
  888. }
  889. if noteString.contains(stringValue) {
  890. self.noteSearchArray.append(model)
  891. }
  892. }
  893. }
  894. self.note_refrshUIIfNeed()
  895. }
  896. @objc func selectSelectedNote(_ sender: AnyObject?) {
  897. if self.hideNotes() == false {
  898. let selectedNotes = self.selectedNotes()
  899. if selectedNotes.count == 1 {
  900. let annotation = selectedNotes.last!
  901. self.listView?.go(to: annotation.bounds, on: annotation.page, animated: true)
  902. // [pdfView scrollAnnotationToVisible:annotation];
  903. // [pdfView setActiveAnnotation:annotation];
  904. self.listView?.updateActiveAnnotations([annotation])
  905. self.listView?.setNeedsDisplayAnnotationViewForVisiblePages()
  906. if annotation is CPDFPolygonAnnotation || annotation is CPDFPolylineAnnotation {
  907. self.listView?.pdfListViewDelegate.pdfListViewAnnotationMeasureInfoChange?(self.listView, with: annotation)
  908. } else if let anno = annotation as? CPDFLineAnnotation {
  909. if anno.isMeasure {
  910. self.listView?.pdfListViewDelegate.pdfListViewAnnotationMeasureInfoChange?(self.listView, with: annotation)
  911. }
  912. }
  913. // }
  914. }
  915. // NSInteger column = [sender clickedColumn];
  916. // if (column != -1) {
  917. // NSString *colID = [[[sender tableColumns] objectAtIndex:column] identifier];
  918. //
  919. // if ([colID isEqualToString:@"color"]){
  920. // for (PDFAnnotation *annotation in self.pdfView.activeAnnotations) {
  921. // if (![annotation isKindOfClass:[PDFAnnotationChoiceWidget class]] &&
  922. // ![annotation isKindOfClass:[PDFAnnotationButtonWidget class]] &&
  923. // ![annotation isKindOfClass:[PDFAnnotationTextWidget class]]) {
  924. // [[NSColorPanel sharedColorPanel] orderFront:nil];
  925. // break;
  926. // }
  927. //
  928. // }
  929. // }
  930. // }
  931. }
  932. }
  933. func selectedNotes() -> [CPDFAnnotation] {
  934. var selectedNotes: [CPDFAnnotation] = []
  935. let rowIndexes = self.noteOutlineView.selectedRowIndexes
  936. for row in rowIndexes {
  937. let item = self.noteOutlineView.item(atRow: row)
  938. if item is KMBotaAnnotationModel {
  939. if let anno = (item as! KMBotaAnnotationModel).anno {
  940. // if anno.type == nil {
  941. // item = [(SKNoteText *)item note];
  942. // }
  943. if selectedNotes.contains(anno) == false {
  944. selectedNotes.append(anno)
  945. }
  946. }
  947. }
  948. }
  949. return selectedNotes
  950. }
  951. func clearAnnotationFilterData() {
  952. if let _key = self.pdfDocument()?.documentURL?.path {
  953. let userDefaults = UserDefaults.standard
  954. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  955. userDefaults.set(typeData, forKey: NoteFilterVC.filterSelectTypeKey + _key)
  956. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  957. userDefaults.set(colorData, forKey: NoteFilterVC.filterSelectColorKey + _key)
  958. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  959. userDefaults.set(authorData, forKey: NoteFilterVC.filterSelectAuthorKey + _key)
  960. userDefaults.synchronize()
  961. }
  962. }
  963. private func _annoList_needRefreshUI(annos: [CPDFAnnotation]?) -> Bool {
  964. guard let data = annos else {
  965. return false
  966. }
  967. // for anno in data {
  968. // if anno.isKind(of: KMTableAnnotation.self) == false {
  969. // return true
  970. // }
  971. // }
  972. return true
  973. }
  974. }