KMToolbarViewController.swift 84 KB

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