KMLeftSideViewController+Note.swift 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. noteOutlineView.delegate = self
  20. noteOutlineView.dataSource = self
  21. noteOutlineView.botaDelegate = self
  22. noteOutlineView.botaDataSource = self
  23. noteOutlineView.noteDelegate = self
  24. noteOutlineView.menu = NSMenu()
  25. noteOutlineView.menu?.delegate = self
  26. noteOutlineView.typeSelectHelper = SKTypeSelectHelper(matchOption: .SKSubstringMatch)
  27. noteOutlineView.enclosingScrollView?.scrollerStyle = .legacy
  28. noteOutlineView.enclosingScrollView?.autohidesScrollers = true
  29. noteOutlineView.registerForDraggedTypes(NSColor.readableTypes(for: NSPasteboard(name: .drag)))
  30. noteOutlineView.target = self
  31. noteOutlineView.doubleAction = #selector(selectSelectedNote)
  32. }
  33. func note_initDefalutValue() {
  34. let sud = UserDefaults.standard
  35. if let dict = sud.dictionary(forKey: Self.Key.noteTableColumn) {
  36. self.noteTypeDict = dict
  37. } else {
  38. self.noteTypeDict = [Self.Key.noteFilterPage : false,
  39. Self.Key.noteFilterTime : false,
  40. Self.Key.noteFilterAuther : false]
  41. sud.sync_setValue(self.noteTypeDict, forKey: Self.Key.noteTableColumn)
  42. }
  43. self.caseInsensitiveNoteSearch = sud.bool(forKey: SKCaseInsensitiveNoteSearchKey)
  44. self.isAscendSort = KMDataManager.ud_bool(forKey: Self.Key.noteAscendSortKey)
  45. var sortType = 0
  46. if let data = self.listView?.document?.documentURL.path {
  47. sortType = KMDataManager.udExtension_object(forKey: Self.Key.noteSortTypeKey + data) as? Int ?? 0
  48. }
  49. if (sortType == 1) {
  50. noteSortType = KMNoteSortType(rawValue: sortType) ?? .none
  51. } else {
  52. noteSortType = .page
  53. }
  54. noteOutlineView.autoresizesOutlineColumn = false
  55. noteOutlineView.indentationPerLevel = 0
  56. }
  57. func annoListIsShowPage() -> Bool {
  58. return !(self.noteTypeDict[Self.Key.noteFilterPage] as? Bool ?? false)
  59. }
  60. func annoListIsShowTime() -> Bool {
  61. return !(self.noteTypeDict[Self.Key.noteFilterTime] as? Bool ?? false)
  62. }
  63. func annoListIsShowAnther() -> Bool {
  64. return !(self.noteTypeDict[Self.Key.noteFilterAuther] as? Bool ?? false)
  65. }
  66. }
  67. // MARK: - Menu
  68. extension KMLeftSideViewController {
  69. func annoListMenu(_ menu: NSMenu) {
  70. var item: NSMenuItem?
  71. var items: NSArray?
  72. var rowIndexes = self.noteOutlineView.selectedRowIndexes
  73. let row = self.noteOutlineView.clickedRow
  74. if row == -1 {
  75. _ = self._addDeleteAllAnnoItem(menu)
  76. return
  77. }
  78. if rowIndexes.contains(row) == false {
  79. rowIndexes = IndexSet(integer: row)
  80. }
  81. items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
  82. guard let model = self.fetchAnnoModel(for: row) else {
  83. return
  84. }
  85. let isFold = model.isFold()
  86. item = menu.addItem(title: KMLocalizedString("Expand"), action: #selector(unfoldNoteAction), target: self)
  87. item?.state = isFold ? .off : .on
  88. item?.representedObject = items
  89. item = menu.addItem(title: KMLocalizedString("Collapse"), action: #selector(foldNoteAction), target: self)
  90. item?.state = isFold ? .on : .off
  91. item?.representedObject = items
  92. menu.addItem(.separator())
  93. let hideNotes = self.hideNotes()
  94. if hideNotes == false && (items?.count ?? 0) == 1 {
  95. }
  96. if menu.numberOfItems > 0 {
  97. if self.outlineView(self.noteOutlineView, canDeleteItems: items as? [Any] ?? []) {
  98. item = menu.addItem(title: KMLocalizedString("Delete", comment: "Menu item title"), action: #selector(deleteNotes), target: self)
  99. item?.representedObject = items
  100. }
  101. _ = self._addDeleteAllAnnoItem(menu)
  102. }
  103. }
  104. private func _addExportPDFMenu(_ menu: NSMenu) -> NSMenu {
  105. var item = menu.addItem(title: KMLocalizedString("Export Annotations…"), action: nil, target: self)
  106. let subMenu = NSMenu()
  107. item?.submenu = subMenu
  108. item = subMenu.addItem(title: KMLocalizedString("PDF", comment: ""), action: #selector(exportAnnotationNotes), target: self)
  109. item?.tag = 0
  110. item = subMenu.addItem(title: KMLocalizedString("PDF Bundle"), action: #selector(exportAnnotationNotes), target: self)
  111. item?.tag = 1
  112. item = subMenu.addItem(title: KMLocalizedString("PDF Reader Pro Edition Notes"), action: #selector(exportAnnotationNotes), target: self)
  113. item?.tag = 2
  114. item = subMenu.addItem(title: KMLocalizedString("Notes as Text"), action: #selector(exportAnnotationNotes), target: self)
  115. item?.tag = 3
  116. item = subMenu.addItem(title: KMLocalizedString("Notes as RTF"), action: #selector(exportAnnotationNotes), target: self)
  117. item?.tag = 4
  118. item = subMenu.addItem(title: KMLocalizedString("Notes as RTFD"), action: #selector(exportAnnotationNotes), target: self)
  119. item?.tag = 5
  120. item = subMenu.addItem(title: KMLocalizedString("Notes as FDF"), action: #selector(exportAnnotationNotes), target: self)
  121. item?.tag = 6
  122. return menu
  123. }
  124. private func _addDeleteAllAnnoItem(_ menu: NSMenu) -> NSMenuItem? {
  125. return menu.addItem(title: KMLocalizedString("Remove All Annotations"), action: #selector(removeAllAnnotations), target: self)
  126. }
  127. private func _addDeleteAllReplyAnnoItem(_ menu: NSMenu) -> NSMenuItem? {
  128. return menu.addItem(title: KMLocalizedString("Delete All Reply"), action: #selector(removeAllReplyAnnotations), target: self)
  129. }
  130. @IBAction func note_expandAllComments(_ sender: AnyObject?) {
  131. guard let model = self.annoListModel else {
  132. return
  133. }
  134. for secM in self.annoListModel?.datas ?? [] {
  135. secM.isExpand = true
  136. }
  137. noteOutlineView.reloadData()
  138. }
  139. @IBAction func note_foldAllComments(_ sender: AnyObject?) {
  140. guard let model = self.annoListModel else {
  141. return
  142. }
  143. for secM in self.annoListModel?.datas ?? [] {
  144. secM.isExpand = false
  145. }
  146. self.noteOutlineView.reloadData()
  147. }
  148. @IBAction func noteShowNoteAction(_ sender: AnyObject?) {
  149. let item = sender as? NSMenuItem
  150. let tag = item?.tag ?? 0
  151. if (tag == 100) {
  152. } else if (tag == 101) {
  153. let isPage = !self.annoListIsShowPage()
  154. self.noteTypeDict[Self.Key.noteFilterPage] = !isPage
  155. } else if (tag == 102) {
  156. let isTime = !self.annoListIsShowTime()
  157. self.noteTypeDict[Self.Key.noteFilterTime] = !isTime
  158. } else if (tag == 103) {
  159. let isAuther = !self.annoListIsShowAnther()
  160. self.noteTypeDict[Self.Key.noteFilterAuther] = !isAuther
  161. }
  162. UserDefaults.standard.sync_setValue(self.noteTypeDict, forKey: Self.Key.noteTableColumn)
  163. // 更新数据
  164. var models: [KMBotaAnnotationModel] = []
  165. if self.noteSearchMode {
  166. for model in self.noteSearchArray {
  167. guard let data = model as? KMBotaAnnotationModel else {
  168. continue
  169. }
  170. models.append(data)
  171. }
  172. } else {
  173. let selModels = self.annoListModel?.datas ?? []
  174. for selModel in selModels {
  175. for item in selModel.items {
  176. if let data = item as? KMBotaAnnotationModel {
  177. models.append(data)
  178. }
  179. }
  180. }
  181. }
  182. for model in models {
  183. model.showPage = self.annoListIsShowPage()
  184. model.showTime = self.annoListIsShowTime()
  185. model.showAuthor = self.annoListIsShowAnther()
  186. }
  187. let selectRow = self.noteOutlineView.selectedRow
  188. self.noteOutlineView.reloadData()
  189. self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
  190. }
  191. @objc func importNotes(_ sender: NSMenuItem?) {
  192. let panel = NSOpenPanel()
  193. panel.allowedFileTypes = ["xfdf"]
  194. panel.allowsMultipleSelection = false
  195. panel.beginSheetModal(for: self.view.window!) { resp in
  196. if resp != .OK {
  197. return
  198. }
  199. if let result = self.pdfDocument()?.importAnnotation(fromXFDFPath: panel.url?.path), result {
  200. self.reloadAnnotation()
  201. self.listView?.setNeedsDisplayForVisiblePages()
  202. }
  203. }
  204. }
  205. @objc func exportNotes(_ sender: NSMenuItem?) {
  206. guard let cnt = self.listView?.notes?.count, cnt > 0 else {
  207. NSSound.beep()
  208. return
  209. }
  210. let fileName = "\(self.pdfDocument()?.documentURL.deletingPathExtension().lastPathComponent ?? "")" + "_xfdf"
  211. let panel = NSSavePanel()
  212. panel.directoryURL = self.pdfDocument()?.documentURL.deletingLastPathComponent()
  213. panel.allowedFileTypes = ["xfdf"]
  214. panel.nameFieldStringValue = fileName
  215. panel.beginSheetModal(for: self.view.window!) { resp in
  216. if resp != .OK {
  217. return
  218. }
  219. let filePath = panel.url?.path
  220. if let success = self.pdfDocument()?.exportAnnotation(toXFDFPath: filePath), success {
  221. NSWorkspace.shared.selectFile(filePath, inFileViewerRootedAtPath: "")
  222. } else {
  223. Task {
  224. _ = await KMAlertTool.runModel(message: KMLocalizedString("Export Failure!"), buttons: [KMLocalizedString("OK")])
  225. }
  226. }
  227. }
  228. }
  229. @objc func exportAnnotationNotes(_ sender: AnyObject?) {
  230. let doc = self.view.window?.windowController?.document as? NSDocument
  231. doc?.saveTo(sender)
  232. }
  233. // 展开
  234. @objc func unfoldNoteAction(_ sender: NSMenuItem) {
  235. if sender.state == .on {
  236. return
  237. }
  238. let row = self.noteOutlineView.clickedRow
  239. guard let model = self.fetchAnnoModel(for: row) else {
  240. return
  241. }
  242. model.foldType = .unfold
  243. model.isExpand = true
  244. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
  245. (viewS as? KMNoteTableViewCell)?.isFold = false
  246. model.footerModel?.isExpand = true
  247. // self.noteOutlineView.reloadItem(model.footerModel)
  248. self.noteOutlineView.reloadData()
  249. }
  250. @objc func foldNoteAction(_ sender: NSMenuItem) {
  251. if sender.state == .on {
  252. return
  253. }
  254. let row = self.noteOutlineView.clickedRow
  255. guard let model = self.fetchAnnoModel(for: row) else {
  256. return
  257. }
  258. model.foldType = .fold
  259. model.isExpand = false
  260. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
  261. (viewS as? KMNoteTableViewCell)?.isFold = true
  262. model.footerModel?.isExpand = false
  263. // self.noteOutlineView.reloadItem(model.footerModel)
  264. self.noteOutlineView.reloadData()
  265. }
  266. @objc func deleteNotes(_ sender: NSMenuItem) {
  267. self.outlineView(self.noteOutlineView, deleteItems: sender.representedObject as? [Any] ?? [])
  268. }
  269. @objc func removeAllAnnotations(_ sender: AnyObject?) {
  270. guard let doc = self.pdfDocument() else {
  271. return
  272. }
  273. Task {
  274. let response = await KMAlertTool.runModel(message: KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?"), buttons: [KMLocalizedString("Yes"), KMLocalizedString("No")])
  275. if response == .alertFirstButtonReturn {
  276. self.dataUpdating = true
  277. for model in self.annoListModel?.datas ?? [] {
  278. for item in model.items {
  279. if let anno = item.anno {
  280. if let data = anno as? CPDFFreeTextAnnotation {
  281. self.listView?.commitEditAnnotationFreeText(data)
  282. }
  283. self.listView?.remove(anno)
  284. }
  285. }
  286. }
  287. self.annoListModel?.datas.removeAll()
  288. self.dataUpdating = false
  289. self.note_refrshUIIfNeed()
  290. }
  291. }
  292. }
  293. @objc func removeAllReplyAnnotations(_ sender: NSMenuItem?) {
  294. Task {
  295. let response = await KMAlertTool.runModel(message: KMLocalizedString("Are you sure to delete all comment replies?"), buttons: [KMLocalizedString("Yes"), KMLocalizedString("No")])
  296. if response == .alertFirstButtonReturn {
  297. self.dataUpdating = true
  298. var hasAnno = false
  299. for model in self.annoListModel?.datas ?? [] {
  300. for item in model.items {
  301. guard let annoM = item as? KMBotaAnnotationModel else {
  302. continue
  303. }
  304. for replyM in annoM.replyAnnos {
  305. replyM.replyAnno?.page.removeAnnotation(replyM.replyAnno)
  306. hasAnno = true
  307. }
  308. annoM.replyAnnos.removeAll()
  309. }
  310. }
  311. self.dataUpdating = false
  312. self.note_refrshUIIfNeed()
  313. if let data = self.view.window, hasAnno {
  314. KMTools.setDocumentEditedState(window: data)
  315. }
  316. }
  317. }
  318. }
  319. @objc func editNoteTextFromTable(_ sender: NSMenuItem) {
  320. guard let annotation = sender.representedObject as? CPDFAnnotation else {
  321. return
  322. }
  323. self.listView?.scrollAnnotationToVisible(annotation)
  324. }
  325. @objc func editThisAnnotation(_ sender: AnyObject?) {
  326. guard let annotation = (sender as? NSMenuItem)?.representedObject as? CPDFAnnotation else {
  327. NSSound.beep()
  328. return
  329. }
  330. self.listView?.edit(annotation)
  331. }
  332. @objc func editNoteFromTable(_ sender: AnyObject?) {
  333. guard let annotation = (sender as? NSMenuItem)?.representedObject as? CPDFAnnotation else {
  334. NSSound.beep()
  335. return
  336. }
  337. let model = fetchAnnoModel(for: annotation)
  338. let row = self.noteOutlineView.row(forItem: model)
  339. self.noteOutlineView.km_safe_selectRowIndexes(.init(integer: row), byExtendingSelection: false)
  340. let noteIndex = self.noteOutlineView.column(withIdentifier: .init("note"))
  341. if (noteIndex >= 0) {
  342. self.noteOutlineView.scrollColumnToVisible(noteIndex)
  343. //
  344. self.isRenameNoteOutline = true
  345. let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true) as? KMNoteTableViewCell
  346. viewS!.isFold = false
  347. let targrtTextField = viewS?.noteContentLabel
  348. self.editNoteTextField = targrtTextField
  349. self.editNote = annotation
  350. targrtTextField?.delegate = self
  351. targrtTextField?.isEditable = true
  352. targrtTextField?.becomeFirstResponder()
  353. }
  354. }
  355. @IBAction func noteSortAction(_ sender: AnyObject?) {
  356. // if (self.isAscendSort) {
  357. // self.isAscendSort = false
  358. // self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  359. // self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  360. // } else {
  361. // self.isAscendSort = true
  362. // self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  363. // self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  364. // }
  365. KMDataManager.ud_set(self.isAscendSort, forKey: Self.Key.noteAscendSortKey)
  366. if self.noteSearchMode {
  367. reloadNoteForSearchMode()
  368. } else {
  369. reloadNoteForSortMode()
  370. }
  371. }
  372. @IBAction func noteSearchAction(_ sender: NSButton) {
  373. // self.noteTitleLabel.isHidden = true
  374. // self.noteSearchButton.isHidden = true
  375. // self.noteDoneButton.isHidden = false
  376. // self.noteFilterButton.isHidden = true
  377. // self.noteMoreButton.isHidden = true
  378. self.noteFilterButtonHoverView.isHidden = true
  379. }
  380. @IBAction func noteFilterAction(_ sender: AnyObject?) {
  381. let button = sender as? NSButton
  382. if self.noteFilterSelected == false {
  383. }
  384. let menu = NSMenu()
  385. self.noteFilterMenu = menu
  386. let filterViewController = KMNoteOutlineFilterViewController()
  387. filterViewController.listView = self.listView
  388. filterViewController.view.layer?.backgroundColor = .clear
  389. var states: [CPDFAnnotationState] = []
  390. for anno in self.allAnnotations {
  391. if let reviewS = self.noteReplyHanddler.fetchReviewState(anno) {
  392. if states.contains(reviewS) == false {
  393. states.append(reviewS)
  394. }
  395. } else {
  396. if states.contains(.none) == false {
  397. states.append(.none)
  398. }
  399. }
  400. if let markS = self.noteReplyHanddler.fetchAnnoState(anno) {
  401. if states.contains(markS) == false {
  402. states.append(markS)
  403. }
  404. } else {
  405. if states.contains(.unMarked) == false {
  406. states.append(.unMarked)
  407. }
  408. }
  409. }
  410. filterViewController.updateStates(states: states)
  411. filterViewController.setNotesArray(self.allAnnotations as NSArray)
  412. filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
  413. menu.cancelTracking()
  414. self?.headerView.sortButton.properties.state = .normal
  415. self?.headerView.sortButton.reloadData()
  416. self?.reloadAnnotation()
  417. }
  418. filterViewController.cancelCallback = {[weak self] isCancel in
  419. if (isCancel) {
  420. self?.headerView.sortButton.properties.state = .normal
  421. self?.headerView.sortButton.reloadData()
  422. menu.cancelTracking()
  423. }
  424. }
  425. let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
  426. item.target = self
  427. item.representedObject = filterViewController
  428. item.view = filterViewController.view
  429. menu.delegate = self
  430. menu.popUp(positioning: nil, at: NSMakePoint(-130, 30), in: self.headerView.sortButton)
  431. }
  432. func fetchNote(for index: Int) -> CPDFAnnotation? {
  433. return self.fetchAnnoModel(for: index)?.anno
  434. }
  435. func fetchAnnoModel(for index: Int) -> KMBotaAnnotationModel? {
  436. if self.noteSearchMode { // 搜索模式
  437. return self.noteSearchArray.safe_element(for: index) as? KMBotaAnnotationModel
  438. } else { // 常规模式(非搜索)
  439. // let model = self.annoListModel?.datas.safe_element(for: index)
  440. let model = self.noteOutlineView.item(atRow: index)
  441. if let data = model as? KMBotaAnnotationSectionModel {
  442. return nil
  443. }
  444. if let data = model as? KMBotaAnnotationModel {
  445. return data
  446. }
  447. if let data = model as? KMBotaAnnotationFooterModel {
  448. }
  449. if let data = model as? KMBotaAnnotationReplyModel {
  450. }
  451. return nil
  452. }
  453. }
  454. func fetchAnnoModel(for anno: CPDFAnnotation) -> KMBotaAnnotationModel? {
  455. if self.noteSearchMode { // 搜索模式
  456. for model in self.noteSearchArray {
  457. guard let data = model as? KMBotaAnnotationModel else {
  458. continue
  459. }
  460. if anno.isEqual(to: data.anno) {
  461. return data
  462. }
  463. }
  464. } else { // 常规模式(非搜索)
  465. for model in self.annoListModel?.datas ?? [] {
  466. for item in model.items {
  467. if let data = item as? KMBotaAnnotationModel {
  468. if anno.isEqual(to: data.anno) {
  469. return data
  470. }
  471. }
  472. }
  473. }
  474. }
  475. return nil
  476. }
  477. func showNoteEmptyView() {
  478. self.emptyView.isHidden = false
  479. }
  480. func hideNoteEmptyView() {
  481. self.emptyView.isHidden = true
  482. }
  483. }
  484. // MARK: - Note
  485. extension KMLeftSideViewController {
  486. public func refreshUIForAddAnnotation(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  487. let need = self._annoList_needRefreshUI(annos: annos)
  488. if need == false {
  489. return
  490. }
  491. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  492. self.note_reloadDataIfNeed()
  493. }
  494. public func refreshUIForAnnoAttributeDidChange(_ anno: CPDFAnnotation?, attributes: [String : Any]?) {
  495. self.updateThumbnail(at: Int(anno?.page?.pageIndex() ?? 0))
  496. let need = self._annoList_needRefreshUI(annos: anno != nil ? [anno!] : [])
  497. if need == false {
  498. return
  499. }
  500. if let data = anno {
  501. self.note_reloadDataForAnnoIfNeed(anno: data)
  502. }
  503. }
  504. public func annoList_refreshUIForDeleteAnnotations(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  505. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  506. let need = self._annoList_needRefreshUI(annos: annos)
  507. if need == false {
  508. return
  509. }
  510. for anno in annos ?? [] {
  511. if let model = self.fetchAnnoModel(for: anno) {
  512. self.noteSearchArray.removeObject(model)
  513. model.sectionModel?.items.removeObject(model)
  514. if let footer = model.footerModel {
  515. model.sectionModel?.items.removeObject(footer)
  516. }
  517. if let cnt = model.sectionModel?.items.count, cnt == 0 {
  518. self.annoListModel?.datas.removeObject(model.sectionModel!)
  519. }
  520. if self.allAnnotations.contains(anno) {
  521. self.allAnnotations.removeObject(anno)
  522. }
  523. }
  524. }
  525. if self.dataUpdating == false {
  526. self.note_refrshUIIfNeed()
  527. }
  528. }
  529. func note_refrshUIIfNeed() {
  530. Task { @MainActor in
  531. self.noteOutlineView?.reloadData()
  532. }
  533. }
  534. func note_reloadDataIfNeed() {
  535. self.reloadAnnotation()
  536. }
  537. func note_reloadDataForAnnoIfNeed(anno: CPDFAnnotation) {
  538. if anno is CPDFLineAnnotation ||
  539. anno is CPDFSquareAnnotation ||
  540. anno is CPDFCircleAnnotation ||
  541. anno is CPDFInkAnnotation {
  542. // 形状注释 + Ink 需要显示框住的内容【刷新】
  543. for item in self.annoListModel?.datas ?? [] {
  544. for itemM in item.items {
  545. if anno.isEqual(to: itemM.anno) {
  546. self.noteOutlineView.reloadItem(itemM)
  547. break
  548. }
  549. }
  550. }
  551. } else {
  552. for item in self.annoListModel?.datas ?? [] {
  553. for itemM in item.items {
  554. if anno.isEqual(to: itemM.anno) {
  555. self.noteOutlineView.reloadItem(itemM)
  556. break
  557. }
  558. }
  559. }
  560. }
  561. }
  562. func reloadAnnotation() {
  563. if self.listView != nil {
  564. let filterKey = self.pdfDocument()?.documentURL.path ?? ""
  565. let typeArr: [String] = KMBotaTools.noteFilterAnnoTypes(key: filterKey)
  566. let colorArr: [Any] = KMBotaTools.noteFilterColors(key: filterKey)
  567. let authorArr: [Any] = KMBotaTools.noteFilterAuthors(key: filterKey)
  568. var stateArr: [NSNumber] = KMBotaTools.noteFilterStates(key: filterKey)
  569. var hasMark = false
  570. var hasReview = false
  571. for data in stateArr {
  572. let state = data.intValue
  573. if state == CPDFAnnotationState.marked.rawValue || state == CPDFAnnotationState.unMarked.rawValue {
  574. hasMark = true
  575. }
  576. if state == CPDFAnnotationState.none.rawValue || state == CPDFAnnotationState.accepted.rawValue || state == CPDFAnnotationState.rejected.rawValue || state == CPDFAnnotationState.canceled.rawValue || state == CPDFAnnotationState.completed.rawValue {
  577. hasReview = true
  578. }
  579. }
  580. if hasMark == false {
  581. stateArr.append(NSNumber(value: CPDFAnnotationState.marked.rawValue))
  582. stateArr.append(NSNumber(value: CPDFAnnotationState.unMarked.rawValue))
  583. }
  584. if hasReview == false {
  585. stateArr.append(NSNumber(value: CPDFAnnotationState.none.rawValue))
  586. stateArr.append(NSNumber(value: CPDFAnnotationState.accepted.rawValue))
  587. stateArr.append(NSNumber(value: CPDFAnnotationState.rejected.rawValue))
  588. stateArr.append(NSNumber(value: CPDFAnnotationState.canceled.rawValue))
  589. stateArr.append(NSNumber(value: CPDFAnnotationState.completed.rawValue))
  590. }
  591. var annotationArray: [CPDFAnnotation] = []
  592. var allAnnotation: [CPDFAnnotation] = []
  593. for i in 0 ..< self.pageCount() {
  594. let page = self.pdfDocument()?.page(at: UInt(i))
  595. var annos: [CPDFAnnotation] = []
  596. // 处理过滤
  597. let types = ["Highlight","Underline","Strikeout","Squiggly","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Sign"/*, "table"*/,"Polyline","Polygon"]
  598. if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 && stateArr.count == 0 {
  599. annos = KMOCToolClass.filterAnnotation(annotations: page?.annotations ?? [],types: types) as? [CPDFAnnotation] ?? []
  600. annotationArray += annos
  601. } else {
  602. var filterAnnos: [CPDFAnnotation] = page?.annotations ?? []
  603. let allAnnos = KMOCToolClass.filterAnnotation(annotations: filterAnnos,types: types) as? [CPDFAnnotation] ?? []
  604. annotationArray += allAnnos
  605. if typeArr.count > 0 {
  606. var theTypes = typeArr
  607. if typeArr.contains("Measure") { //包含测量的话
  608. theTypes.append("Polygon")
  609. theTypes.append("Polyline")
  610. theTypes.append(CPDFAnnotation.kType.measureArrow)
  611. }
  612. if theTypes.contains(CPDFAnnotation.kType.measureArrow) && theTypes.contains(CPDFAnnotation.kType.arrow) == false {
  613. theTypes.append(CPDFAnnotation.kType.arrow)
  614. }
  615. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos, types: theTypes) as? [CPDFAnnotation]) ?? []
  616. }
  617. if (colorArr.count > 0) {
  618. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,colors: colorArr) as? [CPDFAnnotation]) ?? []
  619. }
  620. if (authorArr.count > 0) {
  621. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,authors: authorArr) as? [CPDFAnnotation]) ?? []
  622. }
  623. if typeArr.isEmpty == false {
  624. if typeArr.contains("Measure") {
  625. if typeArr.contains(CPDFAnnotation.kType.arrow) == false {
  626. for anno in filterAnnos {
  627. if let data = anno as? CPDFLineAnnotation, data.type == CPDFAnnotation.kType.arrow && data.isMeasure == false {
  628. filterAnnos.removeObject(anno)
  629. }
  630. }
  631. }
  632. } else {
  633. for anno in filterAnnos {
  634. if let data = anno as? CPDFLineAnnotation, data.isMeasure {
  635. filterAnnos.removeObject(anno)
  636. }
  637. }
  638. }
  639. }
  640. if stateArr.count > 0 {
  641. for anno in filterAnnos {
  642. let markState = self.noteReplyHanddler.fetchAnnoState(anno) ?? .unMarked
  643. let reviewState = self.noteReplyHanddler.fetchReviewState(anno) ?? .none
  644. if stateArr.contains(NSNumber(value: markState.rawValue)) == false || stateArr.contains(NSNumber(value: reviewState.rawValue)) == false {
  645. filterAnnos.removeObject(anno)
  646. }
  647. }
  648. }
  649. annos = filterAnnos
  650. }
  651. //添加签名注释
  652. for annotation in page?.annotations ?? [] {
  653. if annotation.isKind(of: CPDFSignatureAnnotation.self) {
  654. annos.append(annotation)
  655. annotationArray.append(annotation)
  656. }
  657. }
  658. for annotation in annos {
  659. if annotation.isKind(of: KMTableAnnotation.self) {
  660. annos.removeObject(annotation)
  661. if annotationArray.contains(annotation) {
  662. annotationArray.removeObject(annotation)
  663. }
  664. } else if annotation.annotationShouldDisplay() == false {
  665. annos.removeObject(annotation)
  666. if annotationArray.contains(annotation) {
  667. annotationArray.removeObject(annotation)
  668. }
  669. } else if annotation.isKind(of: CPDFLinkAnnotation.self) {
  670. annos.removeObject(annotation)
  671. if annotationArray.contains(annotation) {
  672. annotationArray.removeObject(annotation)
  673. }
  674. } else if annotation.isKind(of: CPDFRedactAnnotation.self) {
  675. annos.removeObject(annotation)
  676. if annotationArray.contains(annotation) {
  677. annotationArray.removeObject(annotation)
  678. }
  679. } else if annotation.isForm() {
  680. annos.removeObject(annotation)
  681. if annotationArray.contains(annotation) {
  682. annotationArray.removeObject(annotation)
  683. }
  684. }
  685. }
  686. // 添加刷选后的注释
  687. allAnnotation += annos
  688. }
  689. // 处理排序
  690. if self.noteSortType == .page {
  691. /// 排序(升序)
  692. if self.isAscendSort {
  693. allAnnotation.sort {
  694. let idx0 = $0.page?.pageIndex() ?? 0
  695. let idx1 = $1.page?.pageIndex() ?? 0
  696. return idx0 <= idx1
  697. }
  698. } else {
  699. allAnnotation.sort {
  700. let idx0 = $0.page?.pageIndex() ?? 0
  701. let idx1 = $1.page?.pageIndex() ?? 0
  702. return idx0 > idx1
  703. }
  704. }
  705. } else if self.noteSortType == .time {
  706. /// 排序(升序)
  707. if self.isAscendSort {
  708. allAnnotation.sort {
  709. if $0.modificationDate() == nil {
  710. return false
  711. }
  712. if $1.modificationDate() == nil {
  713. return false
  714. }
  715. return $0.modificationDate() <= $1.modificationDate()
  716. }
  717. } else {
  718. allAnnotation.sort {
  719. if $0.modificationDate() == nil {
  720. return false
  721. }
  722. if $1.modificationDate() == nil {
  723. return false
  724. }
  725. return $0.modificationDate() > $1.modificationDate()
  726. }
  727. }
  728. }
  729. // 数据模型化
  730. let model = KMAnnotationListModel()
  731. var datas: [KMBotaAnnotationModel] = []
  732. var prePageIdx: Int = NSNotFound
  733. var preDate: Date?
  734. var secM: KMBotaAnnotationSectionModel?
  735. for anno in allAnnotation {
  736. let item = KMBotaAnnotationModel()
  737. item.anno = anno
  738. item.showPage = self.annoListIsShowPage()
  739. item.showTime = self.annoListIsShowTime()
  740. item.showAuthor = self.annoListIsShowAnther()
  741. if self.noteSortType == .page {
  742. let pageIdx = Int(anno.pageIndex())
  743. if pageIdx != prePageIdx { // 不是同一个页面
  744. secM = KMBotaAnnotationSectionModel()
  745. model.datas.append(secM!)
  746. }
  747. secM?.items.append(item)
  748. prePageIdx = Int(anno.pageIndex())
  749. } else { // time
  750. let date = anno.modificationDate()
  751. if let same = date?.isSameDay(other: preDate), same == false { // 不是同一天
  752. secM = KMBotaAnnotationSectionModel()
  753. model.datas.append(secM!)
  754. }
  755. secM?.items.append(item)
  756. preDate = date
  757. }
  758. item.sectionModel = secM
  759. let replyAnnos = self.noteReplyHanddler.fetchReplyAnnotations(anno) ?? []
  760. for replyAnno in replyAnnos {
  761. let replyM = KMBotaAnnotationReplyModel()
  762. replyM.anno = anno
  763. replyM.replyAnno = replyAnno
  764. // secM?.items.append(replyM)
  765. replyM.annoModel = item
  766. item.replyAnnos.append(replyM)
  767. }
  768. let footerI = KMBotaAnnotationFooterModel()
  769. footerI.anno = anno
  770. secM?.items.append(footerI)
  771. item.footerModel = footerI
  772. footerI.annoModel = item
  773. }
  774. // model.datas = datas
  775. self.annoListModel = model
  776. // 转换对象,用于数据显示
  777. self.allAnnotations = annotationArray
  778. // self.noteFilterButton.isEnabled = self.allAnnotations.count >= 1
  779. }
  780. self.note_refrshUIIfNeed()
  781. }
  782. func reloadNoteForSearchMode() {
  783. if self.noteSearchMode == false {
  784. return
  785. }
  786. // 处理排序
  787. if self.noteSortType == .page {
  788. if self.isAscendSort { /// 排序(升序)
  789. self.noteSearchArray.sort {
  790. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  791. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  792. return idx0 <= idx1
  793. }
  794. } else {
  795. self.noteSearchArray.sort {
  796. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  797. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  798. return idx0 > idx1
  799. }
  800. }
  801. } else if self.noteSortType == .time {
  802. if self.isAscendSort { /// 排序(升序)
  803. self.noteSearchArray.sort {
  804. if $0.anno?.modificationDate() == nil {
  805. return false
  806. }
  807. if $1.anno?.modificationDate() == nil {
  808. return false
  809. }
  810. return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
  811. }
  812. } else {
  813. self.noteSearchArray.sort {
  814. if $0.anno?.modificationDate() == nil {
  815. return false
  816. }
  817. if $1.anno?.modificationDate() == nil {
  818. return false
  819. }
  820. return $0.anno!.modificationDate() > $1.anno!.modificationDate()
  821. }
  822. }
  823. }
  824. self.note_refrshUIIfNeed()
  825. }
  826. func reloadNoteForSortMode() {
  827. // 处理排序
  828. var models: [KMBotaAnnotationModel] = []
  829. for selM in self.annoListModel?.datas ?? [] {
  830. for model in selM.items {
  831. guard let annoModel = model as? KMBotaAnnotationModel else {
  832. continue
  833. }
  834. models.append(annoModel)
  835. }
  836. }
  837. if self.noteSortType == .page {
  838. if self.isAscendSort { /// 排序(升序)
  839. models.sort {
  840. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  841. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  842. return idx0 <= idx1
  843. }
  844. } else {
  845. models.sort {
  846. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  847. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  848. return idx0 > idx1
  849. }
  850. }
  851. } else if self.noteSortType == .time {
  852. if self.isAscendSort { /// 排序(升序)
  853. models.sort {
  854. if $0.anno?.modificationDate() == nil {
  855. return false
  856. }
  857. if $1.anno?.modificationDate() == nil {
  858. return false
  859. }
  860. return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
  861. }
  862. } else {
  863. models.sort {
  864. if $0.anno?.modificationDate() == nil {
  865. return false
  866. }
  867. if $1.anno?.modificationDate() == nil {
  868. return false
  869. }
  870. return $0.anno!.modificationDate() > $1.anno!.modificationDate()
  871. }
  872. }
  873. }
  874. // 数据模型\化
  875. let listModel = KMAnnotationListModel()
  876. var prePageIdx: Int = NSNotFound
  877. var preDate: Date?
  878. var secM: KMBotaAnnotationSectionModel?
  879. for itemM in models {
  880. guard let anno = itemM.anno else {
  881. continue
  882. }
  883. if self.noteSortType == .page {
  884. let pageIdx = Int(anno.pageIndex())
  885. if pageIdx != prePageIdx { // 不是同一个页面
  886. secM = KMBotaAnnotationSectionModel()
  887. listModel.datas.append(secM!)
  888. secM?.isExpand = itemM.sectionModel?.isExpand ?? true
  889. }
  890. secM?.items.append(itemM)
  891. prePageIdx = Int(anno.pageIndex())
  892. } else { // time
  893. let date = anno.modificationDate()
  894. if let same = date?.isSameDay(other: preDate), same == false { // 不是同一天
  895. secM = KMBotaAnnotationSectionModel()
  896. listModel.datas.append(secM!)
  897. secM?.isExpand = itemM.sectionModel?.isExpand ?? true
  898. }
  899. secM?.items.append(itemM)
  900. preDate = date
  901. }
  902. var tmpSelM = itemM.sectionModel
  903. itemM.sectionModel = secM
  904. let footerI = KMBotaAnnotationFooterModel()
  905. footerI.anno = anno
  906. secM?.items.append(footerI)
  907. footerI.isExpand = itemM.footerModel?.isExpand ?? false
  908. itemM.footerModel = footerI
  909. footerI.annoModel = itemM
  910. }
  911. self.annoListModel = listModel
  912. self.note_refrshUIIfNeed()
  913. }
  914. // 搜索 Action
  915. func updateNoteFilterPredicate(searchString: String) {
  916. var stringValue = searchString
  917. // 清空数据
  918. self.noteSearchArray.removeAll()
  919. if stringValue.isEmpty {
  920. for model in self.annoListModel?.datas ?? [] {
  921. for item in model.items {
  922. guard let _ = item.anno else {
  923. continue
  924. }
  925. guard let data = item as? KMBotaAnnotationModel else {
  926. continue
  927. }
  928. self.noteSearchArray.append(item)
  929. }
  930. }
  931. } else {
  932. // 忽略大小写
  933. let caseInsensite = self.caseInsensitiveNoteSearch
  934. if caseInsensite {
  935. stringValue = stringValue.lowercased()
  936. }
  937. for model in self.annoListModel?.datas ?? [] {
  938. for item in model.items {
  939. guard let note = item.anno else {
  940. continue
  941. }
  942. var noteString = ""
  943. if let anno = note as? CPDFMarkupAnnotation {
  944. noteString = anno.markupContent()
  945. } else {
  946. noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
  947. }
  948. if caseInsensite {
  949. noteString = noteString.lowercased()
  950. }
  951. guard let data = item as? KMBotaAnnotationModel else {
  952. continue
  953. }
  954. if noteString.contains(stringValue) {
  955. self.noteSearchArray.append(item)
  956. }
  957. }
  958. }
  959. }
  960. self.note_refrshUIIfNeed()
  961. }
  962. @objc func selectSelectedNote(_ sender: AnyObject?) {
  963. if self.hideNotes() == false {
  964. let selectedNotes = self.selectedNotes()
  965. if selectedNotes.count == 1 {
  966. let annotation = selectedNotes.last!
  967. self.listView?.go(to: annotation.bounds, on: annotation.page, animated: true)
  968. self.listView?.updateActiveAnnotations([annotation])
  969. self.listView?.setNeedsDisplayAnnotationViewForVisiblePages()
  970. if annotation is CPDFPolygonAnnotation || annotation is CPDFPolylineAnnotation {
  971. self.listView?.pdfListViewDelegate.pdfListViewAnnotationMeasureInfoChange?(self.listView, with: annotation)
  972. } else if let anno = annotation as? CPDFLineAnnotation {
  973. if anno.isMeasure {
  974. self.listView?.pdfListViewDelegate.pdfListViewAnnotationMeasureInfoChange?(self.listView, with: annotation)
  975. }
  976. }
  977. }
  978. }
  979. }
  980. func selectedNotes() -> [CPDFAnnotation] {
  981. var selectedNotes: [CPDFAnnotation] = []
  982. let rowIndexes = self.noteOutlineView.selectedRowIndexes
  983. for row in rowIndexes {
  984. let item = self.noteOutlineView.item(atRow: row)
  985. if item is KMBotaAnnotationModel {
  986. if let anno = (item as! KMBotaAnnotationModel).anno {
  987. if selectedNotes.contains(anno) == false {
  988. selectedNotes.append(anno)
  989. }
  990. }
  991. }
  992. }
  993. return selectedNotes
  994. }
  995. func selectedObjcNotes() -> [Any] {
  996. var selectedNotes: [Any] = []
  997. let rowIndexes = self.noteOutlineView.selectedRowIndexes
  998. for row in rowIndexes {
  999. let item = self.noteOutlineView.item(atRow: row)
  1000. selectedNotes.append(item)
  1001. }
  1002. return selectedNotes
  1003. }
  1004. func clearAnnotationFilterData() {
  1005. if let _key = self.pdfDocument()?.documentURL?.path {
  1006. let userDefaults = UserDefaults.standard
  1007. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1008. userDefaults.set(typeData, forKey: NoteFilterVC.filterSelectTypeKey + _key)
  1009. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1010. userDefaults.set(colorData, forKey: NoteFilterVC.filterSelectColorKey + _key)
  1011. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1012. userDefaults.set(authorData, forKey: NoteFilterVC.filterSelectAuthorKey + _key)
  1013. userDefaults.synchronize()
  1014. }
  1015. }
  1016. private func _annoList_needRefreshUI(annos: [CPDFAnnotation]?) -> Bool {
  1017. guard let data = annos else {
  1018. return false
  1019. }
  1020. var need = false
  1021. for anno in data {
  1022. if anno.isForm() {
  1023. continue
  1024. }
  1025. if anno is CPDFLinkAnnotation {
  1026. continue
  1027. }
  1028. need = true
  1029. }
  1030. return need
  1031. }
  1032. }
  1033. extension KMLeftSideViewController: NSTextFieldDelegate {
  1034. func controlTextDidBeginEditing(_ obj: Notification) {
  1035. if self.noteOutlineView.isEqual(to: obj.object) {
  1036. }
  1037. }
  1038. func controlTextDidEndEditing(_ obj: Notification) {
  1039. if let data = self.editNoteTextField, data.isEqual(to: obj.object) {
  1040. if let data = self.editNote as? CPDFMarkupAnnotation {
  1041. data.setMarkupText(self.editNoteTextField?.stringValue ?? "")
  1042. } else if let data = self.editNote as? CPDFTextAnnotation {
  1043. data.contents = self.editNoteTextField?.stringValue ?? ""
  1044. }
  1045. }
  1046. }
  1047. }
  1048. extension KMLeftSideViewController: KMNoteOutlineViewDelegate {
  1049. func outlineView(_ anOutlineView: NSOutlineView, canResizeRowByItem item: AnyObject?) -> Bool? {
  1050. if anOutlineView.isEqual(to: self.noteOutlineView) {
  1051. return true
  1052. }
  1053. return false
  1054. }
  1055. func outlineView(_ anOutlineView: NSOutlineView, setHeight newHeight: CGFloat, ofRowByItem item: AnyObject?) {
  1056. }
  1057. func outlineView(_ anOutlineView: NSOutlineView, didChangeHiddenOfTableColumn aTableColumn: NSTableColumn) {
  1058. }
  1059. func outlineViewCommandKeyPressedDuringNavigation(_ anOutlineView: NSOutlineView) {
  1060. }
  1061. }
  1062. // MARK: - NSMenuDelegate
  1063. extension KMLeftSideViewController: NSMenuDelegate {
  1064. func menuDidClose(_ menu: NSMenu) {
  1065. if(menu == self.noteFilterMenu) {
  1066. headerView.sortButton.properties.state = .normal
  1067. headerView.sortButton.reloadData()
  1068. }
  1069. }
  1070. }