KMToolbarViewController.swift 84 KB

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