KMToolbarViewController.swift 84 KB

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