KMToolbarViewController.swift 80 KB

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