KMLeftSideViewController+Note.swift 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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. self.editNote = annotation
  348. }
  349. }
  350. @IBAction func noteSortAction(_ sender: AnyObject?) {
  351. // if (self.isAscendSort) {
  352. // self.isAscendSort = false
  353. // self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankPositive)
  354. // self.noteSortButton.toolTip = KMLocalizedString("descending sort", nil)
  355. // } else {
  356. // self.isAscendSort = true
  357. // self.noteSortButton.image = NSImage(named: KMImageNameBtnSidebarRankReverse)
  358. // self.noteSortButton.toolTip = KMLocalizedString("ascending sort", nil)
  359. // }
  360. KMDataManager.ud_set(self.isAscendSort, forKey: Self.Key.noteAscendSortKey)
  361. if self.noteSearchMode {
  362. reloadNoteForSearchMode()
  363. } else {
  364. reloadNoteForSortMode()
  365. }
  366. }
  367. @IBAction func noteSearchAction(_ sender: NSButton) {
  368. // self.noteTitleLabel.isHidden = true
  369. // self.noteSearchButton.isHidden = true
  370. // self.noteDoneButton.isHidden = false
  371. // self.noteFilterButton.isHidden = true
  372. // self.noteMoreButton.isHidden = true
  373. self.noteFilterButtonHoverView.isHidden = true
  374. }
  375. @IBAction func noteFilterAction(_ sender: AnyObject?) {
  376. let button = sender as? NSButton
  377. if self.noteFilterSelected == false {
  378. }
  379. let menu = NSMenu()
  380. self.noteFilterMenu = menu
  381. let filterViewController = KMNoteOutlineFilterViewController()
  382. filterViewController.listView = self.listView
  383. filterViewController.view.layer?.backgroundColor = .clear
  384. var states: [CPDFAnnotationState] = []
  385. for anno in self.allAnnotations {
  386. if let reviewS = self.noteReplyHanddler.fetchReviewState(anno) {
  387. if states.contains(reviewS) == false {
  388. states.append(reviewS)
  389. }
  390. } else {
  391. if states.contains(.none) == false {
  392. states.append(.none)
  393. }
  394. }
  395. if let markS = self.noteReplyHanddler.fetchAnnoState(anno) {
  396. if states.contains(markS) == false {
  397. states.append(markS)
  398. }
  399. } else {
  400. if states.contains(.unMarked) == false {
  401. states.append(.unMarked)
  402. }
  403. }
  404. }
  405. filterViewController.updateStates(states: states)
  406. filterViewController.setNotesArray(self.allAnnotations as NSArray)
  407. filterViewController.applyFilterCallback = { [weak self] typeArr, colorArr, authorArr, isEmpty in
  408. menu.cancelTracking()
  409. self?.headerView.sortButton.properties.state = .normal
  410. self?.headerView.sortButton.reloadData()
  411. self?.reloadAnnotation()
  412. }
  413. filterViewController.cancelCallback = {[weak self] isCancel in
  414. if (isCancel) {
  415. self?.headerView.sortButton.properties.state = .normal
  416. self?.headerView.sortButton.reloadData()
  417. menu.cancelTracking()
  418. }
  419. }
  420. let item = menu.addItem(withTitle: "", action: nil, keyEquivalent: "")
  421. item.target = self
  422. item.representedObject = filterViewController
  423. item.view = filterViewController.view
  424. menu.delegate = self
  425. menu.popUp(positioning: nil, at: NSMakePoint(-130, 30), in: self.headerView.sortButton)
  426. }
  427. func fetchNote(for index: Int) -> CPDFAnnotation? {
  428. return self.fetchAnnoModel(for: index)?.anno
  429. }
  430. func fetchAnnoModel(for index: Int) -> KMBotaAnnotationModel? {
  431. if self.noteSearchMode { // 搜索模式
  432. return self.noteSearchArray.safe_element(for: index) as? KMBotaAnnotationModel
  433. } else { // 常规模式(非搜索)
  434. // let model = self.annoListModel?.datas.safe_element(for: index)
  435. let model = self.noteOutlineView.item(atRow: index)
  436. if let data = model as? KMBotaAnnotationSectionModel {
  437. return nil
  438. }
  439. if let data = model as? KMBotaAnnotationModel {
  440. return data
  441. }
  442. if let data = model as? KMBotaAnnotationFooterModel {
  443. }
  444. if let data = model as? KMBotaAnnotationReplyModel {
  445. }
  446. return nil
  447. }
  448. }
  449. func fetchAnnoModel(for anno: CPDFAnnotation) -> KMBotaAnnotationModel? {
  450. if self.noteSearchMode { // 搜索模式
  451. for model in self.noteSearchArray {
  452. guard let data = model as? KMBotaAnnotationModel else {
  453. continue
  454. }
  455. if anno.isEqual(to: data.anno) {
  456. return data
  457. }
  458. }
  459. } else { // 常规模式(非搜索)
  460. for model in self.annoListModel?.datas ?? [] {
  461. for item in model.items {
  462. if let data = item as? KMBotaAnnotationModel {
  463. if anno.isEqual(to: data.anno) {
  464. return data
  465. }
  466. }
  467. }
  468. }
  469. }
  470. return nil
  471. }
  472. func showNoteEmptyView() {
  473. self.emptyView.isHidden = false
  474. }
  475. func hideNoteEmptyView() {
  476. self.emptyView.isHidden = true
  477. }
  478. }
  479. // MARK: - Note
  480. extension KMLeftSideViewController {
  481. public func refreshUIForAddAnnotation(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  482. let need = self._annoList_needRefreshUI(annos: annos)
  483. if need == false {
  484. return
  485. }
  486. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  487. self.note_reloadDataIfNeed()
  488. }
  489. public func refreshUIForAnnoAttributeDidChange(_ anno: CPDFAnnotation?, attributes: [String : Any]?) {
  490. self.updateThumbnail(at: Int(anno?.page?.pageIndex() ?? 0))
  491. let need = self._annoList_needRefreshUI(annos: anno != nil ? [anno!] : [])
  492. if need == false {
  493. return
  494. }
  495. if let data = anno {
  496. self.note_reloadDataForAnnoIfNeed(anno: data)
  497. }
  498. }
  499. public func annoList_refreshUIForDeleteAnnotations(annos: [CPDFAnnotation]?, page: CPDFPage?) {
  500. self.updateThumbnail(at: Int(page?.pageIndex() ?? 0))
  501. let need = self._annoList_needRefreshUI(annos: annos)
  502. if need == false {
  503. return
  504. }
  505. for anno in annos ?? [] {
  506. if let model = self.fetchAnnoModel(for: anno) {
  507. self.noteSearchArray.removeObject(model)
  508. model.sectionModel?.items.removeObject(model)
  509. if let footer = model.footerModel {
  510. model.sectionModel?.items.removeObject(footer)
  511. }
  512. if let cnt = model.sectionModel?.items.count, cnt == 0 {
  513. self.annoListModel?.datas.removeObject(model.sectionModel!)
  514. }
  515. if self.allAnnotations.contains(anno) {
  516. self.allAnnotations.removeObject(anno)
  517. }
  518. }
  519. }
  520. if self.dataUpdating == false {
  521. self.note_refrshUIIfNeed()
  522. }
  523. }
  524. func note_refrshUIIfNeed() {
  525. Task { @MainActor in
  526. self.noteOutlineView?.reloadData()
  527. }
  528. }
  529. func note_reloadDataIfNeed() {
  530. self.reloadAnnotation()
  531. }
  532. func note_reloadDataForAnnoIfNeed(anno: CPDFAnnotation) {
  533. if anno is CPDFLineAnnotation ||
  534. anno is CPDFSquareAnnotation ||
  535. anno is CPDFCircleAnnotation ||
  536. anno is CPDFInkAnnotation {
  537. // 形状注释 + Ink 需要显示框住的内容【刷新】
  538. for item in self.annoListModel?.datas ?? [] {
  539. for itemM in item.items {
  540. if anno.isEqual(to: itemM.anno) {
  541. self.noteOutlineView.reloadItem(itemM)
  542. break
  543. }
  544. }
  545. }
  546. } else {
  547. for item in self.annoListModel?.datas ?? [] {
  548. for itemM in item.items {
  549. if anno.isEqual(to: itemM.anno) {
  550. self.noteOutlineView.reloadItem(itemM)
  551. break
  552. }
  553. }
  554. }
  555. }
  556. }
  557. func reloadAnnotation() {
  558. if self.listView != nil {
  559. let filterKey = self.pdfDocument()?.documentURL.path ?? ""
  560. let typeArr: [String] = KMBotaTools.noteFilterAnnoTypes(key: filterKey)
  561. let colorArr: [Any] = KMBotaTools.noteFilterColors(key: filterKey)
  562. let authorArr: [Any] = KMBotaTools.noteFilterAuthors(key: filterKey)
  563. var stateArr: [NSNumber] = KMBotaTools.noteFilterStates(key: filterKey)
  564. var hasMark = false
  565. var hasReview = false
  566. for data in stateArr {
  567. let state = data.intValue
  568. if state == CPDFAnnotationState.marked.rawValue || state == CPDFAnnotationState.unMarked.rawValue {
  569. hasMark = true
  570. }
  571. if state == CPDFAnnotationState.none.rawValue || state == CPDFAnnotationState.accepted.rawValue || state == CPDFAnnotationState.rejected.rawValue || state == CPDFAnnotationState.canceled.rawValue || state == CPDFAnnotationState.completed.rawValue {
  572. hasReview = true
  573. }
  574. }
  575. if hasMark == false {
  576. stateArr.append(NSNumber(value: CPDFAnnotationState.marked.rawValue))
  577. stateArr.append(NSNumber(value: CPDFAnnotationState.unMarked.rawValue))
  578. }
  579. if hasReview == false {
  580. stateArr.append(NSNumber(value: CPDFAnnotationState.none.rawValue))
  581. stateArr.append(NSNumber(value: CPDFAnnotationState.accepted.rawValue))
  582. stateArr.append(NSNumber(value: CPDFAnnotationState.rejected.rawValue))
  583. stateArr.append(NSNumber(value: CPDFAnnotationState.canceled.rawValue))
  584. stateArr.append(NSNumber(value: CPDFAnnotationState.completed.rawValue))
  585. }
  586. var annotationArray: [CPDFAnnotation] = []
  587. var allAnnotation: [CPDFAnnotation] = []
  588. for i in 0 ..< self.pageCount() {
  589. let page = self.pdfDocument()?.page(at: UInt(i))
  590. var annos: [CPDFAnnotation] = []
  591. // 处理过滤
  592. let types = ["Highlight","Underline","Strikeout","Squiggly","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Sign"/*, "table"*/,"Polyline","Polygon"]
  593. if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 && stateArr.count == 0 {
  594. annos = KMOCToolClass.filterAnnotation(annotations: page?.annotations ?? [],types: types) as? [CPDFAnnotation] ?? []
  595. annotationArray += annos
  596. } else {
  597. var filterAnnos: [CPDFAnnotation] = page?.annotations ?? []
  598. let allAnnos = KMOCToolClass.filterAnnotation(annotations: filterAnnos,types: types) as? [CPDFAnnotation] ?? []
  599. annotationArray += allAnnos
  600. if typeArr.count > 0 {
  601. var theTypes = typeArr
  602. if typeArr.contains("Measure") { //包含测量的话
  603. theTypes.append("Polygon")
  604. theTypes.append("Polyline")
  605. theTypes.append(CPDFAnnotation.kType.measureArrow)
  606. }
  607. if theTypes.contains(CPDFAnnotation.kType.measureArrow) && theTypes.contains(CPDFAnnotation.kType.arrow) == false {
  608. theTypes.append(CPDFAnnotation.kType.arrow)
  609. }
  610. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos, types: theTypes) as? [CPDFAnnotation]) ?? []
  611. }
  612. if (colorArr.count > 0) {
  613. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,colors: colorArr) as? [CPDFAnnotation]) ?? []
  614. }
  615. if (authorArr.count > 0) {
  616. filterAnnos = (KMOCToolClass.filterAnnotation(annotations: filterAnnos,authors: authorArr) as? [CPDFAnnotation]) ?? []
  617. }
  618. if typeArr.isEmpty == false {
  619. if typeArr.contains("Measure") {
  620. if typeArr.contains(CPDFAnnotation.kType.arrow) == false {
  621. for anno in filterAnnos {
  622. if let data = anno as? CPDFLineAnnotation, data.type == CPDFAnnotation.kType.arrow && data.isMeasure == false {
  623. filterAnnos.removeObject(anno)
  624. }
  625. }
  626. }
  627. } else {
  628. for anno in filterAnnos {
  629. if let data = anno as? CPDFLineAnnotation, data.isMeasure {
  630. filterAnnos.removeObject(anno)
  631. }
  632. }
  633. }
  634. }
  635. if stateArr.count > 0 {
  636. for anno in filterAnnos {
  637. let markState = self.noteReplyHanddler.fetchAnnoState(anno) ?? .unMarked
  638. let reviewState = self.noteReplyHanddler.fetchReviewState(anno) ?? .none
  639. if stateArr.contains(NSNumber(value: markState.rawValue)) == false || stateArr.contains(NSNumber(value: reviewState.rawValue)) == false {
  640. filterAnnos.removeObject(anno)
  641. }
  642. }
  643. }
  644. annos = filterAnnos
  645. }
  646. //添加签名注释
  647. for annotation in page?.annotations ?? [] {
  648. if annotation.isKind(of: CPDFSignatureAnnotation.self) {
  649. annos.append(annotation)
  650. annotationArray.append(annotation)
  651. }
  652. }
  653. for annotation in annos {
  654. if annotation.isKind(of: KMTableAnnotation.self) {
  655. annos.removeObject(annotation)
  656. if annotationArray.contains(annotation) {
  657. annotationArray.removeObject(annotation)
  658. }
  659. } else if annotation.annotationShouldDisplay() == false {
  660. annos.removeObject(annotation)
  661. if annotationArray.contains(annotation) {
  662. annotationArray.removeObject(annotation)
  663. }
  664. } else if annotation.isKind(of: CPDFLinkAnnotation.self) {
  665. annos.removeObject(annotation)
  666. if annotationArray.contains(annotation) {
  667. annotationArray.removeObject(annotation)
  668. }
  669. } else if annotation.isKind(of: CPDFRedactAnnotation.self) {
  670. annos.removeObject(annotation)
  671. if annotationArray.contains(annotation) {
  672. annotationArray.removeObject(annotation)
  673. }
  674. } else if annotation.isForm() {
  675. annos.removeObject(annotation)
  676. if annotationArray.contains(annotation) {
  677. annotationArray.removeObject(annotation)
  678. }
  679. }
  680. }
  681. // 添加刷选后的注释
  682. allAnnotation += annos
  683. }
  684. // 处理排序
  685. if self.noteSortType == .page {
  686. /// 排序(升序)
  687. if self.isAscendSort {
  688. allAnnotation.sort {
  689. let idx0 = $0.page?.pageIndex() ?? 0
  690. let idx1 = $1.page?.pageIndex() ?? 0
  691. return idx0 <= idx1
  692. }
  693. } else {
  694. allAnnotation.sort {
  695. let idx0 = $0.page?.pageIndex() ?? 0
  696. let idx1 = $1.page?.pageIndex() ?? 0
  697. return idx0 > idx1
  698. }
  699. }
  700. } else if self.noteSortType == .time {
  701. /// 排序(升序)
  702. if self.isAscendSort {
  703. allAnnotation.sort {
  704. if $0.modificationDate() == nil {
  705. return false
  706. }
  707. if $1.modificationDate() == nil {
  708. return false
  709. }
  710. return $0.modificationDate() <= $1.modificationDate()
  711. }
  712. } else {
  713. allAnnotation.sort {
  714. if $0.modificationDate() == nil {
  715. return false
  716. }
  717. if $1.modificationDate() == nil {
  718. return false
  719. }
  720. return $0.modificationDate() > $1.modificationDate()
  721. }
  722. }
  723. }
  724. // 数据模型化
  725. let model = KMAnnotationListModel()
  726. var datas: [KMBotaAnnotationModel] = []
  727. var prePageIdx: Int = NSNotFound
  728. var preDate: Date?
  729. var secM: KMBotaAnnotationSectionModel?
  730. for anno in allAnnotation {
  731. let item = KMBotaAnnotationModel()
  732. item.anno = anno
  733. item.showPage = self.annoListIsShowPage()
  734. item.showTime = self.annoListIsShowTime()
  735. item.showAuthor = self.annoListIsShowAnther()
  736. if self.noteSortType == .page {
  737. let pageIdx = Int(anno.pageIndex())
  738. if pageIdx != prePageIdx { // 不是同一个页面
  739. secM = KMBotaAnnotationSectionModel()
  740. model.datas.append(secM!)
  741. }
  742. secM?.items.append(item)
  743. prePageIdx = Int(anno.pageIndex())
  744. } else { // time
  745. let date = anno.modificationDate()
  746. if let same = date?.isSameDay(other: preDate), same == false { // 不是同一天
  747. secM = KMBotaAnnotationSectionModel()
  748. model.datas.append(secM!)
  749. }
  750. secM?.items.append(item)
  751. preDate = date
  752. }
  753. item.sectionModel = secM
  754. let replyAnnos = self.noteReplyHanddler.fetchReplyAnnotations(anno) ?? []
  755. for replyAnno in replyAnnos {
  756. let replyM = KMBotaAnnotationReplyModel()
  757. replyM.anno = anno
  758. replyM.replyAnno = replyAnno
  759. // secM?.items.append(replyM)
  760. replyM.annoModel = item
  761. item.replyAnnos.append(replyM)
  762. }
  763. let footerI = KMBotaAnnotationFooterModel()
  764. footerI.anno = anno
  765. secM?.items.append(footerI)
  766. item.footerModel = footerI
  767. footerI.annoModel = item
  768. }
  769. // model.datas = datas
  770. self.annoListModel = model
  771. // 转换对象,用于数据显示
  772. self.allAnnotations = annotationArray
  773. // self.noteFilterButton.isEnabled = self.allAnnotations.count >= 1
  774. }
  775. self.note_refrshUIIfNeed()
  776. }
  777. func reloadNoteForSearchMode() {
  778. if self.noteSearchMode == false {
  779. return
  780. }
  781. // 处理排序
  782. if self.noteSortType == .page {
  783. if self.isAscendSort { /// 排序(升序)
  784. self.noteSearchArray.sort {
  785. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  786. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  787. return idx0 <= idx1
  788. }
  789. } else {
  790. self.noteSearchArray.sort {
  791. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  792. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  793. return idx0 > idx1
  794. }
  795. }
  796. } else if self.noteSortType == .time {
  797. if self.isAscendSort { /// 排序(升序)
  798. self.noteSearchArray.sort {
  799. if $0.anno?.modificationDate() == nil {
  800. return false
  801. }
  802. if $1.anno?.modificationDate() == nil {
  803. return false
  804. }
  805. return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
  806. }
  807. } else {
  808. self.noteSearchArray.sort {
  809. if $0.anno?.modificationDate() == nil {
  810. return false
  811. }
  812. if $1.anno?.modificationDate() == nil {
  813. return false
  814. }
  815. return $0.anno!.modificationDate() > $1.anno!.modificationDate()
  816. }
  817. }
  818. }
  819. self.note_refrshUIIfNeed()
  820. }
  821. func reloadNoteForSortMode() {
  822. // 处理排序
  823. var models: [KMBotaAnnotationModel] = []
  824. for selM in self.annoListModel?.datas ?? [] {
  825. for model in selM.items {
  826. guard let annoModel = model as? KMBotaAnnotationModel else {
  827. continue
  828. }
  829. models.append(annoModel)
  830. }
  831. }
  832. if self.noteSortType == .page {
  833. if self.isAscendSort { /// 排序(升序)
  834. models.sort {
  835. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  836. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  837. return idx0 <= idx1
  838. }
  839. } else {
  840. models.sort {
  841. let idx0 = $0.anno?.page?.pageIndex() ?? 0
  842. let idx1 = $1.anno?.page?.pageIndex() ?? 0
  843. return idx0 > idx1
  844. }
  845. }
  846. } else if self.noteSortType == .time {
  847. if self.isAscendSort { /// 排序(升序)
  848. models.sort {
  849. if $0.anno?.modificationDate() == nil {
  850. return false
  851. }
  852. if $1.anno?.modificationDate() == nil {
  853. return false
  854. }
  855. return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
  856. }
  857. } else {
  858. models.sort {
  859. if $0.anno?.modificationDate() == nil {
  860. return false
  861. }
  862. if $1.anno?.modificationDate() == nil {
  863. return false
  864. }
  865. return $0.anno!.modificationDate() > $1.anno!.modificationDate()
  866. }
  867. }
  868. }
  869. // 数据模型\化
  870. let listModel = KMAnnotationListModel()
  871. var prePageIdx: Int = NSNotFound
  872. var preDate: Date?
  873. var secM: KMBotaAnnotationSectionModel?
  874. for itemM in models {
  875. guard let anno = itemM.anno else {
  876. continue
  877. }
  878. if self.noteSortType == .page {
  879. let pageIdx = Int(anno.pageIndex())
  880. if pageIdx != prePageIdx { // 不是同一个页面
  881. secM = KMBotaAnnotationSectionModel()
  882. listModel.datas.append(secM!)
  883. secM?.isExpand = itemM.sectionModel?.isExpand ?? true
  884. }
  885. secM?.items.append(itemM)
  886. prePageIdx = Int(anno.pageIndex())
  887. } else { // time
  888. let date = anno.modificationDate()
  889. if let same = date?.isSameDay(other: preDate), same == false { // 不是同一天
  890. secM = KMBotaAnnotationSectionModel()
  891. listModel.datas.append(secM!)
  892. secM?.isExpand = itemM.sectionModel?.isExpand ?? true
  893. }
  894. secM?.items.append(itemM)
  895. preDate = date
  896. }
  897. var tmpSelM = itemM.sectionModel
  898. itemM.sectionModel = secM
  899. let footerI = KMBotaAnnotationFooterModel()
  900. footerI.anno = anno
  901. secM?.items.append(footerI)
  902. footerI.isExpand = itemM.footerModel?.isExpand ?? false
  903. itemM.footerModel = footerI
  904. footerI.annoModel = itemM
  905. }
  906. self.annoListModel = listModel
  907. self.note_refrshUIIfNeed()
  908. }
  909. // 搜索 Action
  910. func updateNoteFilterPredicate(searchString: String) {
  911. var stringValue = searchString
  912. // 清空数据
  913. self.noteSearchArray.removeAll()
  914. if stringValue.isEmpty {
  915. for model in self.annoListModel?.datas ?? [] {
  916. for item in model.items {
  917. guard let _ = item.anno else {
  918. continue
  919. }
  920. guard let data = item as? KMBotaAnnotationModel else {
  921. continue
  922. }
  923. self.noteSearchArray.append(item)
  924. }
  925. }
  926. } else {
  927. // 忽略大小写
  928. let caseInsensite = self.caseInsensitiveNoteSearch
  929. if caseInsensite {
  930. stringValue = stringValue.lowercased()
  931. }
  932. for model in self.annoListModel?.datas ?? [] {
  933. for item in model.items {
  934. guard let note = item.anno else {
  935. continue
  936. }
  937. var noteString = ""
  938. if let anno = note as? CPDFMarkupAnnotation {
  939. noteString = anno.markupContent()
  940. } else {
  941. noteString = KMBOTAAnnotationTool.fetchContentLabelString(annotation: note)
  942. }
  943. if caseInsensite {
  944. noteString = noteString.lowercased()
  945. }
  946. guard let data = item as? KMBotaAnnotationModel else {
  947. continue
  948. }
  949. if noteString.contains(stringValue) {
  950. self.noteSearchArray.append(item)
  951. }
  952. }
  953. }
  954. }
  955. self.note_refrshUIIfNeed()
  956. }
  957. @objc func selectSelectedNote(_ sender: AnyObject?) {
  958. if self.hideNotes() == false {
  959. let selectedNotes = self.selectedNotes()
  960. if selectedNotes.count == 1 {
  961. let annotation = selectedNotes.last!
  962. self.listView?.go(to: annotation.bounds, on: annotation.page, animated: true)
  963. self.listView?.updateActiveAnnotations([annotation])
  964. self.listView?.setNeedsDisplayAnnotationViewForVisiblePages()
  965. if annotation is CPDFPolygonAnnotation || annotation is CPDFPolylineAnnotation {
  966. self.listView?.pdfListViewDelegate.pdfListViewAnnotationMeasureInfoChange?(self.listView, with: annotation)
  967. } else if let anno = annotation as? CPDFLineAnnotation {
  968. if anno.isMeasure {
  969. self.listView?.pdfListViewDelegate.pdfListViewAnnotationMeasureInfoChange?(self.listView, with: annotation)
  970. }
  971. }
  972. }
  973. }
  974. }
  975. func selectedNotes() -> [CPDFAnnotation] {
  976. var selectedNotes: [CPDFAnnotation] = []
  977. let rowIndexes = self.noteOutlineView.selectedRowIndexes
  978. for row in rowIndexes {
  979. let item = self.noteOutlineView.item(atRow: row)
  980. if item is KMBotaAnnotationModel {
  981. if let anno = (item as! KMBotaAnnotationModel).anno {
  982. if selectedNotes.contains(anno) == false {
  983. selectedNotes.append(anno)
  984. }
  985. }
  986. }
  987. }
  988. return selectedNotes
  989. }
  990. func selectedObjcNotes() -> [Any] {
  991. var selectedNotes: [Any] = []
  992. let rowIndexes = self.noteOutlineView.selectedRowIndexes
  993. for row in rowIndexes {
  994. let item = self.noteOutlineView.item(atRow: row)
  995. selectedNotes.append(item)
  996. }
  997. return selectedNotes
  998. }
  999. func clearAnnotationFilterData() {
  1000. if let _key = self.pdfDocument()?.documentURL?.path {
  1001. let userDefaults = UserDefaults.standard
  1002. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1003. userDefaults.set(typeData, forKey: NoteFilterVC.filterSelectTypeKey + _key)
  1004. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1005. userDefaults.set(colorData, forKey: NoteFilterVC.filterSelectColorKey + _key)
  1006. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  1007. userDefaults.set(authorData, forKey: NoteFilterVC.filterSelectAuthorKey + _key)
  1008. userDefaults.synchronize()
  1009. }
  1010. }
  1011. private func _annoList_needRefreshUI(annos: [CPDFAnnotation]?) -> Bool {
  1012. guard let data = annos else {
  1013. return false
  1014. }
  1015. var need = false
  1016. for anno in data {
  1017. if anno.isForm() {
  1018. continue
  1019. }
  1020. if anno is CPDFLinkAnnotation {
  1021. continue
  1022. }
  1023. need = true
  1024. }
  1025. return need
  1026. }
  1027. }
  1028. extension KMLeftSideViewController: NSTextFieldDelegate {
  1029. func controlTextDidBeginEditing(_ obj: Notification) {
  1030. if self.noteOutlineView.isEqual(to: obj.object) {
  1031. }
  1032. }
  1033. func controlTextDidEndEditing(_ obj: Notification) {
  1034. if let data = self.editNoteTextField, data.isEqual(to: obj.object) {
  1035. if let data = self.editNote as? CPDFMarkupAnnotation {
  1036. data.setMarkupText(self.editNoteTextField?.stringValue ?? "")
  1037. } else if let data = self.editNote as? CPDFTextAnnotation {
  1038. data.contents = self.editNoteTextField?.stringValue ?? ""
  1039. }
  1040. }
  1041. }
  1042. }
  1043. extension KMLeftSideViewController: KMNoteOutlineViewDelegate {
  1044. func outlineView(_ anOutlineView: NSOutlineView, canResizeRowByItem item: AnyObject?) -> Bool? {
  1045. if anOutlineView.isEqual(to: self.noteOutlineView) {
  1046. return true
  1047. }
  1048. return false
  1049. }
  1050. func outlineView(_ anOutlineView: NSOutlineView, setHeight newHeight: CGFloat, ofRowByItem item: AnyObject?) {
  1051. }
  1052. func outlineView(_ anOutlineView: NSOutlineView, didChangeHiddenOfTableColumn aTableColumn: NSTableColumn) {
  1053. }
  1054. func outlineViewCommandKeyPressedDuringNavigation(_ anOutlineView: NSOutlineView) {
  1055. }
  1056. }
  1057. // MARK: - NSMenuDelegate
  1058. extension KMLeftSideViewController: NSMenuDelegate {
  1059. func menuDidClose(_ menu: NSMenu) {
  1060. if(menu == self.noteFilterMenu) {
  1061. headerView.sortButton.properties.state = .normal
  1062. headerView.sortButton.reloadData()
  1063. }
  1064. }
  1065. }