KMToolbarViewController.swift 79 KB

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