KMLeftSideViewController.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. //
  2. // KMLeftSideViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lxy on 2022/10/10.
  6. //
  7. import Cocoa
  8. @objc protocol KMLeftSideViewControllerDelegate {
  9. @objc optional func controlStateChange(_ obj: KMLeftSideViewController,show:Bool)
  10. @objc optional func enterEditMode(_ obj: KMLeftSideViewController, _ pages: [Int])
  11. @objc optional func searchAction(searchString:String, isCase:Bool)
  12. @objc optional func controller(_ controller: KMLeftSideViewController, dispayDidChange dispay: KMPDFDisplayType)
  13. @objc optional func controller(controller: KMLeftSideViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?)
  14. @objc optional func controller(controller: KMLeftSideViewController, bookMarkDidChange bookMarks: [KMBookMarkItem])
  15. @objc optional func controller(controller: KMLeftSideViewController, rotateType: KMRotateType)
  16. }
  17. class KMLeftSideViewController: NSViewController {
  18. var listView : CPDFListView!
  19. @IBOutlet weak var leftTableview: NSTableView!
  20. @IBOutlet weak var contentBox: NSBox!
  21. @IBOutlet weak var leftBox: NSBox!
  22. lazy var thumbnailViewController : KMThumbnailViewController = {
  23. let thumbnailViewController = KMThumbnailViewController()
  24. return thumbnailViewController
  25. }()
  26. lazy var outlineViewController : KMOutlineViewController = {
  27. let outlineViewController = KMOutlineViewController()
  28. return outlineViewController
  29. }()
  30. lazy var annotationViewController : KMAnnotationViewController = {
  31. let annotationViewController = KMAnnotationViewController()
  32. return annotationViewController
  33. }()
  34. lazy var bookViewController : KMBookMarkViewController = {
  35. let bookViewController = KMBookMarkViewController()
  36. bookViewController.bookMarkDidChange = { [unowned self] (controller, bookMarks) in
  37. self.delegate?.controller?(controller: self, bookMarkDidChange: bookMarks)
  38. }
  39. return bookViewController
  40. }()
  41. lazy var fromViewController : KMFromViewController = {
  42. let fromViewController = KMFromViewController()
  43. return fromViewController
  44. }()
  45. lazy var searchViewController : KMSearchViewController = {
  46. let searchViewController = KMSearchViewController()
  47. return searchViewController
  48. }()
  49. lazy var signatureViewController : KMSignatureViewController = {
  50. let signatureViewController = KMSignatureViewController()
  51. return signatureViewController
  52. }()
  53. lazy var panelSetViewController : KMPDFViewPanelSetViewController = {
  54. let panelSetViewController = KMPDFViewPanelSetViewController()
  55. panelSetViewController.delegate = self
  56. return panelSetViewController
  57. }()
  58. var dataSource : [KMLeftMethodMode] = [KMLeftMethodMode]()
  59. var type : KMLeftMethodMode = KMLeftMethodMode()
  60. var isShowPanel : Bool = false
  61. var norImage : [String] = []
  62. var selectImage : [String] = []
  63. var mainVC: KMMainViewController?
  64. //select page
  65. var selectPages: [Int]?
  66. open weak var delegate: KMLeftSideViewControllerDelegate?
  67. convenience init(type : KMLeftMethodMode) {
  68. self.init()
  69. self.type = type
  70. }
  71. override func viewDidLoad() {
  72. super.viewDidLoad()
  73. self.leftBox.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
  74. self.leftTableview.backgroundColor(NSColor.km_init(hex: "#F7F8FA"))
  75. self.leftTableview.border(NSColor.km_init(hex: "#EDEEF0"),1 , 0)
  76. self.addMenuTitle()
  77. self.refreshShowMethod()
  78. }
  79. func showPanelView(show: Bool) {
  80. self.isShowPanel = show
  81. if show {
  82. self.panelSetViewController.listView = self.listView
  83. self.panelSetViewController.view.frame = self.view.frame
  84. self.view.addSubview(self.panelSetViewController.view)
  85. self.panelSetViewController.reloadListViewModel()
  86. self.panelSetViewController.view.autoresizingMask = [.height]
  87. } else {
  88. self.contentBox.isHidden = false
  89. self.panelSetViewController.view.removeFromSuperview()
  90. if self.type.methodType == .None {
  91. self.delegate?.controlStateChange?(self, show: false)
  92. }
  93. }
  94. }
  95. func refreshMethodType(methodType: BotaType) {
  96. if (self.isShowPanel) {
  97. self.showPanelView(show: false)
  98. return
  99. }
  100. let newType = KMLeftMethodMode()
  101. var show = true
  102. if self.type.methodType != methodType {
  103. newType.methodType = methodType
  104. }
  105. if self.type.methodType == methodType {
  106. show = false
  107. }
  108. self.type = newType;
  109. self.refreshShowMethod()
  110. self.delegate?.controlStateChange?(self,show:show)
  111. }
  112. private func updateViewButtonState() {
  113. switch self.type.methodType {
  114. case .None: do {
  115. self.contentBox.contentView = NSView()
  116. self.delegate?.controlStateChange?(self,show:false)
  117. }
  118. break
  119. case .Thumbnail: do {
  120. self.thumbnailViewController.listView = self.listView
  121. self.thumbnailViewController.delegate = self
  122. self.contentBox.contentView = self.thumbnailViewController.view
  123. // self.thumbnailViewController.reloadData()
  124. }
  125. break
  126. case .Outline: do {
  127. self.outlineViewController.listView = self.listView
  128. self.contentBox.contentView = self.outlineViewController.view
  129. }
  130. break
  131. case .BookMark: do {
  132. self.bookViewController.listView = self.listView
  133. self.contentBox.contentView = self.bookViewController.view
  134. self.bookViewController.reloadData()
  135. }
  136. break
  137. case .Annotation: do {
  138. self.annotationViewController.listView = self.listView
  139. self.contentBox.contentView = self.annotationViewController.view
  140. // self.annotationViewController.reloadData()
  141. }
  142. break
  143. case .From: do {
  144. self.fromViewController.listView = self.listView
  145. self.contentBox.contentView = self.fromViewController.view
  146. self.fromViewController.reloadData()
  147. }
  148. break
  149. case .Search: do {
  150. self.searchViewController.listView = self.listView
  151. self.searchViewController.delegate = self
  152. self.contentBox.contentView = self.searchViewController.view
  153. // self.searchViewController.reloadData()
  154. }
  155. break
  156. case .Signature: do {
  157. self.signatureViewController.listView = self.listView
  158. self.contentBox.contentView = self.signatureViewController.view
  159. self.signatureViewController.reloadData()
  160. }
  161. break
  162. }
  163. }
  164. func refreshShowMethod() {
  165. self.dataSource = [KMLeftMethodMode]()
  166. norImage = []
  167. selectImage = []
  168. if KMBOTAManagerClass.shard.getMethodShow(key: thumbnailMethodKey) {
  169. let mode = KMLeftMethodMode()
  170. mode.methodName = thumbnailMethodKey
  171. mode.methodType = .Thumbnail
  172. self.dataSource.insert(mode, at: self.dataSource.count)
  173. norImage.append("KMImageNameSidebarThumbailNor")
  174. selectImage.append("KMImageNameSidebarThumbailSelect")
  175. }
  176. if KMBOTAManagerClass.shard.getMethodShow(key: outlineMethodKey) {
  177. let mode = KMLeftMethodMode()
  178. mode.methodName = outlineMethodKey
  179. mode.methodType = .Outline
  180. self.dataSource.insert(mode, at: self.dataSource.count)
  181. norImage.append("KMImageNameSidebarOutlineNor")
  182. selectImage.append("KMImageNameSidebarOutlineSelect")
  183. }
  184. if KMBOTAManagerClass.shard.getMethodShow(key: bookMarkMethodKey) {
  185. let mode = KMLeftMethodMode()
  186. mode.methodName = bookMarkMethodKey
  187. mode.methodType = .BookMark
  188. self.dataSource.insert(mode, at: self.dataSource.count)
  189. norImage.append("KMImageNameSidebarBookMarkNor")
  190. selectImage.append("KMImageNameSidebarBookMarkSelect")
  191. }
  192. if KMBOTAManagerClass.shard.getMethodShow(key: anntationMethodKey) {
  193. let mode = KMLeftMethodMode()
  194. mode.methodName = anntationMethodKey
  195. mode.methodType = .Annotation
  196. self.dataSource.insert(mode, at: self.dataSource.count)
  197. norImage.append("KMImageNameSidebarAnnotationNor")
  198. selectImage.append("KMImageNameSidebarAnnotationSelect")
  199. }
  200. if KMBOTAManagerClass.shard.getMethodShow(key: searchMethodKey) {
  201. let mode = KMLeftMethodMode()
  202. mode.methodName = searchMethodKey
  203. mode.methodType = .Search
  204. self.dataSource.insert(mode, at: self.dataSource.count)
  205. norImage.append("KMImageNameSidebarSearchNor")
  206. selectImage.append("KMImageNameSidebarSearchSelect")
  207. }
  208. // if KMBOTAManagerClass.shard.getMethodShow(key: formMethodKey) {
  209. // let mode = KMLeftMethodMode()
  210. // mode.methodName = formMethodKey
  211. // mode.methodType = .From
  212. // self.dataSource.insert(mode, at: self.dataSource.count)
  213. // }
  214. // if KMBOTAManagerClass.shard.getMethodShow(key: signatureMethodKey) {
  215. // let mode = KMLeftMethodMode()
  216. // mode.methodName = signatureMethodKey
  217. // mode.methodType = .Signature
  218. // self.dataSource.insert(mode, at: self.dataSource.count)
  219. // }
  220. var isConstant = false
  221. for source in dataSource {
  222. if self.type.methodType == source.methodType {
  223. isConstant = true
  224. }
  225. }
  226. if(!isConstant) {
  227. self.type = KMLeftMethodMode()
  228. }
  229. self.leftTableview.reloadData()
  230. var typeIndex = -1
  231. for (index,value) in self.dataSource.enumerated() {
  232. if value.methodType == self.type.methodType {
  233. typeIndex = index
  234. }
  235. }
  236. self.leftTableview.selectRowIndexes([typeIndex], byExtendingSelection: true)
  237. if self.dataSource.count > 0 && typeIndex >= 0 {
  238. self.type = self.dataSource[typeIndex]
  239. }
  240. self.updateViewButtonState()
  241. }
  242. //MARK: menu
  243. private func addMenuTitle() {
  244. let menus : NSMenu = NSMenu(title: "")
  245. let addItem = self.menuItemWithTitle(title: NSLocalizedString("Thumbnails", comment: ""),type:thumbnailMethodKey,action: #selector(renameBookAction),tag: 1)
  246. let outlineItem = self.menuItemWithTitle(title: NSLocalizedString("Outline", comment: ""),type:outlineMethodKey,action: #selector(renameBookAction),tag: 2)
  247. let bookItem = self.menuItemWithTitle(title: NSLocalizedString("Bookmarks", comment: ""), type:bookMarkMethodKey,action: #selector(renameBookAction),tag: 3)
  248. let annationItem = self.menuItemWithTitle(title: NSLocalizedString("Annotations", comment: ""), type:anntationMethodKey,action: #selector(renameBookAction),tag: 4)
  249. let searchItem = self.menuItemWithTitle(title: NSLocalizedString("Search", comment: ""), type:searchMethodKey,action: #selector(renameBookAction),tag: 5)
  250. // let formItem = self.menuItemWithTitle(title: NSLocalizedString("域", comment: ""), type:formMethodKey,action: #selector(renameBookAction),tag: 6)
  251. // let signatureItem = self.menuItemWithTitle(title: NSLocalizedString("签名", comment: ""), type:signatureMethodKey,action: #selector(renameBookAction),tag: 7)
  252. menus.addItem(addItem)
  253. menus.addItem(outlineItem)
  254. menus.addItem(bookItem)
  255. menus.addItem(annationItem)
  256. menus.addItem(searchItem)
  257. // menus.addItem(formItem)
  258. // menus.addItem(signatureItem)
  259. self.leftTableview.menu = menus
  260. }
  261. func menuItemWithTitle(title:String,type:String,action:Selector?,tag:Int) -> NSMenuItem {
  262. let menuItem = NSMenuItem.init(title: title as String, action: action, keyEquivalent: "")
  263. menuItem.target = self
  264. menuItem.tag = tag
  265. if KMBOTAManagerClass.shard.getMethodShow(key: type) {
  266. menuItem.state = NSControl.StateValue.on
  267. } else {
  268. menuItem.state = NSControl.StateValue.off
  269. }
  270. return menuItem
  271. }
  272. @objc func renameBookAction(menuItem:NSMenuItem) {
  273. var show = true
  274. if menuItem.state == NSControl.StateValue.on {
  275. menuItem.state = NSControl.StateValue.off
  276. show = false
  277. } else {
  278. menuItem.state = NSControl.StateValue.on
  279. show = true
  280. }
  281. switch menuItem.tag {
  282. case 1: do {
  283. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: thumbnailMethodKey)
  284. }
  285. case 2: do {
  286. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: outlineMethodKey)
  287. }
  288. case 3: do {
  289. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: bookMarkMethodKey)
  290. }
  291. case 4: do {
  292. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: anntationMethodKey)
  293. }
  294. case 5: do {
  295. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: searchMethodKey)
  296. }
  297. case 6: do {
  298. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: formMethodKey)
  299. }
  300. case 7: do {
  301. KMBOTAManagerClass.shard.setLeftMethod(show: show, key: signatureMethodKey)
  302. }
  303. break
  304. default:
  305. break
  306. }
  307. self.refreshShowMethod()
  308. }
  309. }
  310. extension KMLeftSideViewController: KMThumbnailViewControllerDelegate {
  311. func gotoPageEdit(thumbnailViewController: KMThumbnailViewController, pages: [Int]) {
  312. self.delegate?.enterEditMode?(self, pages)
  313. }
  314. func pageDidSelect(controller: KMThumbnailViewController, pages: [Int]) {
  315. self.selectPages = pages
  316. }
  317. func controller(controller: KMThumbnailViewController, itemClick item: Any?, itemKey: KMItemKey, params: Any?) {
  318. self.delegate?.controller?(controller: self, itemClick: item, itemKey: itemKey, params: params)
  319. }
  320. }
  321. extension KMLeftSideViewController : KMSearchViewControllerDelegate {
  322. func searchAction(searchString: String,isCase:Bool) {
  323. self.delegate?.searchAction?(searchString: searchString, isCase: isCase)
  324. }
  325. func searchDoneAction(viewController: KMSearchViewController) {
  326. self.type = KMLeftMethodMode()
  327. self.updateViewButtonState()
  328. self.delegate?.controlStateChange?(self,show:false)
  329. self.leftTableview.reloadData()
  330. }
  331. }
  332. //MARK: NSTableViewDelegate,NSTableViewDataSource
  333. extension KMLeftSideViewController: NSTableViewDelegate,NSTableViewDataSource {
  334. func numberOfRows(in tableView: NSTableView) -> Int {
  335. return self.dataSource.count
  336. }
  337. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  338. let cell : KMLiftSideCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMLiftSideCellView"), owner: self) as! KMLiftSideCellView
  339. if row <= selectImage.count-1 {
  340. if self.dataSource[row] == self.type {
  341. cell.isSelect = true
  342. cell.mothedImage.image = NSImage(named: selectImage[row])
  343. cell.backgroundColor(NSColor.km_init(hex: "#DFE1E5"))
  344. } else {
  345. cell.isSelect = false
  346. cell.mothedImage.image = NSImage(named: norImage[row])
  347. cell.backgroundColor(NSColor.clear)
  348. }
  349. }
  350. cell.index = row
  351. cell.buttonClick = { [unowned self] index in
  352. if ((index < self.dataSource.count) && (index > -1)) {
  353. let isSearch = self.type.methodType == .Search
  354. var show = true
  355. if( self.type == self.dataSource[index]) {
  356. self.type = KMLeftMethodMode()
  357. show = false
  358. } else {
  359. self.type = self.dataSource[index]
  360. show = true
  361. }
  362. self.trackEvent(type: self.type.methodType)
  363. self.updateViewButtonState()
  364. self.delegate?.controlStateChange?(self,show:show)
  365. self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  366. self.leftTableview.reloadData()
  367. UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  368. UserDefaults.standard.synchronize()
  369. if (isSearch && show == false) {
  370. self.view.window?.makeFirstResponder(self)
  371. } else if (isSearch && self.type.methodType != .Search) { // 切换
  372. self.view.window?.makeFirstResponder(self)
  373. }
  374. }
  375. }
  376. return cell
  377. }
  378. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  379. return 48
  380. }
  381. func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
  382. let rowView = KMCustomTableRowView()
  383. rowView.selectionColor = NSColor(calibratedRed: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1.0)
  384. rowView.color = NSColor.km_init(hex: "#F7F8FA")
  385. return rowView
  386. }
  387. func tableViewSelectionDidChange(_ notification: Notification) {
  388. }
  389. }
  390. extension KMLeftSideViewController: KMPDFViewPanelSetViewControllerDelegate {
  391. func controller(_ controller: KMPDFViewPanelSetViewController, dispayDidChange dispay: KMPDFDisplayType) {
  392. self.delegate?.controller?(self, dispayDidChange: dispay)
  393. }
  394. func controller(_ controller: KMPDFViewPanelSetViewController, pageBreaksClick pageBreaks: Bool) {
  395. self.listView?.displaysPageBreaks = pageBreaks
  396. self.listView?.layoutDocumentView()
  397. }
  398. func controller(_ controller: KMPDFViewPanelSetViewController, rotateClick rotateType: KMRotateType) {
  399. // if (rotateType == .clockwise) { /// 顺时针
  400. // let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  401. // if page.rotation == 0 {
  402. // page.rotation = 90
  403. // } else if page.rotation == 90 {
  404. // page.rotation = 180
  405. // } else if page.rotation == 180 {
  406. // page.rotation = 270
  407. // } else if page.rotation == 270 {
  408. // page.rotation = 0
  409. // }
  410. // self.listView?.layoutDocumentView()
  411. // } else if (rotateType == .anticlockwise) { /// 逆时针
  412. // let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  413. // if page.rotation == 0 {
  414. // page.rotation = 270
  415. // } else if page.rotation == 90 {
  416. // page.rotation = 0
  417. // } else if page.rotation == 180 {
  418. // page.rotation = 90
  419. // } else if page.rotation == 270 {
  420. // page.rotation = 180
  421. // }
  422. // self.listView?.layoutDocumentView()
  423. // }
  424. //
  425. self.delegate?.controller?(controller: self, rotateType: rotateType)
  426. }
  427. }
  428. // MARK: -
  429. // MARK: - 扩展
  430. extension KMLeftSideViewController {
  431. public func selectType(_ type: BotaType) {
  432. // 更新 type
  433. var show = true
  434. if (self.type.methodType == .None) {
  435. show = true
  436. } else {
  437. if (self.type.methodType == type) {
  438. show = false
  439. } else {
  440. show = true
  441. }
  442. }
  443. var index: Int = NSNotFound
  444. switch type {
  445. case .None:
  446. index = NSNotFound
  447. break
  448. case .Thumbnail:
  449. index = 0
  450. break
  451. case .Outline:
  452. index = 1
  453. break
  454. case .BookMark:
  455. index = 2
  456. break
  457. case .Annotation:
  458. index = 3
  459. break
  460. case .Search:
  461. index = 4
  462. break
  463. case .From:
  464. index = 5
  465. break
  466. case .Signature:
  467. index = 6
  468. break
  469. }
  470. self.type = self.getMethodMode(show ? type : .None)
  471. // 更新按钮状态
  472. self.updateViewButtonState()
  473. // 将事件传递出去
  474. self.delegate?.controlStateChange?(self,show:show)
  475. if (index != NSNotFound) {
  476. self.leftTableview.selectRowIndexes([index], byExtendingSelection: true)
  477. // 记录当前选中
  478. UserDefaults.standard.set(index, forKey: "KMBOTASelectedIndexKey")
  479. UserDefaults.standard.synchronize()
  480. }
  481. self.leftTableview.reloadData()
  482. }
  483. private func getMethodMode(_ type: BotaType) -> KMLeftMethodMode {
  484. let mode = KMLeftMethodMode()
  485. mode.methodType = type
  486. switch type {
  487. case .None:
  488. mode.methodName = ""
  489. break
  490. case .Thumbnail:
  491. mode.methodName = thumbnailMethodKey
  492. break
  493. case .Outline:
  494. mode.methodName = outlineMethodKey
  495. break
  496. case .BookMark:
  497. mode.methodName = bookMarkMethodKey
  498. break
  499. case .Annotation:
  500. mode.methodName = anntationMethodKey
  501. break
  502. case .Search:
  503. mode.methodName = searchMethodKey
  504. break
  505. case .From:
  506. mode.methodName = formMethodKey
  507. break
  508. case .Signature:
  509. mode.methodName = signatureMethodKey
  510. break
  511. }
  512. return mode
  513. }
  514. }
  515. //MARK: Cache
  516. extension KMLeftSideViewController {
  517. func clearAnnotationFilterData() {
  518. if let _key = self.listView?.document?.documentURL?.path {
  519. let userDefaults = UserDefaults.standard
  520. let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  521. userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + _key)
  522. let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  523. userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + _key)
  524. let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
  525. userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + _key)
  526. userDefaults.synchronize()
  527. }
  528. }
  529. func clearNotification() {
  530. self.bookViewController.removeNotification()
  531. self.annotationViewController.removeNotification()
  532. self.outlineViewController.removeNotification()
  533. self.thumbnailViewController.removeNotification()
  534. }
  535. }
  536. // MARK: - Analytics (埋点)
  537. extension KMLeftSideViewController {
  538. func trackEvent(type: BotaType) -> Void {
  539. if (type == .Thumbnail) {
  540. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Thumbnail", parameters: [
  541. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  542. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  543. } else if (type == .Outline) {
  544. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Outline", parameters: [
  545. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  546. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  547. } else if (type == .BookMark) {
  548. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_BookMark", parameters: [
  549. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  550. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  551. } else if (type == .Annotation) {
  552. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Annotation", parameters: [
  553. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  554. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  555. } else if (type == .Search) {
  556. KMAnalytics.trackEvent(eventName: "Btn_LeftSideBar_Search", parameters: [
  557. KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.leftSideBar,
  558. KMAnalytics.Parameter.labelKey : KMAnalytics.Label.leftSideBar_Btn], platform: .AppCenter, appTarget: .all)
  559. }
  560. }
  561. }