KMToolbarController.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. //
  2. // KMToolbarController.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2022/12/29.
  6. //
  7. import Cocoa
  8. @objc protocol KMToolbarControllerDelegate {
  9. @objc optional func toolbarController(_ viewController: KMToolbarController, heightOffsetChange heightOffset: Float)
  10. @objc optional func changeAnnotationModeAction(item:KMToolbarClickButton)
  11. @objc optional func showPDFLayoutModeAction(show:Bool)
  12. @objc optional func clickChildTool(type: KMToolbarType, index: Int)
  13. @objc optional func changePDFViewZoomModelAction(selectedTag:Int)
  14. @objc optional func changePDFViewZoomInAction()
  15. @objc optional func changePDFViewZoomOutAction()
  16. @objc optional func changePDFViewGotoNextPageAction()
  17. @objc optional func changePDFViewGoToPreviousPageAction()
  18. @objc optional func showPDFViewPrintViewController()
  19. @objc optional func aiTranslationPDFFileAction()
  20. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
  21. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
  22. @objc optional func mainToolDidClicked(_ toolController: KMToolbarController, _ type: KMToolbarViewType, _ item: KMToolBoxItem, _ pages: [Int])
  23. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
  24. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
  25. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareOriginalPDF item:NSMenuItem)
  26. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
  27. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, rightPanel toolbarItem: KMToolBoxItem)
  28. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, leftPanel toolbarItem: KMToolBoxItem)
  29. }
  30. class KMToolbarController: NSViewController {
  31. @IBOutlet weak var mainToolBarBox: NSBox!
  32. @IBOutlet weak var childToolBarBox: NSBox!
  33. @IBOutlet weak var secondaryToolBarBox: NSBox!
  34. @IBOutlet weak var mainToolBarHeight: NSLayoutConstraint!
  35. @IBOutlet weak var childToolBarHeight: NSLayoutConstraint!
  36. @IBOutlet weak var secondaryToolBarHeight: NSLayoutConstraint!
  37. @IBOutlet weak var bottomOffset: NSLayoutConstraint!
  38. var mainToolBarView: KMToolbarViewController?
  39. var childToolBarView: KMToolbarViewController?
  40. var _toolbarType : KMToolbarViewType = KMToolbarViewType.None
  41. var mainViewController: KMMainViewController?
  42. open weak var delegate: KMToolbarControllerDelegate?
  43. var toolbarItems : [NSToolbarItem.Identifier : Any] = [:]
  44. var listView : CPDFListView?
  45. var lastItemBox : KMToolBoxItem = KMToolBoxItem()
  46. var popover: NSPopover?
  47. // 是否显示所有注释
  48. private var _isShowAllAnnotations = true
  49. // 是否显示所有注释
  50. var isShowAllAnnotations: Bool {
  51. get {
  52. return _isShowAllAnnotations
  53. }
  54. set {
  55. _isShowAllAnnotations = newValue
  56. self.childToolBarView?.isShowAllAnnotations = newValue
  57. self.findChildItem(KMToolbarShowToolbarItemIdentifier)?.isSelected = !newValue
  58. }
  59. }
  60. override func viewDidLoad() {
  61. super.viewDidLoad()
  62. // Do view setup here.
  63. updateViewColor()
  64. mainToolBarView = KMToolbarViewController.init()
  65. mainToolBarView?.view.wantsLayer = true
  66. mainToolBarView?.view.layer?.backgroundColor = NSColor(hex: "#F7F8FA").cgColor
  67. mainToolBarBox.contentView = mainToolBarView?.view
  68. mainToolBarView?.view.frame = mainToolBarBox.frame
  69. mainToolBarView?.delegate = self
  70. mainToolBarView?.view.autoresizingMask = [.width, .height]
  71. mainToolBarView?.pdfView = self.listView!
  72. childToolBarView = KMToolbarViewController.init()
  73. childToolBarView?.view.wantsLayer = true
  74. childToolBarView?.view.layer?.backgroundColor = NSColor(hex: "#F7F8FA").cgColor
  75. childToolBarBox.contentView = childToolBarView?.view
  76. childToolBarView?.view.frame = childToolBarBox.frame
  77. childToolBarView?.delegate = self
  78. childToolBarView?.view.autoresizingMask = [.width, .height]
  79. childToolBarView?.pdfView = self.listView!
  80. toolbarType = .None
  81. mainToolBarView?.toolbarType = .Main
  82. mainToolBarView?.reloadateToolbar()
  83. addObserverForAppearanceChange()
  84. NotificationCenter.default.addObserver(self, selector: #selector(selectedShapAnnotationChangeNotification(_:)), name: NSNotification.Name.init(rawValue: "KMSelectedShapAnnotationChangeNotification"), object: nil)
  85. NotificationCenter.default.addObserver(self, selector: #selector(PDFChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "PDFChangedNotification"), object: nil)
  86. NotificationCenter.default.addObserver(self, selector: #selector(PDFTextEditPDFChangedNotification(_:)), name: NSNotification.Name.init(rawValue: "KMPDFTextEditPDFChangedNotification"), object: nil)
  87. }
  88. // MARK:
  89. func updateViewColor() -> Void {
  90. }
  91. // MARK: Setter&Getter
  92. var toolbarType: KMToolbarViewType {
  93. set {
  94. if newValue == _toolbarType {
  95. if newValue == .Move || newValue == .Magnify || newValue == .Select || newValue == .SelectZoom {
  96. _toolbarType = .Annatiton
  97. } else {
  98. _toolbarType = .None
  99. }
  100. } else {
  101. _toolbarType = newValue
  102. }
  103. secondaryToolBarBox.isHidden = true
  104. secondaryToolBarHeight.constant = 51
  105. if _toolbarType == .None {
  106. bottomOffset.constant = 0
  107. childToolBarBox.isHidden = true
  108. self.delegate?.toolbarController?(self, heightOffsetChange: 40)
  109. } else if _toolbarType == .Page || _toolbarType == .LeftPanel {
  110. bottomOffset.constant = 0
  111. childToolBarBox.isHidden = true
  112. self.delegate?.toolbarController?(self, heightOffsetChange: 40)
  113. } else {
  114. bottomOffset.constant = 41
  115. childToolBarBox.isHidden = false
  116. self.delegate?.toolbarController?(self, heightOffsetChange: 81)
  117. }
  118. childToolBarView?.toolbarType = _toolbarType
  119. childToolBarView?.reloadateToolbar()
  120. }
  121. get {
  122. return _toolbarType
  123. }
  124. }
  125. // MARK: Dark&Light
  126. func addObserverForAppearanceChange() -> Void {
  127. }
  128. // MARK: -
  129. // MARK: Public Methods
  130. // 取消选中 [只是取消选中状态,不会执行具体的方法]
  131. public func cancelSelected(_ identifier: String) {
  132. if (isMainToolItem(identifier)) {
  133. self.findMainItem(identifier)?.isSelected = false
  134. return
  135. }
  136. self.findChildItem(identifier)?.isSelected = false
  137. }
  138. public func clickItem(_ identifier: String) {
  139. self.selectItem(identifier)
  140. }
  141. public func selectItem(_ identifier: String) {
  142. if (isMainToolItem(identifier)) {
  143. self.selectMainItem(identifier)
  144. return
  145. }
  146. // 尝试去选子工具栏
  147. if (self.trySelectChildItem(identifier)) { // 当前主工具栏已开启
  148. return
  149. }
  150. // 当前主工具栏未开启
  151. let mainToolIdentifier = parentIdentifier(identifier)
  152. if (mainToolIdentifier.isEmpty) {
  153. return
  154. }
  155. // 找到主工具栏
  156. self.selectMainItem(mainToolIdentifier)
  157. DispatchQueue.main.async {
  158. // 再去选择子工具栏
  159. self.selectChildItem(identifier)
  160. }
  161. }
  162. // MARK: -
  163. // MARK: private Methods
  164. private func selectMainItem(_ identifier: String) {
  165. if (self.mainToolBarView?.toolbarItems == nil) {
  166. return
  167. }
  168. var item: KMToolBoxItem?
  169. for (key, value) in self.mainToolBarView!.toolbarItems {
  170. if (key == identifier) {
  171. item = (value as! KMToolBoxItem)
  172. break
  173. }
  174. }
  175. // 主工具栏 item
  176. if (item != nil) {
  177. if (identifier == KMDocumentAnnotationToolbarItemIdentifier ||
  178. identifier == KMDocumentPageToolbarItemIdentifier ||
  179. identifier == KMDocumentConversonToolbarItemIdentifier ||
  180. identifier == KMDocumentScanOCRToolbarItemIdentifier ||
  181. identifier == KMDocumentEditToolbarItemIdentifier ||
  182. identifier == KMDocumentFormToolbarItemIdentifier ||
  183. identifier == KMDocumentFillSginToolbarItemIdentifier ||
  184. identifier == KMDocumentToolToolbarItemIdentifier) {
  185. self.mainToolBarView?.leftControllButtonAction(item: item!.clickButton)
  186. } else if (identifier == KMRightControlToolbarItemIdentifier) {
  187. self.mainToolBarView?.rightPanelControllButtonAction(item: item!.clickButton)
  188. } else if (identifier == KMLeftControlToolbarItemIdentifier) {
  189. item?.isSelected = !item!.isSelected
  190. self.delegate?.toolbarViewController?(self.mainToolBarView!, leftPanel: item!)
  191. }
  192. return
  193. }
  194. }
  195. private func trySelectChildItem(_ identifier: String) -> Bool {
  196. // 子工具栏 item [当前主工具栏已开启]
  197. var item: KMToolBoxItem?
  198. if (self.childToolBarView?.toolbarItems != nil && self.childToolBarView!.toolbarItems.count > 0) {
  199. for (key, value) in self.childToolBarView!.toolbarItems {
  200. if (key == identifier) {
  201. item = (value as! KMToolBoxItem)
  202. break
  203. }
  204. }
  205. // 子工具栏[找到]
  206. if (item != nil) {
  207. self.selectChildItem(identifier)
  208. return true
  209. }
  210. }
  211. return false
  212. }
  213. private func selectChildItem(_ identifier: String) {
  214. // 子工具栏 item [当前主工具栏已开启]
  215. var item: KMToolBoxItem?
  216. if (self.childToolBarView?.toolbarItems != nil && self.childToolBarView!.toolbarItems.count > 0) {
  217. for (key, value) in self.childToolBarView!.toolbarItems {
  218. if (key == identifier) {
  219. item = (value as! KMToolBoxItem)
  220. break
  221. }
  222. }
  223. // 子工具栏[找到]
  224. if (item != nil) {
  225. if (identifier == KMToolbarMoveToolModeItemIdentifier ||
  226. identifier == KMToolbarMagnifyToolModeItemIdentifier ||
  227. identifier == KMToolbarSelectToolModeItemIdentifier ||
  228. identifier == KMToolbarZoomToSelectionItemIdentifier) {
  229. self.childToolBarView?.leftControllButtonAction(item: item!.clickButton)
  230. } else {
  231. self.childToolBarView?.changeAnnotationMode(item: item!.clickButton)
  232. }
  233. }
  234. }
  235. }
  236. private func findMainItem(_ identifier: String) -> KMToolBoxItem? {
  237. if (self.mainToolBarView?.toolbarItems == nil) {
  238. return nil
  239. }
  240. var item: KMToolBoxItem?
  241. if (isMainToolItem(identifier)) {
  242. for (key, value) in self.mainToolBarView!.toolbarItems {
  243. if (key == identifier) {
  244. item = (value as! KMToolBoxItem)
  245. break
  246. }
  247. }
  248. return item
  249. }
  250. return nil
  251. }
  252. private func findChildItem(_ identifier: String) -> KMToolBoxItem? {
  253. if (self.childToolBarView?.toolbarItems == nil || self.childToolBarView!.toolbarItems.count == 0) {
  254. return nil
  255. }
  256. var item: KMToolBoxItem?
  257. for (key, value) in self.childToolBarView!.toolbarItems {
  258. if (key == identifier) {
  259. item = (value as! KMToolBoxItem)
  260. break
  261. }
  262. }
  263. return item
  264. }
  265. func exitPageEdit() -> Void {
  266. resetToolbarViewController(mainToolBarView!)
  267. exitPageEditToolbarViewController(mainToolBarView!)
  268. }
  269. func exitTextEdit() -> Void {
  270. secondaryToolBarBox.isHidden = true
  271. secondaryToolBarHeight.constant = 50
  272. bottomOffset.constant = 51
  273. childToolBarBox.isHidden = false
  274. self.delegate?.toolbarController?(self, heightOffsetChange: 102)
  275. }
  276. func enterWatermarkAdjective(_ type: KMToolbarType, _ itemTitles: Array<Array<String>>) {
  277. self.toolbarType = .None
  278. let topBarView = KMWatermarkAdjectiveTopBarView()
  279. topBarView.frame = (self.mainToolBarView?.toolbar.bounds)!
  280. self.mainToolBarView?.toolbar.addSubview(topBarView)
  281. topBarView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  282. topBarView.wantsLayer = true
  283. topBarView.layer?.backgroundColor = NSColor.white.cgColor
  284. topBarView.isCanApply(can: false)
  285. var itemModels: Array<Array<KMWatermarkAdjectiveTopBarItemModel>> = []
  286. for items in itemTitles {
  287. var array: Array<KMWatermarkAdjectiveTopBarItemModel> = []
  288. for title in items {
  289. let model = KMWatermarkAdjectiveTopBarItemModel()
  290. model.iconName = ""
  291. model.itemTitle = title
  292. array.append(model)
  293. }
  294. itemModels.append(array)
  295. }
  296. topBarView.initItemData(itemArrays: itemModels)
  297. topBarView.cancelClick = {
  298. [unowned self] in
  299. self.delegate?.clickChildTool!(type: type, index: 1)
  300. }
  301. topBarView.applyClick = {
  302. [unowned self] in
  303. self.delegate?.clickChildTool!(type: type, index: 2)
  304. }
  305. topBarView.itemClick = {
  306. [unowned self] (section: Int, item: Int) -> () in
  307. self.delegate?.clickChildTool!(type: type, index: 3+item)
  308. }
  309. }
  310. func exitWatermarkAdjective() {
  311. let topBarView = self.mainToolBarView?.toolbar.subviews.last
  312. if (topBarView == nil || topBarView?.isKind(of: KMWatermarkAdjectiveTopBarView.self) == false) {
  313. return
  314. }
  315. topBarView?.removeFromSuperview()
  316. }
  317. func fetchTopBarView() -> NSView? {
  318. let topBarView = self.mainToolBarView?.toolbar.subviews.last
  319. if (topBarView == nil) {
  320. return nil
  321. }
  322. if (topBarView?.isKind(of: KMWatermarkAdjectiveTopBarView.self) == true) {
  323. return topBarView
  324. }
  325. if (topBarView?.isKind(of: KMRedactTopToolBar.self) == true) {
  326. return topBarView
  327. }
  328. return nil
  329. }
  330. func enterRedact() {
  331. self.toolbarType = .None
  332. let topBarView = KMRedactTopToolBar()
  333. topBarView.frame = (self.mainToolBarView?.toolbar.bounds)!
  334. self.mainToolBarView?.toolbar.addSubview(topBarView)
  335. topBarView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
  336. topBarView.wantsLayer = true
  337. topBarView.layer?.backgroundColor = NSColor.white.cgColor
  338. topBarView.selectItem(0)
  339. self.delegate?.clickChildTool!(type: .redact, index: 4)
  340. topBarView.itemClick = { [weak self] index in
  341. self!.delegate?.clickChildTool!(type: .redact, index: index)
  342. }
  343. }
  344. func exitRedact() {
  345. let topBarView = self.mainToolBarView?.toolbar.subviews.last
  346. if (topBarView == nil || topBarView?.isKind(of: KMRedactTopToolBar.self) == false) {
  347. return
  348. }
  349. topBarView?.removeFromSuperview()
  350. }
  351. // MARK: NSNotification
  352. @objc func selectedShapAnnotationChangeNotification(_ notification: Notification) -> Void {
  353. }
  354. @objc func PDFChangedNotification(_ notification: Notification) -> Void {
  355. }
  356. @objc func PDFTextEditPDFChangedNotification(_ notification: Notification) -> Void {
  357. }
  358. // MARK:
  359. func resetToolbarViewController(_ toolbarViewController: KMToolbarViewController) -> Void {
  360. self.toolbarType = .None
  361. self.mainToolBarView?.resetToolbar()
  362. self.mainViewController?.listView.annotationType = .unkown
  363. }
  364. func exitPageEditToolbarViewController(_ toolbarViewController: KMToolbarViewController) -> Void {
  365. }
  366. // MARK: item actions
  367. @objc func cropItemAction(sender: NSMenuItem) {
  368. if (sender.tag == 0) { /// 裁剪当前页面
  369. self.delegate?.clickChildTool!(type: .crop, index: 1)
  370. return
  371. }
  372. if (sender.tag == 1) { /// 裁剪所有页面
  373. self.delegate?.clickChildTool!(type: .crop, index: 2)
  374. return
  375. }
  376. /// 自定义裁剪区域
  377. self.delegate?.clickChildTool!(type: .crop, index: 3)
  378. }
  379. @objc func secureItemAction(sender: NSMenuItem) {
  380. var index: Int = 1
  381. if (sender.tag == 1) { /// 删除安全性设置
  382. index = 2
  383. }
  384. self.delegate?.clickChildTool?(type: .secure, index: index)
  385. }
  386. }
  387. extension KMToolbarController: KMToolbarViewControllerDelegate {
  388. func changeAnnotationModeAction(item: KMToolbarClickButton) {
  389. Task { @MainActor in
  390. let type = CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown
  391. if (type == .link || type == .stamp || type == .signSignature) {
  392. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  393. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  394. return
  395. }
  396. }
  397. if (type == .signText || type == .signTure || type == .signFalse || type == .signCircle || type == .signLine || type == .signDot || type == .signDate) {
  398. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  399. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  400. return
  401. }
  402. }
  403. if self.toolbarType == .Magnify || self.toolbarType == .Move || self.toolbarType == .Select || self.toolbarType == .SelectZoom {
  404. self.toolbarType = .Annatiton
  405. }
  406. self.delegate?.changeAnnotationModeAction?(item: item)
  407. }
  408. }
  409. func toolbarViewController(_ viewController: KMToolbarViewController, clickMode toolMode: KMToolbarViewType, toolbar toolbarItem: KMToolBoxItem, _ pages: [Int]) {
  410. if self.lastItemBox != nil {
  411. if (toolbarItem.isSelected && toolMode.isToolMode()) {
  412. // no nothings
  413. } else {
  414. self.lastItemBox.isSelected = false
  415. }
  416. }
  417. if toolMode != .Magnify && toolMode != .Move && toolMode != .Select && toolMode != .SelectZoom && toolMode != .LeftPanel && toolMode != .RightPanel {
  418. if(toolMode == self.toolbarType) {
  419. toolbarItem.isSelected = false
  420. } else {
  421. toolbarItem.isSelected = true
  422. self.lastItemBox = toolbarItem
  423. }
  424. } else {
  425. if(toolMode != self.toolbarType && toolMode != .LeftPanel) {
  426. let item : KMToolBoxItem = (self.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
  427. item.isSelected = true
  428. self.lastItemBox = item
  429. } else if (toolMode == .LeftPanel) {
  430. if(toolMode == self.toolbarType) {
  431. toolbarItem.isSelected = false
  432. } else {
  433. toolbarItem.isSelected = true
  434. }
  435. }
  436. }
  437. self.toolbarType = toolMode
  438. self.delegate?.mainToolDidClicked?(self, toolMode, toolbarItem, pages)
  439. }
  440. func toolbarViewController(_ viewController: KMToolbarViewController, rightPanel toolbarItem: KMToolBoxItem) {
  441. toolbarItem.isSelected = !toolbarItem.isSelected
  442. self.delegate?.toolbarViewController?(viewController, rightPanel: toolbarItem)
  443. }
  444. func toolbarViewController(_ viewController: KMToolbarViewController, leftPanel toolbarItem: KMToolBoxItem) {
  445. toolbarItem.isSelected = !toolbarItem.isSelected
  446. self.delegate?.toolbarViewController?(viewController, leftPanel: toolbarItem)
  447. }
  448. func showPDFLayoutModeAction(show: Bool) {
  449. self.delegate?.showPDFLayoutModeAction?(show: show)
  450. }
  451. func toolbarViewController(_ viewController: KMToolbarViewController, clickChaildToolType: KMToolbarType, toolbar toolbarItem: KMToolBoxItem) {
  452. if (clickChaildToolType == .crop) {
  453. let titles = [NSLocalizedString("Crop Current Page - White Margins", comment: ""), NSLocalizedString("Crop All Pages - Auto", comment: "")]
  454. let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(titles)
  455. let createFilePopover: NSPopover = NSPopover.init()
  456. createFilePopover.contentViewController = vc
  457. createFilePopover.animates = true
  458. createFilePopover.behavior = .transient
  459. createFilePopover.setValue(true, forKey: "shouldHideAnchor")
  460. createFilePopover.show(relativeTo: NSZeroRect, of: toolbarItem, preferredEdge: .maxY)
  461. self.popover = createFilePopover
  462. vc.downCallback = { [weak self] (downEntered: Bool, count: String) -> Void in
  463. self?.popover?.close()
  464. self?.popover = nil
  465. if downEntered {
  466. if (count == titles.first) {
  467. self!.delegate?.clickChildTool?(type: .crop, index: 1)
  468. } else {
  469. self!.delegate?.clickChildTool?(type: .crop, index: 2)
  470. }
  471. }
  472. }
  473. } else if (clickChaildToolType == .bates || clickChaildToolType == .headerAndFooter || clickChaildToolType == .background || clickChaildToolType == .watermark) {
  474. toolbarItem.isSelected = false
  475. self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
  476. } else if (clickChaildToolType == .redact) {
  477. toolbarItem.isSelected = false
  478. self.enterRedact()
  479. } else if (clickChaildToolType == .compress) {
  480. self.delegate?.clickChildTool?(type: .compress, index: 0)
  481. } else if (clickChaildToolType == .secure) {
  482. // toolbarItem.isSelected = fals
  483. let titles = [NSLocalizedString("Set Passwords", comment: ""), NSLocalizedString("Remove Security", comment: "")]
  484. let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(titles)
  485. let createFilePopover: NSPopover = NSPopover.init()
  486. createFilePopover.contentViewController = vc
  487. createFilePopover.animates = true
  488. createFilePopover.behavior = .transient
  489. createFilePopover.setValue(true, forKey: "shouldHideAnchor")
  490. 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)
  491. vc.downCallback = { [weak self] (downEntered: Bool, count: String) -> Void in
  492. if downEntered {
  493. if (count == titles.first) {
  494. self!.delegate?.clickChildTool?(type: .secure, index: 1)
  495. } else {
  496. self!.delegate?.clickChildTool?(type: .secure, index: 2)
  497. }
  498. }
  499. }
  500. } else if ((KMToolbarType.word.rawValue ... KMToolbarType.conversion_image.rawValue).contains(clickChaildToolType.rawValue)) { /// 转档
  501. self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
  502. } else if (clickChaildToolType == .merge) {
  503. self.delegate?.clickChildTool?(type: clickChaildToolType, index: 0)
  504. }
  505. }
  506. func toolbarViewController(_ viewController: KMToolbarViewController, zoomModel selectedTag: Int) {
  507. self.delegate?.toolbarViewController?(viewController, zoomModel: selectedTag)
  508. }
  509. func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String) {
  510. self.delegate?.toolbarViewController?(viewController, zoomSting: zoomSting)
  511. }
  512. func changePDFViewZoomInAction() {
  513. self.delegate?.changePDFViewZoomInAction?()
  514. }
  515. func changePDFViewZoomOutAction() {
  516. self.delegate?.changePDFViewZoomOutAction?()
  517. }
  518. func changePDFViewGotoNextPageAction() {
  519. self.delegate?.changePDFViewGotoNextPageAction?()
  520. }
  521. func changePDFViewGoToPreviousPageAction() {
  522. self.delegate?.changePDFViewGoToPreviousPageAction?()
  523. }
  524. func showPDFViewPrintViewController() {
  525. self.delegate?.showPDFViewPrintViewController?()
  526. }
  527. func aiTranslationPDFFileAction() {
  528. self.delegate?.aiTranslationPDFFileAction?()
  529. }
  530. func toolbarViewController(_ viewController: KMToolbarViewController, shareDocument item: NSMenuItem) {
  531. self.delegate?.toolbarViewController?(viewController, shareDocument: item)
  532. }
  533. func toolbarViewController(_ viewController: KMToolbarViewController, shareFlatten item: NSMenuItem) {
  534. self.delegate?.toolbarViewController?(viewController, shareFlatten: item)
  535. }
  536. func toolbarViewController(_ viewController: KMToolbarViewController, shareOriginalPDF item: NSMenuItem) {
  537. self.delegate?.toolbarViewController?(viewController, shareOriginalPDF: item)
  538. }
  539. func toolbarViewController(_ viewController: KMToolbarViewController, scanOCRModel selectedTag: Int) {
  540. self.delegate?.toolbarViewController?(viewController, scanOCRModel: selectedTag)
  541. }
  542. }