KMToolbarViewController.swift 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. //
  2. // KMToolbarViewController.swift
  3. // PDF Master
  4. //
  5. // Created by lxy on 2022/12/2.
  6. //
  7. import Cocoa
  8. @objc enum KMToolbarViewType : Int {
  9. case None
  10. case Main
  11. case Annatiton
  12. case Page
  13. case Conversion
  14. case ScanOCR
  15. case editPDF
  16. case Form
  17. case FillSign
  18. case Tool
  19. case redact
  20. case Move
  21. case Magnify
  22. case Select
  23. case SelectZoom
  24. case LeftPanel
  25. case RightPanel
  26. func isToolMode() -> Bool {
  27. return (self == .Move || self == .Magnify || self == .Select || self == .SelectZoom)
  28. }
  29. func itemIdentifier() -> String {
  30. if (self == .Annatiton) {
  31. return KMDocumentAnnotationToolbarItemIdentifier
  32. } else if (self == .Page) {
  33. return KMDocumentPageToolbarItemIdentifier
  34. } else if (self == .Conversion) {
  35. return KMDocumentConversonToolbarItemIdentifier
  36. } else if (self == .ScanOCR) {
  37. return KMDocumentScanOCRToolbarItemIdentifier
  38. } else if (self == .editPDF) {
  39. return KMDocumentEditToolbarItemIdentifier
  40. } else if (self == .Form) {
  41. return KMDocumentFormToolbarItemIdentifier
  42. } else if (self == .FillSign) {
  43. return KMDocumentFillSginToolbarItemIdentifier
  44. } else if (self == .Tool) {
  45. return KMDocumentToolToolbarItemIdentifier
  46. } else if (self == .Move) {
  47. return KMToolbarMoveToolModeItemIdentifier
  48. } else if (self == .Magnify) {
  49. return KMToolbarMagnifyToolModeItemIdentifier
  50. } else if (self == .Select) {
  51. return KMToolbarSelectToolModeItemIdentifier
  52. } else if (self == .SelectZoom) {
  53. return KMToolbarZoomToSelectionItemIdentifier
  54. } else if (self == .LeftPanel) {
  55. return KMLeftControlToolbarItemIdentifier
  56. } else if (self == .RightPanel) {
  57. return KMRightControlToolbarItemIdentifier
  58. }
  59. return ""
  60. }
  61. }
  62. @objc enum KMToolbarType: Int {
  63. /// conversion
  64. case word = 3000
  65. case excel = 3001
  66. case ppt = 3002
  67. case rtf = 3003
  68. case csv = 3004
  69. case html = 3005
  70. case conversion_text = 3006
  71. case conversion_image = 3007
  72. /// tool
  73. case compress = 8000
  74. case merge = 8001
  75. case fileCompare = 8002
  76. case secure = 8003
  77. case redact = 8004
  78. case watermark = 8005
  79. case background = 8006
  80. case headerAndFooter = 8007
  81. case bates = 8008
  82. case crop = 8009
  83. case comparison = 8010
  84. }
  85. @objc protocol KMToolbarViewControllerDelegate {
  86. @objc optional func changeAnnotationModeAction(item:KMToolbarClickButton)
  87. @objc optional func showPDFLayoutModeAction(show:Bool)
  88. @objc optional func changePDFViewZoomInAction()
  89. @objc optional func changePDFViewZoomOutAction()
  90. @objc optional func changePDFViewGotoNextPageAction()
  91. @objc optional func changePDFViewGoToPreviousPageAction()
  92. @objc optional func changePDFViewGotoBackAction()
  93. @objc optional func changePDFViewGoToForwardAction()
  94. @objc optional func showPDFViewPrintViewController()
  95. @objc optional func aiTranslationPDFFileAction()
  96. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
  97. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
  98. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareAction toolbarItem: KMToolbarItemView)
  99. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
  100. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
  101. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareOriginalPDF item:NSMenuItem)
  102. @objc optional func toolbarViewController(_ viewController: KMToolbarViewController, clickMode toolMode: KMToolbarViewType, toolbar toolbarItem: KMToolbarItemView, _ pages: [Int])
  103. @objc optional func toolbarViewController(_ viewController: KMToolbarViewController, clickChaildToolType: KMToolbarType, toolbar toolbarItem: KMToolbarItemView)
  104. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
  105. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, rightPanel toolbarItem: KMToolbarItemView)
  106. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, leftPanel toolbarItem: KMToolbarItemView)
  107. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView)
  108. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String)
  109. }
  110. class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
  111. var toolbar : KMToolbarView!
  112. var toolbarType : KMToolbarViewType = KMToolbarViewType.None
  113. var toolbarItems : [String : Any] = [:]
  114. @IBOutlet weak var mainWindowController : MainWindowController!
  115. open weak var delegate: KMToolbarViewControllerDelegate?
  116. @IBOutlet var zoomButton: NSPopUpButton!
  117. @IBOutlet var zoomView: NSView!
  118. @IBOutlet weak var zoomTextField: NSTextField!
  119. var pdfView : CPDFListView = CPDFListView()
  120. var shareButton = KMToolbarClickButton()
  121. private var bottomLine = NSView()
  122. // 是否显示所有注释
  123. var isShowAllAnnotations = true
  124. var ignoreCurrentAnnotationTypeChange = false
  125. override func viewDidLoad() {
  126. super.viewDidLoad()
  127. self.zoomTextField.delegate = self
  128. NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewAnnotationTypeChangeNotification"), object: nil)
  129. NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewToolModeChangeNotification"), object: nil)
  130. }
  131. override func loadView() {
  132. super.loadView()
  133. self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
  134. self.toolbar.frame = self.view.bounds
  135. self.toolbar.autoresizingMask = [.width,.height]
  136. self.toolbar.delegate = self
  137. self.view.addSubview(self.toolbar)
  138. self.view.addSubview(self.bottomLine)
  139. self.bottomLine.frame = NSMakeRect(0, 0, NSWidth(self.view.bounds), 1)
  140. self.bottomLine.autoresizingMask = [.width]
  141. self.bottomLine.wantsLayer = true
  142. self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#0000001A").cgColor
  143. }
  144. func updateType(newType:KMToolbarViewType) {
  145. if newType != toolbarType {
  146. toolbarType = newType
  147. if self.toolbar != nil && self.toolbar.superview != nil {
  148. self.toolbar.removeFromSuperview()
  149. }
  150. self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
  151. self.toolbar.frame = self.view.bounds
  152. self.toolbar.autoresizingMask = [.width,.height]
  153. self.toolbar.delegate = self
  154. self.view.addSubview(self.toolbar)
  155. }
  156. }
  157. func reloadateToolbar() -> Void {
  158. toolbar.reloadData()
  159. }
  160. func resetToolbar() -> Void {
  161. for item in toolbar.items {
  162. item.isSelected = false
  163. }
  164. }
  165. // MARK: Action
  166. @IBAction func changeAnnotationMode(item: KMToolbarClickButton) {
  167. self.delegate?.changeAnnotationModeAction?(item: item)
  168. }
  169. @IBAction func leftControllButtonAction(item: KMToolbarClickButton) {
  170. let tag = KMToolbarViewType(rawValue: item.tag) ?? .None
  171. if tag == .editPDF {
  172. Task { @MainActor in
  173. #if VERSION_DMG
  174. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  175. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  176. return
  177. }
  178. #endif
  179. self.delegate?.toolbarViewController?(self, clickMode: tag, toolbar: item.clickObject as! KMToolbarItemView, [])
  180. }
  181. } else {
  182. self.delegate?.toolbarViewController?(self, clickMode: tag, toolbar: item.clickObject as! KMToolbarItemView, [])
  183. }
  184. }
  185. @objc private func leftPanelAction(sender: KMToolbarClickButton) {
  186. self.delegate?.toolbarViewController?(self, leftPanel: sender.clickObject as! KMToolbarItemView)
  187. }
  188. @objc private func itemAction(_ item: KMToolbarClickButton) {
  189. self.delegate?.toolbarViewController?(self, itemDidClick: item.clickObject as! KMToolbarItemView)
  190. }
  191. @IBAction func rightPanelControllButtonAction(item: KMToolbarClickButton) {
  192. let tag = KMToolbarViewType(rawValue: item.tag) ?? .None
  193. self.delegate?.toolbarViewController?(self, rightPanel: item.clickObject as! KMToolbarItemView)
  194. }
  195. @IBAction func showPDFLayoutMode(sender: KMToolbarClickButton) {
  196. let item = sender.clickObject as? KMToolbarItemView
  197. if (item != nil) {
  198. item?.isSelected = !item!.isSelected
  199. }
  200. self.delegate?.showPDFLayoutModeAction?(show: true)
  201. }
  202. @objc func cropMenuAction(item: KMToolbarItemView) {
  203. self.delegate?.toolbarViewController?(self, clickChaildToolType: .crop, toolbar: item)
  204. }
  205. @objc func batesMenuAction(sender: KMToolbarClickButton) {
  206. self.delegate?.toolbarViewController?(self, clickChaildToolType: .bates, toolbar: sender.clickObject as! KMToolbarItemView)
  207. }
  208. @objc func headerfooterMenuAction(sender: KMToolbarClickButton) {
  209. self.delegate?.toolbarViewController?(self, clickChaildToolType: .headerAndFooter, toolbar: sender.clickObject as! KMToolbarItemView)
  210. }
  211. @objc func backgroundMenuAction(sender: KMToolbarClickButton) {
  212. self.delegate?.toolbarViewController?(self, clickChaildToolType: .background, toolbar: sender.clickObject as! KMToolbarItemView)
  213. }
  214. @objc func watermarkMenuAction(sender: KMToolbarClickButton) {
  215. self.delegate?.toolbarViewController?(self, clickChaildToolType: .watermark, toolbar: sender.clickObject as! KMToolbarItemView)
  216. }
  217. @objc func redactMenuAction(sender: KMToolbarClickButton) {
  218. self.delegate?.toolbarViewController?(self, clickChaildToolType: .redact, toolbar: sender.clickObject as! KMToolbarItemView)
  219. }
  220. @objc func compressMenuAction(sender: KMToolbarClickButton) {
  221. self.delegate?.toolbarViewController?(self, clickChaildToolType: .compress, toolbar: sender.clickObject as! KMToolbarItemView)
  222. }
  223. @objc func secureMenuAction(sender: KMToolbarClickButton) {
  224. self.delegate?.toolbarViewController?(self, clickChaildToolType: .secure, toolbar: sender.clickObject as! KMToolbarItemView)
  225. }
  226. @objc func conversionMenuItemAction(sender: KMToolbarClickButton) {
  227. let item: KMToolbarItemView = sender.clickObject as! KMToolbarItemView
  228. var type: KMToolbarType = .word
  229. if (item.btnTag == KMToolbarType.excel.rawValue) {
  230. type = .excel
  231. } else if (item.btnTag == KMToolbarType.ppt.rawValue) {
  232. type = .ppt
  233. } else if (item.btnTag == KMToolbarType.rtf.rawValue) {
  234. type = .rtf
  235. } else if (item.btnTag == KMToolbarType.csv.rawValue) {
  236. type = .csv
  237. } else if (item.btnTag == KMToolbarType.html.rawValue) {
  238. type = .html
  239. } else if (item.btnTag == KMToolbarType.conversion_text.rawValue) {
  240. type = .conversion_text
  241. } else if (item.btnTag == KMToolbarType.conversion_image.rawValue) {
  242. type = .conversion_image
  243. }
  244. self.delegate?.toolbarViewController?(self, clickChaildToolType: type, toolbar: item)
  245. }
  246. @IBAction func zoomModelSelectButtonAction(_ sender: NSPopUpButton) {
  247. self.delegate?.toolbarViewController?(self, zoomModel: sender.selectedTag())
  248. for item in sender.itemArray {
  249. item.state = .off
  250. }
  251. sender.selectedItem?.state = .on
  252. }
  253. @IBAction func zoomPDFViewButtonAction(sender:KMToolbarClickButton) {
  254. if sender.tag == 0 {
  255. self.delegate?.changePDFViewZoomOutAction?()
  256. } else if sender.tag == 1 {
  257. self.delegate?.changePDFViewZoomInAction?()
  258. } else if sender.tag == 2 {
  259. self.delegate?.changePDFViewGotoBackAction?()
  260. } else if sender.tag == 3 {
  261. self.delegate?.changePDFViewGoToForwardAction?()
  262. }
  263. }
  264. @IBAction func printPDFViewButtonAction(sender:KMToolbarClickButton) {
  265. self.delegate?.showPDFViewPrintViewController?()
  266. }
  267. @IBAction func aiTranslationButtonAction(sender:KMToolbarClickButton) {
  268. self.delegate?.aiTranslationPDFFileAction?()
  269. }
  270. @IBAction func shareButtonAction(sender:KMToolbarClickButton) {
  271. self.shareButton = sender
  272. let menu = NSMenu()
  273. menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
  274. menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
  275. menu.addItem(withTitle: NSLocalizedString("Original PDF", comment: ""), action: #selector(shareViaWithOriginalPDF), target: self)
  276. menu.popUp(positioning: nil, at: NSPoint(x: sender.frame.origin.x, y: sender.frame.origin.y-10), in: sender.superview)
  277. self.delegate?.toolbarViewController?(self, shareAction: sender.clickObject as! KMToolbarItemView)
  278. }
  279. @IBAction func shareViaWithDocument(sender:NSMenuItem) {
  280. self.delegate?.toolbarViewController?(self, shareDocument: sender)
  281. }
  282. @IBAction func shareViaWithFlatten(sender:NSMenuItem) {
  283. self.delegate?.toolbarViewController?(self, shareFlatten: sender)
  284. }
  285. @IBAction func shareViaWithOriginalPDF(sender:NSMenuItem) {
  286. self.delegate?.toolbarViewController?(self, shareOriginalPDF: sender)
  287. }
  288. @objc func mergeMenuItemAction(sender: KMToolbarClickButton) {
  289. self.delegate?.toolbarViewController?(self, clickChaildToolType: .merge, toolbar: sender.clickObject as! KMToolbarItemView)
  290. }
  291. @IBAction func scanOCRModelSelect(sender:KMToolbarClickButton) {
  292. self.delegate?.toolbarViewController?(self, scanOCRModel: sender.tag)
  293. }
  294. // Form 对齐
  295. @IBAction func formsAlignmentAction(sender:KMToolbarClickButton) {
  296. }
  297. // Form 更多操作
  298. @IBAction func formsMoreOperationAction(sender:KMToolbarClickButton) {
  299. }
  300. func toolbarItemFindItemIdentifiers(value : String) -> KMToolbarItemView{
  301. for item in self.toolbarItems {
  302. if item.key == value {
  303. return item.value as! KMToolbarItemView
  304. }
  305. }
  306. return KMToolbarItemView()
  307. }
  308. func controlTextDidEndEditing(_ obj: Notification) {
  309. let textField = obj.object as? NSTextField
  310. if textField == self.zoomTextField {
  311. self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
  312. }
  313. }
  314. func controlTextDidChange(_ obj: Notification) {
  315. }
  316. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  317. switch commandSelector {
  318. case #selector(NSResponder.insertNewline(_:)):
  319. if let inputView = control as? NSTextField {
  320. // //当当前TextField按下enter
  321. if inputView == zoomTextField {
  322. KMPrint("按下 enter")
  323. self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
  324. } else if let _ = control as? NSSearchField {
  325. self.delegate?.toolbarViewController?(self, searchAction: control.stringValue)
  326. }
  327. }
  328. return true
  329. default:
  330. return false
  331. }
  332. }
  333. }
  334. extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidation {
  335. func toolbarLeftDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  336. if toolbarType == .Main {
  337. return [KMLeftControlToolbarItemIdentifier,
  338. KMDocumentZoomViewToolbarItemIdentifier, KMDocumentZoomOutToolbarItemIdentifier, KMDocumentZoomToolbarItemIdentifier,
  339. KMDocumentPreviousPageToolbarItemIdentifier, KMDocumentNextPageToolbarItemIdentifier, KMDocumentHomeToolbarItemIdentifier]
  340. }
  341. return []
  342. }
  343. func toolbarRightDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  344. if toolbarType == .Main {
  345. return [KMDocumentViewSettingToolbarItemIdentifier, KMDocumentShareToolbarItemIdentifier,
  346. KMDocumentSearchToolbarItemIdentifier, KMRightControlToolbarItemIdentifier]
  347. } else if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
  348. return [KMToolbarAnnotationSettingItemIdentifier]
  349. }
  350. return []
  351. }
  352. func toolbarAllowedItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  353. if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
  354. return [KMNewToolbarSpaceItemIdentifier,
  355. KMToolbarPageEditInsetItemIdentifier, KMToolbarToolMergeItemIdentifier, KMToolbarPageEditSplitItemIdentifier,
  356. KMToolbarToolCompressItemIdentifier, KMToolbarToolSecureItemIdentifier, KMToolbarToolWatermarkItemIdentifier,
  357. KMToolbarToolBackgroundItemIdentifier, KMToolbarToolHeaderFooterItemIdentifier, KMToolbarToolBatesItemIdentifier,
  358. KMToolbarToolCropItemIdentifier,
  359. KMToolbarConversionWordItemIdentifier, KMToolbarConversionExcelItemIdentifier, KMToolbarConversionPPTItemIdentifier,
  360. KMToolbarConversionRTFItemIdentifier, KMToolbarConversionCSVItemIdentifier, KMToolbarConversionHTMLItemIdentifier,
  361. KMToolbarConversionTextItemIdentifier, KMToolbarConversionImageItemIdentifier,
  362. KMToolbarMoveToolModeItemIdentifier,
  363. KMToolbarMagnifyToolModeItemIdentifier,
  364. KMToolbarSelectToolModeItemIdentifier,
  365. KMToolbarZoomToSelectionItemIdentifier,
  366. KMNewToolbarSpaceItemIdentifier,
  367. KMToolbarDividerItemIdentifier,
  368. KMNewToolbarSpaceItemIdentifier,
  369. KMToolbarHighlightAnnotationItemIdentifier,
  370. KMToolbarUnderlineAnnotationItemIdentifier,
  371. KMToolbarStrikeOutAnnotationItemIdentifier,
  372. KMToolbarInkAnnotationItemIdentifier,
  373. KMToolbarFreeTextAnnotationItemIdentifier,
  374. KMToolbarAnchoredAnnotationItemIdentifier,
  375. KMToolbarSquareAnnotationItemIdentifier, KMToolbarCircleAnnotationItemIdentifier, KMToolbarArrowAnnotationItemIdentifier, KMToolbarLineAnnotationItemIdentifier,
  376. KMToolbarLinkAnnotationItemIdentifier,
  377. KMAnnotationStampToolbarItemIdentifier,
  378. KMToolbarSignSignatureAnnotationItemIdentifier,
  379. KMToolbarDividerItemIdentifier,
  380. KMToolbarShowToolbarItemIdentifier,
  381. KMToolbarToolRadioButtonItemIdentifier]
  382. }
  383. return []
  384. }
  385. func toolbarDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  386. switch toolbarType {
  387. case .None:
  388. return []
  389. case .Main:
  390. return [KMDocumentAnnotationToolbarItemIdentifier,
  391. KMDocumentPageToolbarItemIdentifier,
  392. KMDocumentToolToolbarItemIdentifier,
  393. KMDocumentConversonToolbarItemIdentifier,
  394. KMDocumentFormToolbarItemIdentifier,
  395. KMDocumentFillSginToolbarItemIdentifier,
  396. KMDocumentEditToolbarItemIdentifier,
  397. KMDocumentRedactToolbarItemIdentifier,
  398. KMDocumentScanOCRToolbarItemIdentifier]
  399. case .Annatiton,.Magnify,.Move,.Select,.SelectZoom:
  400. let itemIdentifiers: [String]? = self.toolbar?.toolbarIdentifier != nil ? (UserDefaults.standard.object(forKey: self.toolbar!.toolbarIdentifier!) as? [String]) : []
  401. if itemIdentifiers == nil || itemIdentifiers!.count <= 0 {
  402. return [KMToolbarMoveToolModeItemIdentifier,
  403. KMToolbarMagnifyToolModeItemIdentifier,
  404. KMToolbarSelectToolModeItemIdentifier,
  405. KMToolbarZoomToSelectionItemIdentifier,
  406. KMNewToolbarSpaceItemIdentifier,
  407. KMToolbarDividerItemIdentifier,
  408. KMNewToolbarSpaceItemIdentifier,
  409. KMToolbarHighlightAnnotationItemIdentifier,
  410. KMToolbarUnderlineAnnotationItemIdentifier,
  411. KMToolbarStrikeOutAnnotationItemIdentifier,
  412. KMToolbarInkAnnotationItemIdentifier,
  413. KMToolbarFreeTextAnnotationItemIdentifier,
  414. KMToolbarAnchoredAnnotationItemIdentifier,
  415. KMToolbarSquareAnnotationItemIdentifier, KMToolbarCircleAnnotationItemIdentifier, KMToolbarArrowAnnotationItemIdentifier, KMToolbarLineAnnotationItemIdentifier,
  416. KMToolbarLinkAnnotationItemIdentifier,
  417. KMAnnotationStampToolbarItemIdentifier,
  418. KMToolbarSignSignatureAnnotationItemIdentifier,
  419. KMToolbarDividerItemIdentifier,
  420. KMToolbarShowToolbarItemIdentifier]
  421. }
  422. return itemIdentifiers!
  423. case .editPDF:
  424. return [KMToolbarAddTextEditPDFItemIdentifier,
  425. KMToolbarAddImageEditPDFItemIdentifier]
  426. case .Page:
  427. return []
  428. case .Tool:
  429. return [KMToolbarToolCompressItemIdentifier, KMToolbarToolMergeItemIdentifier,
  430. KMToolbarToolSecureItemIdentifier, KMToolbarComparisonItemIdentifier,
  431. KMToolbarToolWatermarkItemIdentifier, KMToolbarToolBackgroundItemIdentifier,
  432. KMToolbarToolHeaderFooterItemIdentifier, KMToolbarToolBatesItemIdentifier]
  433. case .Form:
  434. return [KMToolbarToolTextFieldItemIdentifier,
  435. KMToolbarToolCheckBoxItemIdentifier,
  436. KMToolbarToolRadioButtonItemIdentifier,
  437. KMToolbarToolListBoxItemIdentifier,
  438. KMToolbarToolPullDownmenuItemIdentifier,
  439. KMToolbarToolButtonIdentifier,
  440. KMToolbarToolSignBoxIdentifier,
  441. KMToolbarDividerItemIdentifier,
  442. KMToolbarToolFormAlignIdentifier,
  443. KMToolbarToolFormMoreIdentifier]
  444. case .FillSign:
  445. return [KMToolbarToolTextIdentifier,
  446. KMToolbarToolHookItemIdentifier,
  447. KMToolbarToolForkItemIdentifier,
  448. KMToolbarToolRectangleIdentifier,
  449. KMToolbarToolLineItemIdentifier,
  450. KMToolbarToolDotItemIdentifier,
  451. KMToolbarToolDateIdentifier,
  452. KMToolbarFillSignSignatureIdentifier]
  453. case .Conversion:
  454. return [KMToolbarConversionWordItemIdentifier,
  455. KMToolbarConversionExcelItemIdentifier,
  456. KMToolbarConversionPPTItemIdentifier,
  457. KMToolbarConversionRTFItemIdentifier,
  458. KMToolbarConversionCSVItemIdentifier,
  459. KMToolbarConversionHTMLItemIdentifier,
  460. KMToolbarConversionTextItemIdentifier,
  461. KMToolbarConversionImageItemIdentifier]
  462. case .ScanOCR:
  463. return [KMToolbarToolEnhancedScanIdentifier,
  464. KMToolbarToolOCRTextIdentifier]
  465. default:
  466. break
  467. }
  468. return []
  469. }
  470. func toolbar(_ toolbar: KMToolbarView, itemFor identifier: String) -> KMToolbarItemView {
  471. var item: KMToolbarItemView? = self.toolbarItems[identifier] as? KMToolbarItemView
  472. var create = true
  473. if let data = item {
  474. let pId = parentIdentifier(data.itemIdentifier ?? "")
  475. if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) && (pId != KMDocumentAnnotationToolbarItemIdentifier || data.itemIdentifier! == KMToolbarAnnotationSettingItemIdentifier) {
  476. create = true
  477. }
  478. }
  479. if item == nil || create {
  480. item = KMToolbarItemView.init(itemIdentifier: identifier)
  481. self.toolbarItems[identifier] = item
  482. if identifier == KMLeftControlToolbarItemIdentifier {
  483. item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
  484. item?.titleName = NSLocalizedString("Panel", comment: "")
  485. item?.target = self
  486. item?.toolTip = NSLocalizedString("View Settings", comment: "")
  487. item?.boxImagePosition = .imageAbove
  488. item?.btnAction = #selector(leftPanelAction)
  489. } else if identifier == KMDocumentZoomToolbarItemIdentifier {
  490. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
  491. item?.titleName = NSLocalizedString("", comment: "")
  492. item?.target = self
  493. item?.btnTag = 1
  494. item?.toolTip = NSLocalizedString("Zoom In", comment: "")
  495. item?.boxImagePosition = .imageAbove
  496. item?.btnAction = #selector(zoomPDFViewButtonAction)
  497. } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
  498. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
  499. item?.titleName = NSLocalizedString("", comment: "")
  500. item?.target = self
  501. item?.btnTag = 0
  502. item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
  503. item?.boxImagePosition = .imageAbove
  504. item?.btnAction = #selector(zoomPDFViewButtonAction)
  505. } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
  506. item?.titleName = NSLocalizedString("Zoom", comment: "")
  507. item?.target = self
  508. let view = NSView()
  509. view.frame = NSMakeRect(0, 0, 70, 40)
  510. let boxView = NSView()
  511. boxView.frame = NSMakeRect(0, 16, 70, 22)
  512. view.addSubview(boxView)
  513. boxView.addSubview(self.zoomView)
  514. self.zoomView.frame = NSMakeRect(10, 3, NSWidth(self.zoomView.frame), NSHeight(self.zoomView.frame))
  515. let titleLabel = NSTextField(labelWithString: NSLocalizedString("Zoom", comment: ""))
  516. view.addSubview(titleLabel)
  517. titleLabel.frame = NSMakeRect(0, 0, 70, 16)
  518. titleLabel.alignment = .right
  519. boxView.wantsLayer = true
  520. boxView.layer?.borderWidth = 1
  521. boxView.layer?.borderColor = NSColor.lightGray.cgColor
  522. item?.customizeView = view
  523. } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
  524. item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
  525. item?.titleName = NSLocalizedString("Next", comment: "")
  526. item?.target = self
  527. item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
  528. item?.boxImagePosition = .imageAbove
  529. item?.btnAction = #selector(itemAction)
  530. } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
  531. item?.image = NSImage(named: "KMImageNameToolbarPagepreviousNor")
  532. item?.titleName = NSLocalizedString("Previous", comment: "")
  533. item?.target = self
  534. item?.toolTip = NSLocalizedString("Go To Previous Page", comment: "")
  535. item?.boxImagePosition = .imageAbove
  536. item?.btnAction = #selector(itemAction)
  537. } else if identifier == KMDocumentHomeToolbarItemIdentifier {
  538. item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
  539. item?.titleName = NSLocalizedString("Home", comment: "")
  540. item?.target = self
  541. item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
  542. item?.boxImagePosition = .imageAbove
  543. item?.btnAction = #selector(itemAction)
  544. } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
  545. item?.titleName = NSLocalizedString("Tools", comment: "")
  546. item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
  547. item?.target = self
  548. item?.toolTip = String(format: "%@: %@, %@, %@, %@", KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
  549. item?.btnTag = KMToolbarViewType.Annatiton.rawValue
  550. item?.btnAction = #selector(leftControllButtonAction)
  551. item?.boxImagePosition = .imageAbove
  552. } else if identifier == KMDocumentPageToolbarItemIdentifier {
  553. item?.titleName = NSLocalizedString("Page Edit", comment: "")
  554. item?.target = self
  555. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
  556. item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
  557. item?.btnTag = KMToolbarViewType.Page.rawValue
  558. item?.btnAction = #selector(leftControllButtonAction)
  559. item?.boxImagePosition = .imageAbove
  560. } else if identifier == KMDocumentConversonToolbarItemIdentifier {
  561. item?.titleName = NSLocalizedString("Converter", comment: "")
  562. item?.target = self
  563. item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
  564. item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
  565. item?.btnTag = KMToolbarViewType.Conversion.rawValue
  566. item?.btnAction = #selector(leftControllButtonAction)
  567. item?.boxImagePosition = .imageAbove
  568. } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
  569. item?.titleName = NSLocalizedString("OCR", comment: "")
  570. item?.target = self
  571. item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
  572. item?.boxImagePosition = .imageAbove
  573. item?.btnTag = KMToolbarViewType.ScanOCR.rawValue
  574. item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
  575. item?.btnAction = #selector(leftControllButtonAction)
  576. } else if identifier == KMToolbarToolEnhancedScanIdentifier {
  577. item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
  578. item?.target = self
  579. item?.btnTag = 0
  580. item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
  581. item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
  582. item?.boxImagePosition = .imageLeft
  583. item?.btnAction = #selector(scanOCRModelSelect)
  584. } else if identifier == KMToolbarToolOCRTextIdentifier {
  585. item?.image = NSImage(named: "KMImageNameMainToolOCRText")
  586. item?.target = self
  587. item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
  588. item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
  589. item?.boxImagePosition = .imageLeft
  590. item?.btnAction = #selector(scanOCRModelSelect)
  591. } else if identifier == KMDocumentEditToolbarItemIdentifier {
  592. item?.titleName = NSLocalizedString("Edit PDF", comment: "")
  593. item?.target = self
  594. item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
  595. item?.boxImagePosition = .imageAbove
  596. item?.btnTag = KMToolbarViewType.editPDF.rawValue
  597. item?.toolTip = NSLocalizedString("Edit text and image in PDF", comment: "")
  598. item?.btnAction = #selector(leftControllButtonAction)
  599. } else if identifier == KMDocumentFormToolbarItemIdentifier {
  600. item?.titleName = NSLocalizedString("Forms", comment: "")
  601. item?.target = self
  602. item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
  603. item?.boxImagePosition = .imageAbove
  604. item?.btnTag = KMToolbarViewType.Form.rawValue
  605. item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
  606. item?.btnAction = #selector(leftControllButtonAction)
  607. } else if identifier == KMDocumentFillSginToolbarItemIdentifier {
  608. item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
  609. item?.target = self
  610. item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
  611. item?.boxImagePosition = .imageAbove
  612. item?.btnTag = KMToolbarViewType.FillSign.rawValue
  613. item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
  614. item?.btnAction = #selector(leftControllButtonAction)
  615. } else if identifier == KMDocumentToolToolbarItemIdentifier {
  616. item?.titleName = NSLocalizedString("Editor", comment: "")
  617. item?.target = self
  618. item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
  619. item?.boxImagePosition = .imageAbove
  620. item?.btnTag = KMToolbarViewType.Tool.rawValue
  621. item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
  622. item?.btnAction = #selector(leftControllButtonAction)
  623. } else if identifier == KMDocumentRedactToolbarItemIdentifier {
  624. item?.titleName = NSLocalizedString("Redact Text", comment: "")
  625. item?.target = self
  626. item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
  627. item?.boxImagePosition = .imageAbove
  628. item?.btnTag = KMToolbarViewType.redact.rawValue
  629. item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
  630. item?.btnAction = #selector(leftControllButtonAction)
  631. } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
  632. item?.image = NSImage(named: "ic_function_other_AITranslation")
  633. item?.titleName = "AI Translation"
  634. item?.target = self
  635. item?.toolTip = NSLocalizedString("AI Translation", comment: "")
  636. item?.boxImagePosition = .imageOnly
  637. item?.btnAction = #selector(aiTranslationButtonAction)
  638. } else if identifier == KMDocumentPrintToolbarItemIdentifier {
  639. item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
  640. item?.titleName = "Print"
  641. item?.target = self
  642. item?.toolTip = NSLocalizedString("Print", comment: "")
  643. item?.boxImagePosition = .imageOnly
  644. item?.btnAction = #selector(printPDFViewButtonAction)
  645. } else if identifier == KMDocumentViewSettingToolbarItemIdentifier {
  646. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
  647. item?.titleName = NSLocalizedString("Page Display", comment: "")
  648. item?.target = self
  649. item?.toolTip = NSLocalizedString("Page Display", comment: "")
  650. item?.boxImagePosition = .imageAbove
  651. item?.btnAction = #selector(itemAction)
  652. } else if identifier == KMDocumentShareToolbarItemIdentifier {
  653. item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
  654. item?.titleName = NSLocalizedString("Share", comment: "")
  655. item?.target = self
  656. item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
  657. item?.boxImagePosition = .imageAbove
  658. item?.btnAction = #selector(shareButtonAction)
  659. let menuItem = NSMenuItem.init(title: item!.titleName ?? "", action: nil, target: self)
  660. let menu = NSMenu()
  661. menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
  662. menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
  663. menu.addItem(withTitle: NSLocalizedString("Original PDF", comment: ""), action: #selector(shareViaWithOriginalPDF), target: self)
  664. menuItem.submenu = menu
  665. item?.menuFormRepresentation = menuItem
  666. } else if identifier == KMDocumentSearchToolbarItemIdentifier {
  667. item?.titleName = NSLocalizedString("Search", comment: "")
  668. item?.target = self
  669. let view = NSView()
  670. view.frame = NSMakeRect(0, 0, 150, 40)
  671. let boxView = NSView()
  672. boxView.frame = NSMakeRect(0, 16, 150, 22)
  673. view.addSubview(boxView)
  674. let searchView = NSSearchField()
  675. searchView.frame = NSMakeRect(0, 0, 150, 22)
  676. searchView.placeholderString = NSLocalizedString("Search", comment: "")
  677. searchView.sendsWholeSearchString = true
  678. searchView.sendsSearchStringImmediately = true
  679. searchView.drawsBackground = false
  680. searchView.delegate = self
  681. boxView.addSubview(searchView)
  682. let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
  683. view.addSubview(titleLabel)
  684. titleLabel.frame = NSMakeRect(0, 0, 130, 16)
  685. titleLabel.alignment = .center
  686. item?.customizeView = view
  687. } else if identifier == KMRightControlToolbarItemIdentifier {
  688. item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
  689. item?.titleName = NSLocalizedString("Properties", comment: "")
  690. item?.target = self
  691. item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
  692. item?.boxImagePosition = .imageOnly
  693. item?.btnAction = #selector(rightPanelControllButtonAction)
  694. } else if identifier == KMToolbarMoveToolModeItemIdentifier {
  695. item?.titleName = NSLocalizedString("Scroll Tool", comment: "")
  696. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsPantool)
  697. item?.target = self
  698. item?.btnTag = KMToolbarViewType.Move.rawValue
  699. item?.toolTip = NSLocalizedString("Scroll Tool", comment: "")
  700. item?.boxImagePosition = .imageOnly
  701. item?.btnAction = #selector(leftControllButtonAction)
  702. } else if identifier == KMToolbarMagnifyToolModeItemIdentifier {
  703. item?.titleName = NSLocalizedString("Magnify Tool", comment: "")
  704. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsMagnifier)
  705. item?.target = self
  706. item?.btnTag = KMToolbarViewType.Magnify.rawValue
  707. item?.toolTip = NSLocalizedString("Magnify Tool", comment: "")
  708. item?.boxImagePosition = .imageOnly
  709. item?.btnAction = #selector(leftControllButtonAction)
  710. } else if identifier == KMToolbarSelectToolModeItemIdentifier {
  711. item?.titleName = NSLocalizedString("Content Selection Tool", comment: "")
  712. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsContentsel)
  713. item?.target = self
  714. item?.btnTag = KMToolbarViewType.Select.rawValue
  715. item?.toolTip = NSLocalizedString("Content Selection Tool", comment: "")
  716. item?.boxImagePosition = .imageOnly
  717. item?.btnAction = #selector(leftControllButtonAction)
  718. } else if identifier == KMToolbarZoomToSelectionItemIdentifier {
  719. item?.titleName = NSLocalizedString("Zoom to selected area", comment: "")
  720. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsAreazoom)
  721. item?.target = self
  722. item?.btnTag = KMToolbarViewType.SelectZoom.rawValue
  723. item?.toolTip = NSLocalizedString("Zoom to selected area", comment: "")
  724. item?.boxImagePosition = .imageOnly
  725. item?.btnAction = #selector(leftControllButtonAction)
  726. } else if identifier == KMToolbarHighlightAnnotationItemIdentifier {
  727. item?.titleName = NSLocalizedString("Highlight", comment: "")
  728. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsUnderline)
  729. item?.target = self
  730. item?.btnTag = CAnnotationType.highlight.rawValue
  731. item?.toolTip = String(format: "%@ (⌃⌘H)", NSLocalizedString("Highlight", comment: ""))
  732. item?.boxImagePosition = .imageOnly
  733. item?.btnAction = #selector(changeAnnotationMode)
  734. } else if identifier == KMToolbarUnderlineAnnotationItemIdentifier {
  735. item?.titleName = NSLocalizedString("Underline", comment: "")
  736. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsUnderline)
  737. item?.target = self
  738. item?.btnTag = CAnnotationType.underline.rawValue
  739. item?.toolTip = String(format: "%@ (⇧⌘M)", NSLocalizedString("Underline", comment: ""))
  740. item?.boxImagePosition = .imageOnly
  741. item?.btnAction = #selector(changeAnnotationMode)
  742. } else if identifier == KMToolbarStrikeOutAnnotationItemIdentifier {
  743. item?.titleName = NSLocalizedString("Strikethrough", comment: "")
  744. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsStrikeout)
  745. item?.target = self
  746. item?.btnTag = CAnnotationType.strikeOut.rawValue
  747. item?.toolTip = String(format: "%@ (⌃⌘M)", NSLocalizedString("Strikethrough", comment: ""))
  748. item?.boxImagePosition = .imageOnly
  749. item?.btnAction = #selector(changeAnnotationMode)
  750. } else if identifier == KMToolbarInkAnnotationItemIdentifier {
  751. item?.titleName = NSLocalizedString("Freehand", comment: "")
  752. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsPen)
  753. item?.target = self
  754. item?.btnTag = CAnnotationType.ink.rawValue
  755. item?.toolTip = NSLocalizedString("Add freehand drawings by hand writing just like you do with a pen.", comment: "")
  756. item?.boxImagePosition = .imageOnly
  757. item?.btnAction = #selector(changeAnnotationMode)
  758. } else if identifier == KMToolbarFreeTextAnnotationItemIdentifier {
  759. item?.titleName = NSLocalizedString("Text Note", comment: "")
  760. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsText)
  761. item?.target = self
  762. item?.btnTag = CAnnotationType.freeText.rawValue
  763. item?.toolTip = String(format: "%@ (⌘N)", NSLocalizedString("Text Note", comment: ""))
  764. item?.boxImagePosition = .imageOnly
  765. item?.btnAction = #selector(changeAnnotationMode)
  766. } else if identifier == KMToolbarAnchoredAnnotationItemIdentifier {
  767. item?.titleName = NSLocalizedString("Anchored Note", comment: "")
  768. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsNote)
  769. item?.target = self
  770. item?.btnTag = CAnnotationType.anchored.rawValue
  771. item?.toolTip = String(format: "%@ (⌥⌘N)", NSLocalizedString("Anchored Note", comment: ""))
  772. item?.boxImagePosition = .imageOnly
  773. item?.btnAction = #selector(changeAnnotationMode)
  774. } else if identifier == KMToolbarSquareAnnotationItemIdentifier {
  775. item?.titleName = NSLocalizedString("Square", comment: "")
  776. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsRec)
  777. item?.target = self
  778. item?.btnTag = CAnnotationType.square.rawValue
  779. item?.toolTip = NSLocalizedString("Draw rectangle; draw square by holding Shift key", comment: "")
  780. item?.boxImagePosition = .imageOnly
  781. item?.btnAction = #selector(changeAnnotationMode)
  782. }else if identifier == KMToolbarCircleAnnotationItemIdentifier {
  783. item?.titleName = NSLocalizedString("oval", comment: "")
  784. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsOval)
  785. item?.target = self
  786. item?.btnTag = CAnnotationType.circle.rawValue
  787. item?.toolTip = NSLocalizedString("Draw oval; draw circle by holding Shift key", comment: "")
  788. item?.boxImagePosition = .imageOnly
  789. item?.btnAction = #selector(changeAnnotationMode)
  790. } else if identifier == KMToolbarArrowAnnotationItemIdentifier {
  791. item?.titleName = NSLocalizedString("Arrow", comment: "")
  792. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsArrow)
  793. item?.target = self
  794. item?.btnTag = CAnnotationType.arrow.rawValue
  795. item?.toolTip = NSLocalizedString("Draw arrow; draw straight arrow by holding Shift key", comment: "")
  796. item?.boxImagePosition = .imageOnly
  797. item?.btnAction = #selector(changeAnnotationMode)
  798. } else if identifier == KMToolbarLineAnnotationItemIdentifier {
  799. item?.titleName = NSLocalizedString("Square", comment: "")
  800. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsLine)
  801. item?.target = self
  802. item?.btnTag = CAnnotationType.line.rawValue
  803. item?.toolTip = NSLocalizedString("Draw line; draw straight line by holding Shift key", comment: "")
  804. item?.boxImagePosition = .imageOnly
  805. item?.btnAction = #selector(changeAnnotationMode)
  806. } else if identifier == KMToolbarLinkAnnotationItemIdentifier {
  807. item?.titleName = NSLocalizedString("Link", comment: "")
  808. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsLink)
  809. item?.target = self
  810. item?.btnTag = CAnnotationType.link.rawValue
  811. item?.toolTip = NSLocalizedString("Select an area or text on a page for a link to be inserted.", comment: "")
  812. item?.boxImagePosition = .imageOnly
  813. item?.btnAction = #selector(changeAnnotationMode)
  814. } else if identifier == KMToolbarSignSignatureAnnotationItemIdentifier {
  815. item?.titleName = NSLocalizedString("SignSignature", comment: "")
  816. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsSign)
  817. item?.target = self
  818. item?.btnTag = CAnnotationType.signSignature.rawValue
  819. item?.toolTip = NSLocalizedString("Add beautiful handwriting or use your trackpad to create your own signature.", comment: "")
  820. item?.boxImagePosition = .imageOnly
  821. item?.btnAction = #selector(changeAnnotationMode)
  822. } else if identifier == KMAnnotationStampToolbarItemIdentifier {
  823. item?.titleName = NSLocalizedString("Stamp", comment: "")
  824. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsStamp)
  825. item?.target = self
  826. item?.btnTag = CAnnotationType.stamp.rawValue
  827. item?.toolTip = NSLocalizedString("Add New Stamp", comment: "")
  828. item?.boxImagePosition = .imageOnly
  829. item?.btnAction = #selector(changeAnnotationMode)
  830. } else if identifier == KMToolbarShowToolbarItemIdentifier {
  831. item?.image = NSImage(named: "KMImageNameMainToolShow")
  832. item?.selectedImage = NSImage(named: "KMImageNameMainToolHide")
  833. item?.alternateImage = NSImage(named: "KMImageNameMainToolShow")
  834. item?.selectedBackgroundColor = NSColor.clear
  835. item?.target = self
  836. item?.toolTip = NSLocalizedString("Hide", comment: "")
  837. item?.titleName = NSLocalizedString("Hide", comment: "")
  838. item?.boxImagePosition = .imageOnly
  839. item?.btnAction = #selector(showPDFLayoutMode)
  840. } else if identifier == KMToolbarAddTextEditPDFItemIdentifier {
  841. item?.image = NSImage(named: "KMImageNameMainToolFreeText")
  842. item?.target = self
  843. item?.btnTag = CAnnotationType.addText.rawValue
  844. item?.toolTip = NSLocalizedString("Add Text", comment: "")
  845. item?.titleName = NSLocalizedString("Add Text", comment: "")
  846. item?.boxImagePosition = .imageLeft
  847. item?.btnAction = #selector(changeAnnotationMode)
  848. } else if identifier == KMToolbarAddImageEditPDFItemIdentifier {
  849. item?.image = NSImage(named: "KMImageNameMainToolEditImage")
  850. item?.target = self
  851. item?.btnTag = CAnnotationType.addImage.rawValue
  852. item?.toolTip = NSLocalizedString("Add Image", comment: "")
  853. item?.titleName = NSLocalizedString("Add Image", comment: "")
  854. item?.boxImagePosition = .imageLeft
  855. item?.btnAction = #selector(changeAnnotationMode)
  856. } else if identifier == KMToolbarToolCropItemIdentifier {
  857. item?.image = NSImage(named: "KMImageNameMainToolsCrop")
  858. item?.alternateImage = NSImage(named: "KMImageNameMainToolsCrop")
  859. item?.target = self
  860. item?.btnTag = KMToolbarType.crop.rawValue
  861. item?.toolTip = NSLocalizedString("Crop pages", comment: "")
  862. item?.titleName = NSLocalizedString("Crop", comment: "")
  863. item?.boxImagePosition = .imageExpandLeft
  864. item?.btnAction = #selector(cropMenuAction)
  865. let menuItem = NSMenuItem.init(title: "Crop", action: #selector(cropMenuAction), target: self)
  866. item?.menuFormRepresentation = menuItem
  867. } else if identifier == KMToolbarComparisonItemIdentifier {
  868. item?.image = NSImage(named: KMImageNameUXIconBatchComparison)
  869. item?.target = self
  870. item?.btnTag = KMToolbarType.comparison.rawValue
  871. item?.toolTip = NSLocalizedString("Compare", comment: "")
  872. item?.titleName = NSLocalizedString("Compare", comment: "")
  873. item?.boxImagePosition = .imageLeft
  874. item?.btnAction = #selector(itemAction)
  875. } else if identifier == KMToolbarToolBatesItemIdentifier {
  876. item?.image = NSImage(named: "KMImageNameUXIconBatchBatesNor")
  877. item?.target = self
  878. item?.btnTag = KMToolbarType.bates.rawValue
  879. item?.toolTip = NSLocalizedString("Add PDF Bates numbering to your legal, medical, or business documents", comment: "")
  880. item?.titleName = NSLocalizedString("Bates Number", comment: "")
  881. item?.boxImagePosition = .imageLeft
  882. item?.btnAction = #selector(batesMenuAction)
  883. let menuItem = NSMenuItem.init(title: "Bates Number", action: #selector(batesMenuAction), target: self)
  884. item?.menuFormRepresentation = menuItem
  885. } else if identifier == KMToolbarToolHeaderFooterItemIdentifier {
  886. item?.image = NSImage(named: "KMImageNameUXIconBatchHeaderandfooterNor")
  887. item?.target = self
  888. item?.btnTag = KMToolbarType.headerAndFooter.rawValue
  889. item?.toolTip = NSLocalizedString("Insert header, footer, and page numbers to PDF", comment: "")
  890. item?.titleName = NSLocalizedString("Header & Footer", comment: "")
  891. item?.boxImagePosition = .imageLeft
  892. item?.btnAction = #selector(headerfooterMenuAction)
  893. let menuItem = NSMenuItem.init(title: "Header&Footer", action: #selector(headerfooterMenuAction), target: self)
  894. item?.menuFormRepresentation = menuItem
  895. } else if identifier == KMToolbarToolBackgroundItemIdentifier {
  896. item?.image = NSImage(named: "KMImageNameUXIconBatchBackgroundNor")
  897. item?.target = self
  898. item?.btnTag = KMToolbarType.background.rawValue
  899. item?.toolTip = NSLocalizedString("Insert PDF page background by color or image", comment: "")
  900. item?.titleName = NSLocalizedString("Backgroud", comment: "")
  901. item?.boxImagePosition = .imageLeft
  902. item?.btnAction = #selector(backgroundMenuAction)
  903. let menuItem = NSMenuItem.init(title: "Backgroud", action: #selector(backgroundMenuAction), target: self)
  904. item?.menuFormRepresentation = menuItem
  905. } else if identifier == KMToolbarToolWatermarkItemIdentifier {
  906. item?.image = NSImage(named: "KMImageNameMainToolsWatermark")
  907. item?.target = self
  908. item?.btnTag = KMToolbarType.watermark.rawValue
  909. item?.toolTip = NSLocalizedString("Watermark", comment: "")
  910. item?.titleName = NSLocalizedString("Watermark", comment: "")
  911. item?.boxImagePosition = .imageLeft
  912. item?.btnAction = #selector(watermarkMenuAction)
  913. let menuItem = NSMenuItem.init(title: "Watermark", action: #selector(watermarkMenuAction), target: self)
  914. item?.menuFormRepresentation = menuItem
  915. } else if identifier == KMToolbarToolTextFieldItemIdentifier {
  916. item?.image = NSImage(named: "KMImageNameMainToolFormText")
  917. item?.target = self
  918. item?.btnTag = CAnnotationType.textField.rawValue
  919. item?.toolTip = NSLocalizedString("TextField", comment: "")
  920. item?.titleName = NSLocalizedString("TextField", comment: "")
  921. item?.boxImagePosition = .imageOnly
  922. item?.btnAction = #selector(changeAnnotationMode)
  923. let menuItem = NSMenuItem.init(title: "TextField", action: #selector(changeAnnotationMode), target: self)
  924. menuItem.tag = item!.btnTag
  925. item?.menuFormRepresentation = menuItem
  926. } else if identifier == KMToolbarToolCheckBoxItemIdentifier {
  927. item?.image = NSImage(named: "KMImageNameMainToolFormCheckbox")
  928. item?.target = self
  929. item?.btnTag = CAnnotationType.checkBox.rawValue
  930. item?.toolTip = NSLocalizedString("CheckBox", comment: "")
  931. item?.titleName = NSLocalizedString("CheckBox", comment: "")
  932. item?.boxImagePosition = .imageOnly
  933. item?.btnAction = #selector(changeAnnotationMode)
  934. } else if identifier == KMToolbarToolRadioButtonItemIdentifier {
  935. item?.image = NSImage(named: "KMImageNameMainToolFormRadio")
  936. item?.target = self
  937. item?.btnTag = CAnnotationType.radioButton.rawValue
  938. item?.toolTip = NSLocalizedString("RadioButton", comment: "")
  939. item?.titleName = NSLocalizedString("RadioButton", comment: "")
  940. item?.boxImagePosition = .imageOnly
  941. item?.btnAction = #selector(changeAnnotationMode)
  942. let menuItem = NSMenuItem.init(title: "RadioButton", action: #selector(changeAnnotationMode), target: self)
  943. menuItem.tag = item!.btnTag
  944. item?.menuFormRepresentation = menuItem
  945. } else if identifier == KMToolbarToolListBoxItemIdentifier {
  946. item?.image = NSImage(named: "KMImageNameMainToolFormListBox")
  947. item?.target = self
  948. item?.btnTag = CAnnotationType.listMenu.rawValue
  949. item?.toolTip = NSLocalizedString("ListBox", comment: "")
  950. item?.titleName = NSLocalizedString("ListBox", comment: "")
  951. item?.boxImagePosition = .imageOnly
  952. item?.btnAction = #selector(changeAnnotationMode)
  953. let menuItem = NSMenuItem.init(title: "ListBox", action: #selector(changeAnnotationMode), target: self)
  954. menuItem.tag = item!.btnTag
  955. item?.menuFormRepresentation = menuItem
  956. } else if identifier == KMToolbarToolPullDownmenuItemIdentifier {
  957. item?.image = NSImage(named: "KMImageNameMainToolFormPulldown")
  958. item?.target = self
  959. item?.btnTag = CAnnotationType.comboBox.rawValue
  960. item?.toolTip = NSLocalizedString("PullDownmenu", comment: "")
  961. item?.titleName = NSLocalizedString("PullDownmenu", comment: "")
  962. item?.boxImagePosition = .imageOnly
  963. item?.btnAction = #selector(changeAnnotationMode)
  964. let menuItem = NSMenuItem.init(title: "PullDownmenu", action: #selector(changeAnnotationMode), target: self)
  965. menuItem.tag = item!.btnTag
  966. item?.menuFormRepresentation = menuItem
  967. } else if identifier == KMToolbarToolButtonIdentifier {
  968. item?.image = NSImage(named: "KMImageNameMainToolFormButton")
  969. item?.target = self
  970. item?.btnTag = CAnnotationType.actionButton.rawValue
  971. item?.toolTip = NSLocalizedString("Button", comment: "")
  972. item?.titleName = NSLocalizedString("Button", comment: "")
  973. item?.boxImagePosition = .imageOnly
  974. item?.btnAction = #selector(changeAnnotationMode)
  975. let menuItem = NSMenuItem.init(title: "Button", action: #selector(changeAnnotationMode), target: self)
  976. menuItem.tag = item!.btnTag
  977. item?.menuFormRepresentation = menuItem
  978. } else if identifier == KMToolbarToolSignBoxIdentifier {
  979. item?.image = NSImage(named: "KMImageNameMainToolFormSign")
  980. item?.target = self
  981. item?.btnTag = CAnnotationType.signature.rawValue
  982. item?.toolTip = NSLocalizedString("SignBox", comment: "")
  983. item?.titleName = NSLocalizedString("SignBox", comment: "")
  984. item?.boxImagePosition = .imageOnly
  985. item?.btnAction = #selector(changeAnnotationMode)
  986. let menuItem = NSMenuItem.init(title: "SignBox", action: #selector(changeAnnotationMode), target: self)
  987. menuItem.tag = item!.btnTag
  988. item?.menuFormRepresentation = menuItem
  989. } else if identifier == KMToolbarToolFormAlignIdentifier {
  990. item?.image = NSImage(named: "KMImageNameMainToolFormAlignment")
  991. item?.target = self
  992. item?.toolTip = NSLocalizedString("Alignment", comment: "")
  993. item?.titleName = NSLocalizedString("Alignment", comment: "")
  994. item?.boxImagePosition = .imageExpandLeft
  995. item?.btnAction = #selector(formsAlignmentAction)
  996. let menuItem = NSMenuItem.init(title: "Alignment", action: #selector(formsAlignmentAction), target: self)
  997. menuItem.tag = item!.btnTag
  998. item?.menuFormRepresentation = menuItem
  999. } else if identifier == KMToolbarToolFormMoreIdentifier {
  1000. item?.image = NSImage(named: "KMImageNameMainToolFormMore")
  1001. item?.target = self
  1002. item?.toolTip = NSLocalizedString("More", comment: "")
  1003. item?.titleName = NSLocalizedString("More", comment: "")
  1004. item?.boxImagePosition = .imageExpandLeft
  1005. item?.btnAction = #selector(formsMoreOperationAction)
  1006. let menuItem = NSMenuItem.init(title: "More", action: #selector(formsMoreOperationAction), target: self)
  1007. menuItem.tag = item!.btnTag
  1008. item?.menuFormRepresentation = menuItem
  1009. } else if identifier == KMToolbarToolRedactItemIdentifier {
  1010. item?.image = NSImage(named: "KMImageNameMainToolsRedact")
  1011. item?.target = self
  1012. item?.btnTag = KMToolbarType.redact.rawValue
  1013. item?.toolTip = NSLocalizedString("Redact", comment: "")
  1014. item?.titleName = NSLocalizedString("Redact", comment: "")
  1015. item?.btnAction = #selector(redactMenuAction)
  1016. let menuItem = NSMenuItem.init(title: "Redact", action: #selector(changeAnnotationMode), target: self)
  1017. menuItem.tag = item!.btnTag
  1018. item?.menuFormRepresentation = menuItem
  1019. } else if identifier == KMToolbarToolCompressItemIdentifier {
  1020. item?.image = NSImage(named: "KMImageNameUXIconBatchOptimizeNor")
  1021. item?.target = self
  1022. item?.btnTag = KMToolbarType.compress.rawValue
  1023. item?.boxImagePosition = .imageLeft
  1024. item?.toolTip = NSLocalizedString("Reduce file size", comment: "")
  1025. item?.titleName = NSLocalizedString("Compress", comment: "")
  1026. item?.btnAction = #selector(compressMenuAction)
  1027. } else if identifier == KMToolbarToolSecureItemIdentifier {
  1028. item?.image = NSImage(named: "KMImageNameUXIconBatchSafeNor")
  1029. item?.target = self
  1030. item?.toolTip = NSLocalizedString("Batch encrypting PDF documents", comment: "")
  1031. item?.titleName = NSLocalizedString("Security", comment: "")
  1032. item?.boxImagePosition = .imageExpandLeft
  1033. item?.btnAction = #selector(secureMenuAction)
  1034. let menuItem = NSMenuItem.init(title: "Security", action: #selector(secureMenuAction), target: self)
  1035. menuItem.tag = item!.btnTag
  1036. item?.menuFormRepresentation = menuItem
  1037. } else if identifier == KMToolbarToolHookItemIdentifier {
  1038. item?.image = NSImage(named: "KMImageNameFillSignHook")
  1039. item?.target = self
  1040. item?.btnTag = CAnnotationType.signTure.rawValue
  1041. item?.toolTip = NSLocalizedString("Signature", comment: "")
  1042. item?.titleName = NSLocalizedString("Signature", comment: "")
  1043. item?.boxImagePosition = .imageOnly
  1044. item?.btnAction = #selector(changeAnnotationMode)
  1045. } else if identifier == KMToolbarToolForkItemIdentifier {
  1046. item?.image = NSImage(named: "KMImageNameFillSignFork")
  1047. item?.target = self
  1048. item?.btnTag = CAnnotationType.signFalse.rawValue
  1049. item?.toolTip = NSLocalizedString("X", comment: "")
  1050. item?.titleName = NSLocalizedString("signFalse", comment: "")
  1051. item?.boxImagePosition = .imageOnly
  1052. item?.btnAction = #selector(changeAnnotationMode)
  1053. } else if identifier == KMToolbarToolLineItemIdentifier {
  1054. item?.image = NSImage(named: "KMImageNameFillSignLine")
  1055. item?.target = self
  1056. item?.btnTag = CAnnotationType.signLine.rawValue
  1057. item?.toolTip = NSLocalizedString("Line", comment: "")
  1058. item?.titleName = NSLocalizedString("Line", comment: "")
  1059. item?.boxImagePosition = .imageOnly
  1060. item?.btnAction = #selector(changeAnnotationMode)
  1061. } else if identifier == KMToolbarToolDotItemIdentifier {
  1062. item?.image = NSImage(named: "KMImageNameFillSignDot")
  1063. item?.target = self
  1064. item?.btnTag = CAnnotationType.signDot.rawValue
  1065. item?.toolTip = NSLocalizedString("Dot", comment: "")
  1066. item?.titleName = NSLocalizedString("Dot", comment: "")
  1067. item?.boxImagePosition = .imageOnly
  1068. item?.btnAction = #selector(changeAnnotationMode)
  1069. } else if identifier == KMToolbarToolRectangleIdentifier {
  1070. item?.image = NSImage(named: "KMImageNameFillSignRectangle")
  1071. item?.target = self
  1072. item?.btnTag = CAnnotationType.signCircle.rawValue
  1073. item?.toolTip = NSLocalizedString("Rectangle", comment: "")
  1074. item?.titleName = NSLocalizedString("Rectangle", comment: "")
  1075. item?.boxImagePosition = .imageOnly
  1076. item?.btnAction = #selector(changeAnnotationMode)
  1077. } else if identifier == KMToolbarToolTextIdentifier {
  1078. item?.image = NSImage(named: "KMImageNameMainToolFreeText")
  1079. item?.target = self
  1080. item?.btnTag = CAnnotationType.signText.rawValue
  1081. item?.toolTip = NSLocalizedString("Add a handwritten signature or create a signature via the trackpad", comment: "")
  1082. item?.titleName = NSLocalizedString("signText", comment: "")
  1083. item?.boxImagePosition = .imageOnly
  1084. item?.btnAction = #selector(changeAnnotationMode)
  1085. } else if identifier == KMToolbarToolDateIdentifier {
  1086. item?.image = NSImage(named: "KMImageNameFillSignDate")
  1087. item?.target = self
  1088. item?.btnTag = CAnnotationType.signDate.rawValue
  1089. item?.toolTip = NSLocalizedString("Date", comment: "")
  1090. item?.titleName = NSLocalizedString("Date", comment: "")
  1091. item?.boxImagePosition = .imageOnly
  1092. item?.btnAction = #selector(changeAnnotationMode)
  1093. } else if (identifier == KMToolbarFillSignSignatureIdentifier) {
  1094. item?.image = NSImage(named: "KMImageNameMainToolSignSignature")
  1095. item?.target = self
  1096. item?.btnTag = CAnnotationType.signSignature.rawValue
  1097. item?.toolTip = NSLocalizedString("Add a handwritten signature or create a signature via the trackpad", comment: "")
  1098. item?.boxImagePosition = .imageOnly
  1099. item?.btnAction = #selector(changeAnnotationMode)
  1100. } else if identifier == KMToolbarConversionWordItemIdentifier {
  1101. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertWord)
  1102. item?.target = self
  1103. item?.btnTag = KMToolbarType.word.rawValue
  1104. item?.toolTip = NSLocalizedString("Convert all the great work stored in your PDF to a Word document that’s easy to update. Keep the fonts and layouts intact — including bullets and tables.", comment: "")
  1105. item?.titleName = NSLocalizedString("To Word", comment: "")
  1106. item?.boxImagePosition = .imageLeft
  1107. item?.btnAction = #selector(conversionMenuItemAction)
  1108. } else if identifier == KMToolbarConversionExcelItemIdentifier {
  1109. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertExcel)
  1110. item?.target = self
  1111. item?.btnTag = KMToolbarType.excel.rawValue
  1112. item?.toolTip = NSLocalizedString("Skip the data entry steps and tedious reformatting tasks, too. When you convert to Excel, your data is preserved along with your columns, layouts, and formatting.", comment: "")
  1113. item?.titleName = NSLocalizedString("To Excel", comment: "")
  1114. item?.boxImagePosition = .imageLeft
  1115. item?.btnAction = #selector(conversionMenuItemAction)
  1116. } else if identifier == KMToolbarConversionPPTItemIdentifier {
  1117. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPPT)
  1118. item?.target = self
  1119. item?.btnTag = KMToolbarType.ppt.rawValue
  1120. item?.toolTip = NSLocalizedString("When you use PDF Reader Pro to convert PDFs to PowerPoint, you know your formats will be saved, too. So you don’t have to bother redoing bullets, tables, objects, or master layouts.", comment: "")
  1121. item?.titleName = NSLocalizedString("To PPT", comment: "")
  1122. item?.boxImagePosition = .imageLeft
  1123. item?.btnAction = #selector(conversionMenuItemAction)
  1124. } else if identifier == KMToolbarConversionRTFItemIdentifier {
  1125. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertRTF)
  1126. item?.target = self
  1127. item?.btnTag = KMToolbarType.rtf.rawValue
  1128. item?.toolTip = NSLocalizedString("Turn PDF documents into Rich Text Format (RTF) files that can be opened in virtually any word processor.", comment: "")
  1129. item?.titleName = NSLocalizedString("To RTF", comment: "")
  1130. item?.boxImagePosition = .imageLeft
  1131. item?.btnAction = #selector(conversionMenuItemAction)
  1132. } else if identifier == KMToolbarConversionCSVItemIdentifier {
  1133. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertCSV)
  1134. item?.target = self
  1135. item?.btnTag = KMToolbarType.csv.rawValue
  1136. item?.toolTip = NSLocalizedString("PDF To CSV", comment: "")
  1137. item?.titleName = NSLocalizedString("To CSV", comment: "")
  1138. item?.boxImagePosition = .imageLeft
  1139. item?.btnAction = #selector(conversionMenuItemAction)
  1140. } else if identifier == KMToolbarConversionHTMLItemIdentifier {
  1141. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertHtml)
  1142. item?.target = self
  1143. item?.btnTag = KMToolbarType.html.rawValue
  1144. item?.toolTip = NSLocalizedString("PDF To HTML", comment: "")
  1145. item?.titleName = NSLocalizedString("To HTML", comment: "")
  1146. item?.boxImagePosition = .imageLeft
  1147. item?.btnAction = #selector(conversionMenuItemAction)
  1148. } else if identifier == KMToolbarConversionTextItemIdentifier {
  1149. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertText)
  1150. item?.target = self
  1151. item?.btnTag = KMToolbarType.conversion_text.rawValue
  1152. item?.toolTip = NSLocalizedString("PDF To Text", comment: "")
  1153. item?.titleName = NSLocalizedString("To Text", comment: "")
  1154. item?.boxImagePosition = .imageLeft
  1155. item?.btnAction = #selector(conversionMenuItemAction)
  1156. } else if identifier == KMToolbarConversionImageItemIdentifier {
  1157. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPDFToIMG)
  1158. item?.target = self
  1159. item?.btnTag = KMToolbarType.conversion_image.rawValue
  1160. item?.toolTip = NSLocalizedString("Convert PDF to JPEG, PNG, TIFF, BMP, GIF or TGA files", comment: "")
  1161. item?.titleName = NSLocalizedString("To Image", comment: "")
  1162. item?.boxImagePosition = .imageLeft
  1163. item?.btnAction = #selector(conversionMenuItemAction)
  1164. } else if identifier == KMToolbarToolMergeItemIdentifier {
  1165. item?.image = NSImage(named: "KMImageNameUXIconBatchMergeNor")
  1166. item?.target = self
  1167. item?.btnTag = KMToolbarType.merge.rawValue
  1168. item?.toolTip = NSLocalizedString("Combine multiple documents into a new PDF, or borrow individual pages", comment: "")
  1169. item?.titleName = NSLocalizedString("Merge", comment: "")
  1170. item?.boxImagePosition = .imageLeft
  1171. item?.btnAction = #selector(mergeMenuItemAction)
  1172. } else if identifier == KMToolbarAnnotationSettingItemIdentifier {
  1173. item?.image = NSImage(named: "KMImageNameUXIconBtnSetNor")
  1174. item?.target = self
  1175. item?.titleName = NSLocalizedString("Setting", comment: "")
  1176. item?.boxImagePosition = .imageOnly
  1177. item?.btnAction = #selector(itemAction)
  1178. }
  1179. }
  1180. return item!
  1181. }
  1182. func validateToolbarItem(_ item: NSToolbarItem) -> Bool {
  1183. return true
  1184. }
  1185. @objc func listViewAnnotationTypeChangeNotification(sender: Notification?) {
  1186. // if let notiName = sender?.name, notiName == NSNotification.Name.CPDFListViewAnnotationTypeChange, self.ignoreCurrentAnnotationTypeChange {
  1187. // }
  1188. if (self.ignoreCurrentAnnotationTypeChange) {
  1189. // 忽略后重置 这个属性是基于单次添加,所以使用后会重置
  1190. // self.ignoreCurrentAnnotationTypeChange = false
  1191. return
  1192. }
  1193. let annotationType : CAnnotationType = pdfView.annotationType
  1194. if annotationType == .square || annotationType == .circle || annotationType == .arrow || annotationType == .line{
  1195. UserDefaults.standard.set(pdfView.annotationType.rawValue, forKey: KMToolBarToolPDFShapeStyle)
  1196. UserDefaults.standard.synchronize()
  1197. }
  1198. for item in self.toolbar.items {
  1199. if self.toolbarType == .Annatiton || self.toolbarType == .Move || self.toolbarType == .Magnify ||
  1200. self.toolbarType == .Select || self.toolbarType == .SelectZoom {
  1201. item.isSelected = false
  1202. if item.itemIdentifier == KMDocumentAnnotationToolbarItemIdentifier {
  1203. item.isSelected = true
  1204. } else if item.itemIdentifier == KMToolbarHighlightAnnotationItemIdentifier {
  1205. if annotationType == .highlight {
  1206. item.isSelected = true
  1207. }
  1208. } else if item.itemIdentifier == KMToolbarUnderlineAnnotationItemIdentifier {
  1209. if annotationType == .underline {
  1210. item.isSelected = true
  1211. }
  1212. } else if item.itemIdentifier == KMToolbarStrikeOutAnnotationItemIdentifier {
  1213. if annotationType == .strikeOut {
  1214. item.isSelected = true
  1215. }
  1216. } else if item.itemIdentifier == KMToolbarInkAnnotationItemIdentifier {
  1217. if annotationType == .ink || annotationType == .eraser {
  1218. item.isSelected = true
  1219. }
  1220. } else if item.itemIdentifier == KMToolbarFreeTextAnnotationItemIdentifier {
  1221. if annotationType == .freeText {
  1222. item.isSelected = true
  1223. }
  1224. } else if item.itemIdentifier == KMToolbarAnchoredAnnotationItemIdentifier {
  1225. if annotationType == .anchored {
  1226. item.isSelected = true
  1227. }
  1228. } else if item.itemIdentifier == KMToolbarSquareAnnotationItemIdentifier {
  1229. if annotationType == .square {
  1230. item.isSelected = true
  1231. }
  1232. } else if item.itemIdentifier == KMToolbarCircleAnnotationItemIdentifier {
  1233. if annotationType == .circle {
  1234. item.isSelected = true
  1235. }
  1236. } else if item.itemIdentifier == KMToolbarArrowAnnotationItemIdentifier {
  1237. if annotationType == .arrow {
  1238. item.isSelected = true
  1239. }
  1240. } else if item.itemIdentifier == KMToolbarLineAnnotationItemIdentifier {
  1241. if annotationType == .line {
  1242. item.isSelected = true
  1243. }
  1244. } else if item.itemIdentifier == KMToolbarLinkAnnotationItemIdentifier {
  1245. if annotationType == .link {
  1246. item.isSelected = true
  1247. }
  1248. } else if item.itemIdentifier == KMAnnotationStampToolbarItemIdentifier {
  1249. if annotationType == .stamp {
  1250. item.isSelected = true
  1251. }
  1252. } else if item.itemIdentifier == KMToolbarSignSignatureAnnotationItemIdentifier {
  1253. if annotationType == .signSignature {
  1254. item.isSelected = true
  1255. }
  1256. } else if pdfView.toolMode == .moveToolMode {
  1257. if item.itemIdentifier == KMToolbarMoveToolModeItemIdentifier {
  1258. item.isSelected = true
  1259. }
  1260. } else if pdfView.toolMode == .magnifyToolMode {
  1261. if item.itemIdentifier == KMToolbarMagnifyToolModeItemIdentifier {
  1262. item.isSelected = true
  1263. }
  1264. } else if pdfView.toolMode == .selectToolMode {
  1265. if item.itemIdentifier == KMToolbarSelectToolModeItemIdentifier {
  1266. item.isSelected = true
  1267. }
  1268. } else if pdfView.toolMode == .selectZoomToolMode {
  1269. if item.itemIdentifier == KMToolbarZoomToSelectionItemIdentifier {
  1270. item.isSelected = true
  1271. }
  1272. }
  1273. if (item.itemIdentifier == KMToolbarShowToolbarItemIdentifier) {
  1274. item.isSelected = !self.isShowAllAnnotations
  1275. }
  1276. } else if self.toolbarType == .FillSign {
  1277. item.isSelected = false
  1278. if pdfView.toolMode == .selfSignMode {
  1279. if item.itemIdentifier == KMToolbarToolHookItemIdentifier {
  1280. if annotationType == .signTure {
  1281. item.isSelected = true
  1282. }
  1283. } else if item.itemIdentifier == KMToolbarToolForkItemIdentifier {
  1284. if annotationType == .signFalse {
  1285. item.isSelected = true
  1286. }
  1287. } else if item.itemIdentifier == KMToolbarToolLineItemIdentifier {
  1288. if annotationType == .signLine {
  1289. item.isSelected = true
  1290. }
  1291. } else if item.itemIdentifier == KMToolbarToolDotItemIdentifier {
  1292. if annotationType == .signDot {
  1293. item.isSelected = true
  1294. }
  1295. } else if item.itemIdentifier == KMToolbarToolRectangleIdentifier {
  1296. if annotationType == .signCircle {
  1297. item.isSelected = true
  1298. }
  1299. } else if item.itemIdentifier == KMToolbarToolDateIdentifier {
  1300. if annotationType == .signDate {
  1301. item.isSelected = true
  1302. }
  1303. } else if item.itemIdentifier == KMToolbarToolTextIdentifier {
  1304. if annotationType == .signText {
  1305. item.isSelected = true
  1306. }
  1307. } else if (item.itemIdentifier == KMToolbarFillSignSignatureIdentifier) {
  1308. if (annotationType == .signSignature) {
  1309. item.isSelected = true
  1310. }
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. extension KMToolbarViewController: NSSearchFieldDelegate {
  1318. }