KMToolbarViewController.swift 84 KB

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