KMToolbarController.swift 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. //
  2. // KMToolbarController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/12/29.
  6. //
  7. import Cocoa
  8. extension CAnnotationType {
  9. func isAdvanced() -> Bool {
  10. if (self == .link || self == .stamp || self == .signSignature) {
  11. return true
  12. }
  13. if (self == .signText || self == .signTure || self == .signFalse || self == .signCircle || self == .signLine || self == .signDot || self == .signDate) {
  14. return true
  15. }
  16. if (self == .addText || self == .addImage) {
  17. return true
  18. }
  19. return false
  20. }
  21. func isMarkup() -> Bool {
  22. if self == .highlight || self == .underline || self == .strikeOut || self == .ink || self == .squiggly {
  23. return true
  24. }
  25. return false
  26. }
  27. func isSquare() -> Bool {
  28. if self == .square || self == .circle || self == .line || self == .arrow {
  29. return true
  30. }
  31. return false
  32. }
  33. }
  34. @objc protocol KMToolbarControllerDelegate {
  35. @objc optional func toolbarController(_ viewController: KMToolbarController, heightOffsetChange heightOffset: Float, animated: Bool)
  36. @objc optional func changeAnnotationModeAction(item:KMToolbarClickButton)
  37. @objc optional func showPDFLayoutModeAction(show:Bool)
  38. @objc optional func clickChildTool(type: KMToolbarType, index: Int)
  39. @objc optional func changePDFViewZoomModelAction(selectedTag:Int)
  40. @objc optional func changePDFViewZoomInAction()
  41. @objc optional func changePDFViewZoomOutAction()
  42. @objc optional func changePDFViewGotoNextPageAction()
  43. @objc optional func changePDFViewGoToPreviousPageAction()
  44. @objc optional func changePDFViewGotoBackAction()
  45. @objc optional func changePDFViewGoToForwardAction()
  46. @objc optional func aiTranslationPDFFileAction()
  47. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
  48. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
  49. @objc optional func mainToolDidClicked(_ toolController: KMToolbarController, _ beforeType: KMToolbarViewType, _ type: KMToolbarViewType, _ item: KMToolbarItemView, _ pages: [Int])
  50. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareAction toolbarItem: KMToolbarItemView)
  51. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
  52. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
  53. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareOriginalPDF item:NSMenuItem)
  54. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
  55. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView)
  56. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String, forward: Bool)
  57. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, findSearchAction searchString: String, forward: Bool)
  58. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, findSearchAllAction searchString: String, forward: Bool)
  59. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
  60. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, viewItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
  61. }
  62. class KMToolbarController: NSViewController {
  63. static let mainToolBarHeight: Float = 48
  64. static let childToolBarHeightValue: Float = 41
  65. static let findBarHeight: Float = 25
  66. @IBOutlet weak var mainToolBarBox: NSBox!
  67. @IBOutlet weak var childToolBarBox: NSBox!
  68. @IBOutlet weak var secondaryToolBarBox: NSBox!
  69. @IBOutlet weak var mainToolBarHeight: NSLayoutConstraint!
  70. @IBOutlet weak var childToolBarHeight: NSLayoutConstraint!
  71. @IBOutlet weak var secondaryToolBarHeight: NSLayoutConstraint!
  72. @IBOutlet weak var bottomOffset: NSLayoutConstraint!
  73. var mainToolBarView: KMToolbarViewController?
  74. var childToolBarView: KMToolbarViewController?
  75. var _toolbarType : KMToolbarViewType = KMToolbarViewType.None
  76. weak var mainViewController: KMMainViewController?
  77. open weak var delegate: KMToolbarControllerDelegate?
  78. var toolbarItems : [NSToolbarItem.Identifier : Any] = [:]
  79. var listView : CPDFListView?
  80. var lastItemBox : KMToolbarItemView = KMToolbarItemView()
  81. var lastChildItemBox : KMToolbarItemView = KMToolbarItemView()
  82. var popover: NSPopover?
  83. //find seaarch
  84. @IBOutlet weak var findSearchView: KMSearchFindView!
  85. // 是否显示所有注释
  86. private var _isShowAllAnnotations = true
  87. // 是否显示所有注释
  88. var isShowAllAnnotations: Bool {
  89. get {
  90. return _isShowAllAnnotations
  91. }
  92. set {
  93. _isShowAllAnnotations = newValue
  94. self.childToolBarView?.isShowAllAnnotations = newValue
  95. let item = self.findChildItem(KMToolbarShowToolbarItemIdentifier)
  96. item?.isSelected = !newValue
  97. if newValue {
  98. item?.titleName = NSLocalizedString("Hide", comment: "")
  99. item?.toolTip = NSLocalizedString("Hide", comment: "")
  100. item?.menuFormRepresentation?.title = NSLocalizedString("Hide", comment: "")
  101. } else {
  102. item?.titleName = NSLocalizedString("Display", comment: "")
  103. item?.toolTip = NSLocalizedString("Display", comment: "")
  104. item?.menuFormRepresentation?.title = NSLocalizedString("Display", comment: "")
  105. }
  106. for itemId in self._fetchItemIdsForHideNotes() {
  107. self.findItem(itemId)?.unEnabled = !self.isShowAllAnnotations
  108. }
  109. }
  110. }
  111. private var _ignoreCurrentAnnotationTypeChange = false
  112. var ignoreCurrentAnnotationTypeChange: Bool {
  113. get {
  114. return self._ignoreCurrentAnnotationTypeChange
  115. }
  116. set {
  117. self._ignoreCurrentAnnotationTypeChange = newValue
  118. self.childToolBarView?.ignoreCurrentAnnotationTypeChange = self.ignoreCurrentAnnotationTypeChange
  119. // 忽略后重置 这个属性是基于单次添加,所以使用后会重置
  120. // self._ignoreCurrentAnnotationTypeChange = false
  121. }
  122. }
  123. var mainToolBarisVisable: Bool {
  124. get {
  125. return self.mainToolBarBox.isHidden == false
  126. }
  127. set {
  128. let needShow = newValue
  129. let currentIsShow = self.mainToolBarisVisable
  130. let toolBarH: Float = Self.mainToolBarHeight
  131. if needShow {
  132. if currentIsShow { // 当前已显示
  133. return
  134. }
  135. let height = self.view.frame.size.height
  136. self.mainToolBarBox.animator().isHidden = false
  137. self.mainToolBarHeight.animator().constant = toolBarH.cgFloat
  138. self.delegate?.toolbarController?(self, heightOffsetChange: Float(height)+toolBarH, animated: true)
  139. } else {
  140. if currentIsShow == false { // 当前已隐藏
  141. return
  142. }
  143. let height = self.view.frame.size.height
  144. self.mainToolBarBox.isHidden = true
  145. self.mainToolBarHeight.animator().constant = 0
  146. self.delegate?.toolbarController?(self, heightOffsetChange: Float(height)-toolBarH, animated: true)
  147. }
  148. }
  149. }
  150. override func viewDidLoad() {
  151. super.viewDidLoad()
  152. // Do view setup here.
  153. updateViewColor()
  154. mainToolBarView = KMToolbarViewController.init()
  155. mainToolBarView?.view.wantsLayer = true
  156. mainToolBarView?.view.layer?.backgroundColor = NSColor.km_init(hex: "#F7F8FA").cgColor
  157. mainToolBarBox.contentView = mainToolBarView?.view
  158. mainToolBarView?.delegate = self
  159. if let data = self.listView {
  160. mainToolBarView?.pdfView = data
  161. }
  162. childToolBarView = KMToolbarViewController.init()
  163. childToolBarView?.view.wantsLayer = true
  164. childToolBarView?.view.layer?.backgroundColor = NSColor.km_init(hex: "#F7F8FA").cgColor
  165. childToolBarBox.contentView = childToolBarView?.view
  166. childToolBarView?.view.frame = childToolBarBox.frame
  167. childToolBarView?.delegate = self
  168. childToolBarView?.view.autoresizingMask = [.width, .height]
  169. if let data = self.listView {
  170. childToolBarView?.pdfView = data
  171. }
  172. toolbarType = .None
  173. mainToolBarView?.toolbarType = .Main
  174. mainToolBarView?.reloadateToolbar()
  175. mainToolBarView?.toolbar?.allowsUserCustomization = true
  176. self.findSearchView.isHidden = true
  177. NotificationCenter.default.addObserver(self, selector: #selector(selectedShapAnnotationChangeNotification(_:)), name: NSNotification.Name.init(rawValue: "KMSelectedShapAnnotationChangeNotification"), object: nil)
  178. NotificationCenter.default.addObserver(self, selector: #selector(PDFChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "PDFChangedNotification"), object: nil)
  179. NotificationCenter.default.addObserver(self, selector: #selector(PDFTextEditPDFChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "KMPDFTextEditPDFChangedNotification"), object: nil)
  180. }
  181. // MARK:
  182. func updateViewColor() -> Void {
  183. }
  184. // MARK: Setter&Getter
  185. var toolbarType: KMToolbarViewType {
  186. set {
  187. if newValue == _toolbarType {
  188. if newValue == .Move || newValue == .Magnify || newValue == .Select || newValue == .SelectZoom {
  189. _toolbarType = .Annatiton
  190. } else {
  191. _toolbarType = .None
  192. }
  193. } else {
  194. _toolbarType = newValue
  195. }
  196. mainViewController?.cancelMeasureType()
  197. mainToolBarView?.toolbar?.isHidden = false
  198. secondaryToolBarBox.isHidden = true
  199. secondaryToolBarHeight.constant = 51
  200. let mainToolbarH = self.mainToolBarisVisable ? Self.mainToolBarHeight : 0
  201. if self.mainViewController!.viewManager.isPDFReadMode {
  202. if (_toolbarType == .Annatiton) {
  203. let childToolbarH = Self.childToolBarHeightValue
  204. bottomOffset.constant = childToolbarH.cgFloat
  205. mainToolBarHeight.constant = 0
  206. childToolBarBox.isHidden = false
  207. self.delegate?.toolbarController?(self, heightOffsetChange: 41, animated: false)
  208. } else {
  209. mainToolBarHeight.constant = 0
  210. bottomOffset.constant = 0
  211. childToolBarBox.isHidden = true
  212. mainToolBarView?.toolbar?.isHidden = true
  213. self.delegate?.toolbarController?(self, heightOffsetChange: 0, animated: false)
  214. }
  215. } else {
  216. if _toolbarType == .None {
  217. bottomOffset.constant = 0
  218. childToolBarBox.isHidden = true
  219. self.delegate?.toolbarController?(self, heightOffsetChange: mainToolbarH, animated: false)
  220. } else if _toolbarType == .Page || _toolbarType == .LeftPanel || _toolbarType == .redact {
  221. bottomOffset.constant = 0
  222. childToolBarBox.isHidden = true
  223. self.delegate?.toolbarController?(self, heightOffsetChange: mainToolbarH, animated: false)
  224. } else {
  225. let childToolbarH = Self.childToolBarHeightValue
  226. bottomOffset.constant = childToolbarH.cgFloat
  227. childToolBarBox.isHidden = false
  228. self.delegate?.toolbarController?(self, heightOffsetChange: mainToolbarH + childToolbarH, animated: false)
  229. }
  230. }
  231. childToolBarView?.toolbarType = _toolbarType
  232. if self.toolbarType == .Annatiton {
  233. childToolBarView?.toolbar?.contentInset = .init(top: 0, left: 0, bottom: 0, right: 44)
  234. childToolBarView?.rightItemView.isHidden = false
  235. } else {
  236. childToolBarView?.toolbar?.contentInset = NSEdgeInsetsZero
  237. childToolBarView?.rightItemView.isHidden = true
  238. }
  239. childToolBarView?.reloadateToolbar()
  240. }
  241. get {
  242. return _toolbarType
  243. }
  244. }
  245. // MARK: -
  246. // MARK: Public Methods
  247. // 取消选中 [只是取消选中状态,不会执行具体的方法]
  248. public func cancelSelected(_ identifier: String) {
  249. if (isMainToolItem(identifier)) {
  250. self.findMainItem(identifier)?.isSelected = false
  251. return
  252. }
  253. self.findChildItem(identifier)?.isSelected = false
  254. }
  255. public func clickItem(_ identifier: String) {
  256. self.selectItem(identifier)
  257. }
  258. public func selectItem(_ identifier: String) {
  259. if self.isShowAllAnnotations == false {
  260. let itemIds = self._fetchItemIdsForHideNotes()
  261. if itemIds.contains(identifier) {
  262. NSSound.beep()
  263. return
  264. }
  265. }
  266. if (isMainToolItem(identifier)) {
  267. self.selectMainItem(identifier)
  268. return
  269. }
  270. if let parentItem = self.findItem(parentIdentifier(identifier)), parentItem.isSelected {
  271. if (self.trySelectChildItem(identifier)) { // 尝试去选子工具栏
  272. return
  273. }
  274. }
  275. // 当前主工具栏未开启
  276. let mainToolIdentifier = parentIdentifier(identifier)
  277. if (mainToolIdentifier.isEmpty) {
  278. return
  279. }
  280. // 找到主工具栏
  281. self.selectMainItem(mainToolIdentifier)
  282. DispatchQueue.main.async {
  283. // 再去选择子工具栏
  284. self.selectChildItem(identifier)
  285. }
  286. }
  287. public func findItem(_ identifier: String) -> KMToolbarItemView? {
  288. if (isMainToolItem(identifier)) {
  289. return self.findMainItem(identifier)
  290. }
  291. return self.findChildItem(identifier)
  292. }
  293. // MARK: -
  294. // MARK: private Methods
  295. private func selectMainItem(_ identifier: String) {
  296. if (self.mainToolBarView?.toolbarItems == nil) {
  297. return
  298. }
  299. var item: KMToolbarItemView?
  300. for (key, value) in self.mainToolBarView?.toolbarItems ?? [:] {
  301. if (key == identifier) {
  302. item = (value as? KMToolbarItemView)
  303. break
  304. }
  305. }
  306. // 主工具栏 item
  307. if let data = item {
  308. if (identifier == KMDocumentAnnotationToolbarItemIdentifier ||
  309. identifier == KMDocumentPageToolbarItemIdentifier ||
  310. identifier == KMDocumentConversonToolbarItemIdentifier ||
  311. identifier == KMDocumentEditToolbarItemIdentifier ||
  312. identifier == KMDocumentFormToolbarItemIdentifier ||
  313. identifier == KMDocumentFillSginToolbarItemIdentifier ||
  314. identifier == KMDocumentToolToolbarItemIdentifier) {
  315. self.mainToolBarView?.leftControllButtonAction(item: data.clickButton)
  316. } else if (identifier == KMRightControlToolbarItemIdentifier) {
  317. self.mainToolBarView?.itemAction(data)
  318. } else if (identifier == KMLeftControlToolbarItemIdentifier) {
  319. self.mainToolBarView?.itemAction(data)
  320. } else if identifier == KMDocumentRedactToolbarItemIdentifier {
  321. self.mainToolBarView?.itemAction(data)
  322. } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
  323. self.mainToolBarView?.itemAction(data)
  324. } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
  325. self.mainToolBarView?.itemAction(data)
  326. }
  327. return
  328. }
  329. }
  330. private func trySelectChildItem(_ identifier: String) -> Bool {
  331. // 子工具栏 item [当前主工具栏已开启]
  332. var item: KMToolbarItemView?
  333. if let items = self.childToolBarView?.toolbarItems, items.count > 0 {
  334. for (key, value) in items {
  335. if (key == identifier) {
  336. item = (value as? KMToolbarItemView)
  337. break
  338. }
  339. }
  340. // 子工具栏[找到]
  341. if (item != nil) {
  342. self.selectChildItem(identifier)
  343. return true
  344. }
  345. }
  346. return false
  347. }
  348. private func selectChildItem(_ identifier: String) {
  349. // 子工具栏 item [当前主工具栏已开启]
  350. var item: KMToolbarItemView?
  351. if let items = self.childToolBarView?.toolbarItems, items.count > 0 {
  352. for (key, value) in items {
  353. if (key == identifier) {
  354. item = (value as? KMToolbarItemView)
  355. break
  356. }
  357. }
  358. // 子工具栏[找到]
  359. if let data = item {
  360. if (identifier == KMToolbarMoveToolModeItemIdentifier ||
  361. identifier == KMToolbarMagnifyToolModeItemIdentifier ||
  362. identifier == KMToolbarSelectToolModeItemIdentifier ||
  363. identifier == KMToolbarZoomToSelectionItemIdentifier) {
  364. self.childToolBarView?.leftControllButtonAction(item: data.clickButton)
  365. } else if identifier == KMToolbarViewSettingIdentifier ||
  366. identifier == KMAnnotationImageToolbarItemIdentifier ||
  367. identifier == KMAnnotationTableToolbarItemIdentifier {
  368. self.childToolBarView?.itemAction(data)
  369. } else {
  370. self.childToolBarView?.changeAnnotationMode(item: data.clickButton)
  371. }
  372. }
  373. }
  374. }
  375. private func findMainItem(_ identifier: String) -> KMToolbarItemView? {
  376. if (self.mainToolBarView?.toolbarItems == nil) {
  377. return nil
  378. }
  379. var item: KMToolbarItemView?
  380. if (isMainToolItem(identifier)) {
  381. for (key, value) in self.mainToolBarView?.toolbarItems ?? [:] {
  382. if (key == identifier) {
  383. item = (value as? KMToolbarItemView)
  384. break
  385. }
  386. }
  387. return item
  388. }
  389. return nil
  390. }
  391. private func findChildItem(_ identifier: String) -> KMToolbarItemView? {
  392. if (self.childToolBarView?.toolbarItems == nil || self.childToolBarView!.toolbarItems.count == 0) {
  393. return nil
  394. }
  395. var item: KMToolbarItemView?
  396. for (key, value) in self.childToolBarView?.toolbarItems ?? [:] {
  397. if (key == identifier) {
  398. item = (value as? KMToolbarItemView)
  399. break
  400. }
  401. }
  402. return item
  403. }
  404. private func _fetchItemIdsForHideNotes() -> [String] {
  405. let itemIds = [KMDocumentEditToolbarItemIdentifier, KMDocumentFormToolbarItemIdentifier, KMDocumentFillSginToolbarItemIdentifier, KMDocumentRedactToolbarItemIdentifier, KMDocumentSignToolbarItemIdentifier]
  406. var annoIds = annotationToolIdentifiers
  407. if annoIds.contains(KMToolbarShowToolbarItemIdentifier) {
  408. annoIds.removeObject(KMToolbarShowToolbarItemIdentifier)
  409. }
  410. return annoIds + itemIds + editPDFItemIdentifiers + formToolIdentifiers + fillSignToolIdentifiers
  411. }
  412. func exitPageEdit() -> Void {
  413. if let data = self.mainToolBarView {
  414. resetToolbarViewController(data)
  415. exitPageEditToolbarViewController(data)
  416. }
  417. }
  418. func exitTextEdit() -> Void {
  419. secondaryToolBarBox.isHidden = true
  420. secondaryToolBarHeight.constant = 50
  421. bottomOffset.constant = 51
  422. childToolBarBox.isHidden = false
  423. self.delegate?.toolbarController?(self, heightOffsetChange: 102, animated: false)
  424. }
  425. func enterWatermarkAdjective(_ type: KMToolbarType, _ itemTitles: Array<Array<String>>) {
  426. self.toolbarType = .None
  427. }
  428. func exitWatermarkAdjective() {
  429. let topBarView = self.mainToolBarView?.toolbar?.subviews.last
  430. topBarView?.removeFromSuperview()
  431. }
  432. func fetchTopBarView() -> NSView? {
  433. let topBarView = self.mainToolBarView?.toolbar?.subviews.last
  434. if (topBarView == nil) {
  435. return nil
  436. }
  437. if (topBarView?.isKind(of: KMRedactTopToolBar.self) == true) {
  438. return topBarView
  439. }
  440. return nil
  441. }
  442. func enterRedact() {
  443. self.toolbarType = .None
  444. let topBarView = KMRedactTopToolBar()
  445. topBarView.frame = (self.mainToolBarView?.toolbar?.bounds) ?? .zero
  446. self.mainToolBarView?.toolbar?.addSubview(topBarView)
  447. topBarView.autoresizingMask = [.width, .height]
  448. topBarView.wantsLayer = true
  449. topBarView.layer?.backgroundColor = NSColor.white.cgColor
  450. topBarView.selectItem(0)
  451. self.delegate?.clickChildTool?(type: .redact, index: 4)
  452. topBarView.itemClick = { [weak self] index in
  453. self?.delegate?.clickChildTool?(type: .redact, index: index)
  454. }
  455. }
  456. func exitRedact() {
  457. let topBarView = self.mainToolBarView?.toolbar?.subviews.last
  458. if (topBarView == nil || topBarView?.isKind(of: KMRedactTopToolBar.self) == false) {
  459. return
  460. }
  461. topBarView?.removeFromSuperview()
  462. }
  463. // MARK: NSNotification
  464. @objc func selectedShapAnnotationChangeNotification(_ notification: Notification) -> Void {
  465. }
  466. @objc func PDFChangedNotification(_ notification: Notification) -> Void {
  467. }
  468. @objc func PDFTextEditPDFChangedNotification(_ notification: Notification) -> Void {
  469. }
  470. // MARK:
  471. func resetToolbarViewController(_ toolbarViewController: KMToolbarViewController) -> Void {
  472. self.toolbarType = .None
  473. self.mainToolBarView?.resetToolbar()
  474. self.mainViewController?.listView.annotationType = .unkown
  475. }
  476. func exitPageEditToolbarViewController(_ toolbarViewController: KMToolbarViewController) -> Void {
  477. }
  478. // MARK: item actions
  479. @objc func cropItemAction(sender: NSMenuItem) {
  480. if (sender.tag == 0) { /// 裁剪当前页面
  481. self.delegate?.clickChildTool?(type: .crop, index: 1)
  482. return
  483. }
  484. if (sender.tag == 1) { /// 裁剪所有页面
  485. self.delegate?.clickChildTool?(type: .crop, index: 2)
  486. return
  487. }
  488. /// 自定义裁剪区域
  489. self.delegate?.clickChildTool?(type: .crop, index: 3)
  490. }
  491. @objc func secureItemAction(sender: NSMenuItem) {
  492. var index: Int = 1
  493. if (sender.tag == 1) { /// 删除安全性设置
  494. index = 2
  495. }
  496. self.delegate?.clickChildTool?(type: .secure, index: index)
  497. }
  498. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  499. super.interfaceThemeDidChanged(appearance)
  500. self.mainToolBarView?.interfaceThemeDidChanged(appearance)
  501. self.childToolBarView?.interfaceThemeDidChanged(appearance)
  502. for item in self.childToolBarView?.toolbar?.items ?? [] {
  503. if item.itemIdentifier == KMToolbarHighlightAnnotationItemIdentifier {
  504. let color = KMPreference.shared.markupHighlightColor
  505. let imageV = KMNoteTypeImageView()
  506. item.image = imageV.noteTypeImage(withType: SKNHighlightString, color: color)
  507. } else if item.itemIdentifier == KMToolbarUnderlineAnnotationItemIdentifier {
  508. let color = KMPreference.shared.markupUnderlineColor
  509. let imageV = KMNoteTypeImageView()
  510. item.image = imageV.noteTypeImage(withType: SKNUnderlineString, color: color)
  511. } else if item.itemIdentifier == KMToolbarStrikeOutAnnotationItemIdentifier {
  512. let color = KMPreference.shared.markupStrikthroughColor
  513. let imageV = KMNoteTypeImageView()
  514. item.image = imageV.noteTypeImage(withType: SKNStrikeOutString, color: color)
  515. } else if item.itemIdentifier == KMToolbarSquigglyAnnotationItemIdentifier {
  516. let color = UserDefaults.standard.PDFListViewColor(forKey: CSquigglyNoteColorKey)
  517. let imageV = KMNoteTypeImageView()
  518. item.image = imageV.noteTypeImage(withType: CPDFAnnotation.kType.squiggly, color: color ?? NSColor(red: 252.0/255.0, green: 31.0/255.0, blue: 31.0/255.0, alpha: 1.0))
  519. } else if item.itemIdentifier == KMToolbarInkAnnotationItemIdentifier {
  520. let color = KMPreference.shared.markupPenColor
  521. let imageV = KMNoteTypeImageView()
  522. item.image = imageV.noteTypeImage(withType: SKNInkString, color: color)
  523. }
  524. }
  525. }
  526. }
  527. //MARK: Find Search
  528. extension KMToolbarController {
  529. func showFindBar() {
  530. self.findSearchView.isHidden = false
  531. let height: Float = self.fetchHeight(type: _toolbarType)
  532. self.delegate?.toolbarController?(self, heightOffsetChange: height, animated: false)
  533. self.findSearchView.findField.becomeFirstResponder()
  534. self.findSearchView.doneAction = { [weak self] view in
  535. self?.exitFindBar()
  536. }
  537. self.findSearchView.searchAction = { [weak self] view, searchString, forward in
  538. if let data = self?.mainToolBarView {
  539. self?.toolbarViewController(data, findSearchAction: searchString, forward: forward)
  540. }
  541. return true
  542. }
  543. self.findSearchView.showAllAction = { [weak self] view, searchString, forward in
  544. if let data = self?.mainToolBarView {
  545. self?.toolbarViewController(data, findSearchAllAction: searchString, forward: forward)
  546. }
  547. }
  548. }
  549. func showFindString(forward: Bool) {
  550. if let data = self.mainToolBarView {
  551. self.toolbarViewController(data, findSearchAction: self.findSearchView.findString ?? "", forward: forward)
  552. }
  553. }
  554. func showAllAction() {
  555. if let data = self.mainToolBarView {
  556. self.toolbarViewController(data, findSearchAllAction: self.findSearchView.findString ?? "", forward: true)
  557. }
  558. }
  559. func exitFindBar() {
  560. self.findSearchView.isHidden = true
  561. let height: Float = self.fetchHeight(type: _toolbarType, isShow: false)
  562. self.delegate?.toolbarController?(self, heightOffsetChange: height, animated: false)
  563. }
  564. func fetchHeight(type: KMToolbarViewType, isShow: Bool = true) -> Float {
  565. var height: Float = 0.0
  566. let mainToolbarH = self.mainToolBarisVisable ? Self.mainToolBarHeight : 0
  567. let childToolbarH = Self.childToolBarHeightValue
  568. let findBarH = Self.findBarHeight
  569. if isShow {
  570. if _toolbarType == .None {
  571. bottomOffset.constant = findBarH.cgFloat
  572. height = mainToolbarH
  573. } else if _toolbarType == .Page || _toolbarType == .LeftPanel || _toolbarType == .redact {
  574. bottomOffset.constant = findBarH.cgFloat
  575. height = mainToolbarH
  576. } else {
  577. bottomOffset.constant = childToolbarH.cgFloat + findBarH.cgFloat
  578. height = mainToolbarH + childToolbarH
  579. }
  580. height = height + findBarH
  581. } else {
  582. if _toolbarType == .None {
  583. bottomOffset.constant = 0
  584. height = mainToolbarH
  585. } else if _toolbarType == .Page || _toolbarType == .LeftPanel || _toolbarType == .redact {
  586. bottomOffset.constant = 0
  587. height = mainToolbarH
  588. } else {
  589. bottomOffset.constant = childToolbarH.cgFloat
  590. height = mainToolbarH + childToolbarH
  591. }
  592. }
  593. return height
  594. }
  595. }
  596. extension KMToolbarController: KMToolbarViewControllerDelegate {
  597. func changeAnnotationModeAction(item: KMToolbarClickButton) {
  598. let type = CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown
  599. if (type.isAdvanced() == false) {
  600. if self.toolbarType == .Magnify || self.toolbarType == .Move || self.toolbarType == .Select || self.toolbarType == .SelectZoom {
  601. self.toolbarType = .Annatiton
  602. }
  603. self.delegate?.changeAnnotationModeAction?(item: item)
  604. return
  605. }
  606. // 高级功能
  607. Task { @MainActor in
  608. //文字编辑 图片编辑 选中按钮逻辑(只能同时选中其中一个)
  609. if type == .addText || type == .addImage {
  610. let boxItem = item.clickObject as? KMToolbarItemView
  611. if let data = boxItem {
  612. if self.lastChildItemBox != data {
  613. self.lastChildItemBox.isSelected = false
  614. data.isSelected = true
  615. } else {
  616. data.isSelected = !data.isSelected
  617. }
  618. self.lastChildItemBox = data
  619. }
  620. }
  621. if self.toolbarType == .Magnify || self.toolbarType == .Move || self.toolbarType == .Select || self.toolbarType == .SelectZoom {
  622. self.toolbarType = .Annatiton
  623. }
  624. self.trackEvent(type: type)
  625. self.delegate?.changeAnnotationModeAction?(item: item)
  626. }
  627. }
  628. func trackEvent(type: CAnnotationType) {
  629. var eventStr = "Btn_SubTbr_Fill&Sign_Check"
  630. switch type {
  631. case .signTure:
  632. eventStr = "Btn_SubTbr_Fill&Sign_Check"
  633. case .signFalse:
  634. eventStr = "Btn_SubTbr_Fill&Sign_X"
  635. case .signDate:
  636. eventStr = "Btn_SubTbr_Fill&Sign_Date"
  637. case .signDot:
  638. eventStr = "Btn_SubTbr_Fill&Sign_Dot"
  639. case .signCircle:
  640. eventStr = "Btn_SubTbr_Fill&Sign_Circle"
  641. case .signLine:
  642. eventStr = "Btn_SubTbr_Fill&Sign_Line"
  643. default:
  644. eventStr = ""
  645. break
  646. }
  647. if eventStr.count > 1{
  648. FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Fill&Sign", withProperties: ["SubTbr_Btn": eventStr])
  649. }
  650. }
  651. func toolbarViewController(_ viewController: KMToolbarViewController, clickMode toolMode: KMToolbarViewType, toolbar toolbarItem: KMToolbarItemView, _ pages: [Int]) {
  652. let beforeModel = KMToolbarViewType(rawValue: self.lastItemBox.clickButton.tag) ?? .None
  653. if toolMode != .redact { // 标记秘文
  654. let mainC = self.delegate as? KMMainViewController
  655. var control: KMPDFRedactViewController?
  656. for childC in mainC?.children ?? [] {
  657. if (childC.isKind(of: KMPDFRedactViewController.self)) {
  658. control = (childC as! KMPDFRedactViewController)
  659. break
  660. }
  661. }
  662. if let annos = control?.redactPdfView.newAddAnnotation, annos.count > 0 {
  663. let alert = NSAlert()
  664. alert.informativeText = NSLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", comment: "")
  665. alert.addButton(withTitle: NSLocalizedString("Exit", comment: ""))
  666. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  667. let resp = alert.runModal()
  668. if resp != .alertFirstButtonReturn { // 取消
  669. return
  670. }
  671. control?.redactPdfView.newAddAnnotation.removeAll()
  672. }
  673. }
  674. if self.lastItemBox != nil {
  675. if (toolbarItem.isSelected && toolMode.isToolMode()) {
  676. // no nothings
  677. } else {
  678. self.lastItemBox.isSelected = false
  679. }
  680. }
  681. if self.lastChildItemBox != nil {
  682. if toolMode == .editPDF {
  683. if !self.lastItemBox.isSelected {
  684. self.lastChildItemBox.isSelected = false
  685. }
  686. }
  687. }
  688. if toolMode != .Magnify && toolMode != .Move && toolMode != .Select && toolMode != .SelectZoom && toolMode != .LeftPanel && toolMode != .RightPanel {
  689. if(toolMode == self.toolbarType) {
  690. toolbarItem.isSelected = false
  691. } else {
  692. toolbarItem.isSelected = true
  693. self.lastItemBox = toolbarItem
  694. self.trackEvent(toolType: toolMode)
  695. }
  696. } else {
  697. if(toolMode != self.toolbarType && toolMode != .LeftPanel) {
  698. let item : KMToolbarItemView = (self.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
  699. item.isSelected = true
  700. self.lastItemBox = item
  701. if toolMode == .Select {
  702. FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Tools", withProperties: ["SubTbr_Btn" : "Btn_SubTbr_Tools_ContentSelection"])
  703. }
  704. if toolMode == .SelectZoom {
  705. FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Tools", withProperties: ["SubTbr_Btn" : "Btn_SubTbr_Tools_Zoom"])
  706. }
  707. } else if (toolMode == .LeftPanel) {
  708. if(toolMode == self.toolbarType) {
  709. toolbarItem.isSelected = false
  710. } else {
  711. toolbarItem.isSelected = true
  712. }
  713. }
  714. }
  715. self.toolbarType = toolMode
  716. self.delegate?.mainToolDidClicked?(self, beforeModel, toolMode, toolbarItem, pages)
  717. }
  718. func trackEvent(toolType type: KMToolbarViewType) -> Void {
  719. if (type == .Annatiton) {
  720. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_Tools"])
  721. } else if (type == .editPDF) {
  722. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_EditPDF"])
  723. } else if (type == .Page) {
  724. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_PageEdit"])
  725. } else if (type == .Conversion) {
  726. } else if (type == .Tool) {
  727. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_Editor"])
  728. } else if (type == .Conversion) {
  729. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_Converter"])
  730. } else if (type == .Form) {
  731. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_Form"])
  732. } else if (type == .FillSign) {
  733. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_Fill & Sign"])
  734. } else if (type == .redact) {
  735. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn" : "Btn_Tbr_Redact"])
  736. }
  737. }
  738. func showPDFLayoutModeAction(show: Bool) {
  739. self.delegate?.showPDFLayoutModeAction?(show: show)
  740. }
  741. func toolbarViewController(_ viewController: KMToolbarViewController, clickChaildToolType: KMToolbarType, toolbar toolbarItem: KMToolbarItemView) {
  742. if (clickChaildToolType == .crop) {
  743. let titles = [NSLocalizedString("Crop Current Page - White Margins", comment: ""), NSLocalizedString("Crop All Pages - Auto", comment: "")]
  744. let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(titles)
  745. let createFilePopover: NSPopover = NSPopover.init()
  746. createFilePopover.contentViewController = vc
  747. createFilePopover.animates = true
  748. createFilePopover.behavior = .transient
  749. createFilePopover.setValue(true, forKey: "shouldHideAnchor")
  750. createFilePopover.show(relativeTo: NSZeroRect, of: toolbarItem, preferredEdge: .maxY)
  751. self.popover = createFilePopover
  752. vc.downCallback = { [weak self] (downEntered: Bool, count: String) -> Void in
  753. self?.popover?.close()
  754. self?.popover = nil
  755. if downEntered {
  756. if (count == titles.first) {
  757. self?.delegate?.clickChildTool?(type: .crop, index: 1)
  758. } else {
  759. self?.delegate?.clickChildTool?(type: .crop, index: 2)
  760. }
  761. }
  762. }
  763. } else if (clickChaildToolType == .bates || clickChaildToolType == .headerAndFooter || clickChaildToolType == .background || clickChaildToolType == .watermark) {
  764. toolbarItem.isSelected = false
  765. self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
  766. } else if (clickChaildToolType == .redact) {
  767. toolbarItem.isSelected = false
  768. self.enterRedact()
  769. } else if (clickChaildToolType == .compress) {
  770. self.delegate?.clickChildTool?(type: .compress, index: 0)
  771. } else if (clickChaildToolType == .secure) {
  772. // toolbarItem.isSelected = fals
  773. let titles = [NSLocalizedString("Set Passwords", comment: ""), NSLocalizedString("Remove Security", comment: "")]
  774. let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(titles)
  775. let createFilePopover: NSPopover = NSPopover.init()
  776. createFilePopover.contentViewController = vc
  777. createFilePopover.animates = true
  778. createFilePopover.behavior = .transient
  779. createFilePopover.setValue(true, forKey: "shouldHideAnchor")
  780. createFilePopover.show(relativeTo: CGRect(x: toolbarItem.bounds.origin.x, y: 10, width: toolbarItem.bounds.size.width, height: toolbarItem.bounds.size.height), of: toolbarItem, preferredEdge: .minY)
  781. vc.downCallback = { [weak self] (downEntered: Bool, count: String) -> Void in
  782. if downEntered {
  783. if (count == titles.first) {
  784. self?.delegate?.clickChildTool?(type: .secure, index: 1)
  785. } else {
  786. self?.delegate?.clickChildTool?(type: .secure, index: 2)
  787. }
  788. }
  789. }
  790. } else if ((KMToolbarType.word.rawValue ... KMToolbarType.conversion_imageToPDF.rawValue).contains(clickChaildToolType.rawValue)) { /// 转档
  791. self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
  792. } else if (clickChaildToolType == .merge) {
  793. self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
  794. }
  795. }
  796. func toolbarViewController(_ viewController: KMToolbarViewController, zoomModel selectedTag: Int) {
  797. self.delegate?.toolbarViewController?(viewController, zoomModel: selectedTag)
  798. }
  799. func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String) {
  800. self.delegate?.toolbarViewController?(viewController, zoomSting: zoomSting)
  801. }
  802. func changePDFViewZoomInAction() {
  803. self.delegate?.changePDFViewZoomInAction?()
  804. }
  805. func changePDFViewZoomOutAction() {
  806. self.delegate?.changePDFViewZoomOutAction?()
  807. }
  808. func changePDFViewGotoNextPageAction() {
  809. self.delegate?.changePDFViewGotoNextPageAction?()
  810. }
  811. func changePDFViewGoToPreviousPageAction() {
  812. self.delegate?.changePDFViewGoToPreviousPageAction?()
  813. }
  814. func changePDFViewGotoBackAction() {
  815. self.delegate?.changePDFViewGotoBackAction?()
  816. }
  817. func changePDFViewGoToForwardAction() {
  818. self.delegate?.changePDFViewGoToForwardAction?()
  819. }
  820. func aiTranslationPDFFileAction() {
  821. self.delegate?.aiTranslationPDFFileAction?()
  822. }
  823. func toolbarViewController(_ viewController: KMToolbarViewController, shareAction toolbarItem: KMToolbarItemView) {
  824. self.delegate?.toolbarViewController?(viewController, shareAction: toolbarItem)
  825. }
  826. func toolbarViewController(_ viewController: KMToolbarViewController, shareDocument item: NSMenuItem) {
  827. self.delegate?.toolbarViewController?(viewController, shareDocument: item)
  828. }
  829. func toolbarViewController(_ viewController: KMToolbarViewController, shareFlatten item: NSMenuItem) {
  830. self.delegate?.toolbarViewController?(viewController, shareFlatten: item)
  831. }
  832. func toolbarViewController(_ viewController: KMToolbarViewController, shareOriginalPDF item: NSMenuItem) {
  833. self.delegate?.toolbarViewController?(viewController, shareOriginalPDF: item)
  834. }
  835. func toolbarViewController(_ viewController: KMToolbarViewController, scanOCRModel selectedTag: Int) {
  836. self.delegate?.toolbarViewController?(viewController, scanOCRModel: selectedTag)
  837. }
  838. func toolbarViewController(_ viewController: KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView) {
  839. let itemIdentifier = toolbarItem.itemIdentifier
  840. if itemIdentifier != KMRightControlToolbarItemIdentifier {
  841. if self.lastItemBox != nil {
  842. if (toolbarItem.isSelected) {
  843. // no nothings
  844. } else {
  845. let p_itemIdentifier = parentIdentifier(itemIdentifier ?? "")
  846. if p_itemIdentifier != self.lastItemBox.itemIdentifier {
  847. self.lastItemBox.isSelected = false
  848. }
  849. }
  850. }
  851. }
  852. if toolbarItem.itemIdentifier != KMDocumentRedactToolbarItemIdentifier { // 标记秘文
  853. let mainC = self.delegate as? KMMainViewController
  854. var control: KMPDFRedactViewController?
  855. for childC in mainC?.children ?? [] {
  856. if (childC.isKind(of: KMPDFRedactViewController.self)) {
  857. control = (childC as! KMPDFRedactViewController)
  858. break
  859. }
  860. }
  861. if let annos = control?.redactPdfView.newAddAnnotation, annos.count > 0 {
  862. let alert = NSAlert()
  863. alert.informativeText = NSLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", comment: "")
  864. alert.addButton(withTitle: NSLocalizedString("Exit", comment: ""))
  865. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  866. let resp = alert.runModal()
  867. if resp != .alertFirstButtonReturn { // 取消
  868. return
  869. }
  870. control?.redactPdfView.newAddAnnotation.removeAll()
  871. }
  872. }
  873. self.delegate?.toolbarViewController?(viewController, itemDidClick: toolbarItem)
  874. }
  875. func toolbarViewController(_ viewController: KMToolbarViewController, searchAction searchString: String, forward: Bool) {
  876. self.delegate?.toolbarViewController?(viewController, searchAction: searchString, forward: forward)
  877. }
  878. func toolbarViewController(_ viewController: KMToolbarViewController, findSearchAction searchString: String, forward: Bool) {
  879. self.delegate?.toolbarViewController?(viewController, findSearchAction: searchString, forward: forward)
  880. }
  881. func toolbarViewController(_ viewController: KMToolbarViewController, findSearchAllAction searchString: String, forward: Bool) {
  882. self.delegate?.toolbarViewController?(viewController, findSearchAllAction: searchString, forward: forward)
  883. }
  884. func toolbarViewController(_ viewController: KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?) {
  885. let itemIdentifier = toolbarItem.itemIdentifier
  886. if itemIdentifier != KMRightControlToolbarItemIdentifier {
  887. if self.lastItemBox != nil {
  888. if (toolbarItem.isSelected) {
  889. // no nothings
  890. } else {
  891. let p_itemIdentifier = parentIdentifier(itemIdentifier ?? "")
  892. if p_itemIdentifier != self.lastItemBox.itemIdentifier {
  893. self.lastItemBox.isSelected = false
  894. }
  895. }
  896. }
  897. }
  898. if toolbarItem.itemIdentifier != KMDocumentRedactToolbarItemIdentifier { // 标记秘文
  899. let mainC = self.delegate as? KMMainViewController
  900. var control: KMPDFRedactViewController?
  901. for childC in mainC?.children ?? [] {
  902. if (childC.isKind(of: KMPDFRedactViewController.self)) {
  903. control = (childC as! KMPDFRedactViewController)
  904. break
  905. }
  906. }
  907. if let annos = control?.redactPdfView.newAddAnnotation, annos.count > 0 {
  908. let alert = NSAlert()
  909. alert.informativeText = NSLocalizedString("There are unapplied redactions in this file. Exit will not save redaction.", comment: "")
  910. alert.addButton(withTitle: NSLocalizedString("Exit", comment: ""))
  911. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  912. let resp = alert.runModal()
  913. if resp != .alertFirstButtonReturn { // 取消
  914. return
  915. }
  916. control?.redactPdfView.newAddAnnotation.removeAll()
  917. }
  918. }
  919. self.delegate?.toolbarViewController?(viewController, menuItemDidClick: toolbarItem, index: index, info: info)
  920. }
  921. func toolbarViewController(_ viewController: KMToolbarViewController, viewItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?) {
  922. self.delegate?.toolbarViewController?(viewController, viewItemDidClick: toolbarItem, index: index, info: info)
  923. }
  924. }
  925. extension KMToolbarController {
  926. func updataItemVisible() {
  927. guard let isCompareModel = self.mainViewController?.isCompareModel else { return }
  928. if isCompareModel {
  929. self.toolbarType = .None
  930. self.mainToolBarView?.isEnable(isEnable: false)
  931. } else {
  932. self.mainToolBarView?.isEnable()
  933. }
  934. }
  935. }