KMToolbarViewController.swift 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. //
  2. // KMToolbarViewController.swift
  3. // PDF Reader Pro
  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. case viewSetting
  27. case AITools
  28. func isToolMode() -> Bool {
  29. return (self == .Move || self == .Magnify || self == .Select || self == .SelectZoom)
  30. }
  31. func itemIdentifier() -> String {
  32. if (self == .Annatiton) {
  33. return KMDocumentAnnotationToolbarItemIdentifier
  34. } else if (self == .Page) {
  35. return KMDocumentPageToolbarItemIdentifier
  36. } else if (self == .Conversion) {
  37. return KMDocumentConversonToolbarItemIdentifier
  38. } else if (self == .ScanOCR) {
  39. return KMDocumentScanOCRToolbarItemIdentifier
  40. } else if (self == .editPDF) {
  41. return KMDocumentEditToolbarItemIdentifier
  42. } else if (self == .Form) {
  43. return KMDocumentFormToolbarItemIdentifier
  44. } else if (self == .FillSign) {
  45. return KMDocumentFillSginToolbarItemIdentifier
  46. } else if (self == .Tool) {
  47. return KMDocumentToolToolbarItemIdentifier
  48. } else if (self == .Move) {
  49. return KMToolbarMoveToolModeItemIdentifier
  50. } else if (self == .Magnify) {
  51. return KMToolbarMagnifyToolModeItemIdentifier
  52. } else if (self == .Select) {
  53. return KMToolbarSelectToolModeItemIdentifier
  54. } else if (self == .SelectZoom) {
  55. return KMToolbarZoomToSelectionItemIdentifier
  56. } else if (self == .LeftPanel) {
  57. return KMLeftControlToolbarItemIdentifier
  58. } else if (self == .RightPanel) {
  59. return KMRightControlToolbarItemIdentifier
  60. } else if (self == .AITools) {
  61. return KMDocumentAIToolsToolbarItemIdentifier
  62. }
  63. return ""
  64. }
  65. }
  66. @objc enum KMToolbarType: Int {
  67. /// conversion
  68. case word = 3000
  69. case excel = 3001
  70. case ppt = 3002
  71. case rtf = 3003
  72. case csv = 3004
  73. case html = 3005
  74. case conversion_text = 3006
  75. case conversion_image = 3007
  76. /// tool
  77. case compress = 8000
  78. case merge = 8001
  79. case fileCompare = 8002
  80. case secure = 8003
  81. case redact = 8004
  82. case watermark = 8005
  83. case background = 8006
  84. case headerAndFooter = 8007
  85. case bates = 8008
  86. case crop = 8009
  87. case comparison = 8010
  88. case aiTools = 8011
  89. }
  90. @objc protocol KMToolbarViewControllerDelegate {
  91. @objc optional func changeAnnotationModeAction(item:KMToolbarClickButton)
  92. @objc optional func showPDFLayoutModeAction(show:Bool)
  93. @objc optional func changePDFViewZoomInAction()
  94. @objc optional func changePDFViewZoomOutAction()
  95. @objc optional func changePDFViewGotoNextPageAction()
  96. @objc optional func changePDFViewGoToPreviousPageAction()
  97. @objc optional func changePDFViewGotoBackAction()
  98. @objc optional func changePDFViewGoToForwardAction()
  99. @objc optional func aiTranslationPDFFileAction()
  100. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
  101. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
  102. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareAction toolbarItem: KMToolbarItemView)
  103. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
  104. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
  105. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareOriginalPDF item:NSMenuItem)
  106. @objc optional func toolbarViewController(_ viewController: KMToolbarViewController, clickMode toolMode: KMToolbarViewType, toolbar toolbarItem: KMToolbarItemView, _ pages: [Int])
  107. @objc optional func toolbarViewController(_ viewController: KMToolbarViewController, clickChaildToolType: KMToolbarType, toolbar toolbarItem: KMToolbarItemView)
  108. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
  109. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView)
  110. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String, forward: Bool)
  111. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, findSearchAction searchString: String, forward: Bool)
  112. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
  113. @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, viewItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
  114. }
  115. class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
  116. var toolbar : KMToolbarView?
  117. var toolbarType : KMToolbarViewType = KMToolbarViewType.None
  118. var toolbarItems : [String : Any] = [:]
  119. @IBOutlet weak var mainWindowController : MainWindowController!
  120. open weak var delegate: KMToolbarViewControllerDelegate?
  121. @IBOutlet var zoomButton: NSPopUpButton!
  122. @IBOutlet var zoomView: NSView!
  123. @IBOutlet weak var zoomTextField: NSTextField!
  124. var searchField: NSSearchField = NSSearchField()
  125. var pdfView : CPDFListView = CPDFListView()
  126. var shareButton = KMToolbarClickButton()
  127. private var bottomLine = NSView()
  128. // 是否显示所有注释
  129. var isShowAllAnnotations = true
  130. var ignoreCurrentAnnotationTypeChange = false
  131. private var _currentItemView: KMToolbarItemView?
  132. override func viewDidLoad() {
  133. super.viewDidLoad()
  134. self.zoomTextField.delegate = self
  135. for item in self.zoomButton.itemArray {
  136. let string = item.title
  137. item.title = NSLocalizedString(string, comment: "")
  138. }
  139. NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewAnnotationTypeChangeNotification"), object: nil)
  140. NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewToolModeChangeNotification"), object: nil)
  141. }
  142. override func loadView() {
  143. super.loadView()
  144. self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
  145. self.toolbar?.frame = self.view.bounds
  146. self.toolbar?.autoresizingMask = [.width,.height]
  147. self.toolbar?.delegate = self
  148. self.view.addSubview(self.toolbar!)
  149. self.view.addSubview(self.bottomLine)
  150. self.bottomLine.frame = NSMakeRect(0, 0, NSWidth(self.view.bounds), 1)
  151. self.bottomLine.autoresizingMask = [.width]
  152. self.bottomLine.wantsLayer = true
  153. self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#0000001A").cgColor
  154. }
  155. func updateType(newType:KMToolbarViewType) {
  156. if newType != toolbarType {
  157. toolbarType = newType
  158. if self.toolbar != nil && self.toolbar?.superview != nil {
  159. self.toolbar?.removeFromSuperview()
  160. }
  161. self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
  162. self.toolbar?.frame = self.view.bounds
  163. self.toolbar?.autoresizingMask = [.width,.height]
  164. self.toolbar?.delegate = self
  165. self.view.addSubview(self.toolbar!)
  166. }
  167. }
  168. func reloadateToolbar() -> Void {
  169. self.toolbar?.reloadData()
  170. }
  171. func resetToolbar() -> Void {
  172. for item in self.toolbar?.items ?? [] {
  173. item.isSelected = false
  174. }
  175. }
  176. // MARK: Action
  177. @IBAction func changeAnnotationMode(item: KMToolbarClickButton) {
  178. self.delegate?.changeAnnotationModeAction?(item: item)
  179. if item.isKind(of: KMToolbarClickButton.self) {
  180. self._itemSetPromptFlag(item: item.clickObject as? KMToolbarItemView)
  181. } else {
  182. }
  183. }
  184. @IBAction func leftControllButtonAction(item: KMToolbarClickButton) {
  185. let tag = KMToolbarViewType(rawValue: item.tag) ?? .None
  186. if tag == .editPDF {
  187. if IAPProductsManager.default().isAvailableAllFunction() == false {
  188. KMPreference.shared.openDocumentType = .newWindow
  189. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  190. return
  191. }
  192. if !self.pdfView.document!.allowsPrinting || !self.pdfView.document!.allowsCopying {
  193. let alert = NSAlert()
  194. alert.alertStyle = .critical
  195. alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
  196. alert.runModal()
  197. return
  198. }
  199. Task { @MainActor in
  200. self.delegate?.toolbarViewController?(self, clickMode: tag, toolbar: item.clickObject as! KMToolbarItemView, [])
  201. }
  202. } else {
  203. self.delegate?.toolbarViewController?(self, clickMode: tag, toolbar: item.clickObject as! KMToolbarItemView, [])
  204. }
  205. self._itemSetPromptFlag(item: item.clickObject as? KMToolbarItemView)
  206. }
  207. @objc private func _itemAction(_ item: KMToolbarClickButton) {
  208. if item.clickObject?.itemIdentifier == KMAnnotationImageToolbarItemIdentifier || item.clickObject?.itemIdentifier == KMAnnotationTableToolbarItemIdentifier {
  209. self.pdfView.toolMode = .textToolMode
  210. self.pdfView.annotationType = .unkown
  211. }
  212. if let data = item.clickObject as? KMToolbarItemView {
  213. if data.itemIdentifier == KMToolbarComparisonItemIdentifier {
  214. self._currentItemView = data
  215. if let subMenu = data.menuFormRepresentation?.submenu {
  216. subMenu.popUp(positioning: nil, at: item.frame.origin, in: item.superview)
  217. }
  218. return
  219. }
  220. }
  221. if let itemView = item.clickObject as? KMToolbarItemView {
  222. if itemView.itemIdentifier == KMDocumentRedactToolbarItemIdentifier {
  223. self.delegate?.toolbarViewController?(self, clickMode: .redact, toolbar: itemView, [])
  224. } else {
  225. self.delegate?.toolbarViewController?(self, itemDidClick: itemView)
  226. }
  227. self._itemSetPromptFlag(item: itemView)
  228. }
  229. }
  230. @objc private func OCRbtnAction1(_ item: KMToolbarClickButton) {
  231. FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn": "Btn_Tbr_OCR"])
  232. self._itemAction(item)
  233. }
  234. @objc private func OCRbtnAction2(_ item: KMToolbarClickButton) {
  235. FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Converter", withProperties: ["SubTbr_Btn": "Btn_SubTbr_Converter_OCR"])
  236. self._itemAction(item)
  237. }
  238. @objc private func _menuItemAction(_ item: NSMenuItem) {
  239. guard let itemId = item.representedObject as? String else {
  240. NSSound.beep()
  241. return
  242. }
  243. let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
  244. self.delegate?.toolbarViewController?(self, menuItemDidClick: item_, index: 0, info: nil)
  245. self._itemSetPromptFlag(item: item_)
  246. }
  247. @objc private func _comparisonAction(sender: NSMenuItem) {
  248. if let data = self._currentItemView {
  249. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  250. } else {
  251. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarComparisonItemIdentifier), index: sender.tag, info: nil)
  252. }
  253. self._itemSetPromptFlag(itemIdentifier: KMToolbarComparisonItemIdentifier)
  254. }
  255. @IBAction func showPDFLayoutMode(sender: KMToolbarClickButton) {
  256. if let item = sender.clickObject as? KMToolbarItemView {
  257. item.isSelected = !item.isSelected
  258. self.delegate?.showPDFLayoutModeAction?(show: true)
  259. self._itemSetPromptFlag(item: item)
  260. }
  261. }
  262. @objc func cropMenuAction(item: KMToolbarItemView) {
  263. self.delegate?.toolbarViewController?(self, clickChaildToolType: .crop, toolbar: item)
  264. }
  265. @objc private func _cropAction(_ sender: NSMenuItem) {
  266. if let data = self._currentItemView {
  267. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  268. } else {
  269. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarCropIdentifier), index: sender.tag, info: nil)
  270. }
  271. self._itemSetPromptFlag(itemIdentifier: KMToolbarCropIdentifier)
  272. }
  273. @objc func batesMenuAction(sender: KMToolbarClickButton) {
  274. self._currentItemView = sender.clickObject as? KMToolbarItemView
  275. if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
  276. subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
  277. }
  278. }
  279. @objc private func _batesAction(sender: NSMenuItem) {
  280. if let data = self._currentItemView {
  281. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  282. } else {
  283. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolBatesItemIdentifier), index: sender.tag, info: nil)
  284. }
  285. self._itemSetPromptFlag(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  286. }
  287. @objc private func _AIAction(sender: NSMenuItem) {
  288. if let data = self._currentItemView {
  289. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  290. } else {
  291. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarAIItemIdentifier), index: sender.tag, info: nil)
  292. }
  293. self._itemSetPromptFlag(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  294. }
  295. @objc func headerfooterMenuAction(sender: KMToolbarClickButton) {
  296. self._currentItemView = sender.clickObject as? KMToolbarItemView
  297. if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
  298. subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
  299. }
  300. }
  301. @objc private func _headerfooterAction(sender: NSMenuItem) {
  302. if let data = self._currentItemView {
  303. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  304. } else {
  305. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolHeaderFooterItemIdentifier), index: sender.tag, info: nil)
  306. }
  307. self._itemSetPromptFlag(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  308. }
  309. @objc func backgroundMenuAction(sender: KMToolbarClickButton) {
  310. self._currentItemView = sender.clickObject as? KMToolbarItemView
  311. if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
  312. subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
  313. }
  314. }
  315. @objc private func _backgroundAction(sender: NSMenuItem) {
  316. if let data = self._currentItemView {
  317. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  318. } else {
  319. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolBackgroundItemIdentifier), index: sender.tag, info: nil)
  320. }
  321. self._itemSetPromptFlag(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  322. }
  323. @objc func watermarkMenuAction(sender: KMToolbarClickButton) {
  324. self._currentItemView = sender.clickObject as? KMToolbarItemView
  325. if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
  326. subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
  327. }
  328. }
  329. @objc private func _watermarkAction(sender: NSMenuItem) {
  330. if let data = self._currentItemView {
  331. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  332. } else {
  333. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolWatermarkItemIdentifier), index: sender.tag, info: nil)
  334. }
  335. self._itemSetPromptFlag(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  336. }
  337. @objc func redactMenuAction(sender: KMToolbarClickButton) {
  338. self.delegate?.toolbarViewController?(self, clickChaildToolType: .redact, toolbar: sender.clickObject as! KMToolbarItemView)
  339. self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
  340. }
  341. @objc func compressMenuAction(sender: KMToolbarClickButton) {
  342. self.delegate?.toolbarViewController?(self, clickChaildToolType: .compress, toolbar: sender.clickObject as! KMToolbarItemView)
  343. self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
  344. }
  345. @objc func secureMenuAction(sender: KMToolbarClickButton) {
  346. self.delegate?.toolbarViewController?(self, clickChaildToolType: .secure, toolbar: sender.clickObject as! KMToolbarItemView)
  347. self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
  348. }
  349. @objc private func _secureAction(sender: NSMenuItem) {
  350. if let data = self._currentItemView {
  351. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  352. } else {
  353. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolSecureItemIdentifier), index: sender.tag, info: nil)
  354. }
  355. self._itemSetPromptFlag(itemIdentifier: KMToolbarToolSecureItemIdentifier)
  356. }
  357. @objc func conversionMenuItemAction(sender: KMToolbarClickButton) {
  358. if let item: KMToolbarItemView = sender.clickObject as? KMToolbarItemView {
  359. var type: KMToolbarType = .word
  360. if (item.btnTag == KMToolbarType.excel.rawValue) {
  361. type = .excel
  362. } else if (item.btnTag == KMToolbarType.ppt.rawValue) {
  363. type = .ppt
  364. } else if (item.btnTag == KMToolbarType.rtf.rawValue) {
  365. type = .rtf
  366. } else if (item.btnTag == KMToolbarType.csv.rawValue) {
  367. type = .csv
  368. } else if (item.btnTag == KMToolbarType.html.rawValue) {
  369. type = .html
  370. } else if (item.btnTag == KMToolbarType.conversion_text.rawValue) {
  371. type = .conversion_text
  372. } else if (item.btnTag == KMToolbarType.conversion_image.rawValue) {
  373. type = .conversion_image
  374. }
  375. self.delegate?.toolbarViewController?(self, clickChaildToolType: type, toolbar: item)
  376. self._itemSetPromptFlag(item: item)
  377. }
  378. }
  379. @objc private func _pdfToImageAction(sender: NSMenuItem) {
  380. if let data = self._currentItemView {
  381. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  382. } else {
  383. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarConversionImageItemIdentifier), index: sender.tag, info: nil)
  384. }
  385. self._itemSetPromptFlag(itemIdentifier: KMToolbarConversionImageItemIdentifier)
  386. }
  387. @objc private func _exportImageAction(sender: NSMenuItem) {
  388. if let data = self._currentItemView {
  389. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  390. } else {
  391. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarConversionExportImageItemIdentifier), index: sender.tag, info: nil)
  392. }
  393. self._itemSetPromptFlag(itemIdentifier: KMToolbarConversionExportImageItemIdentifier)
  394. }
  395. @objc private func _newPDFAction(sender: NSMenuItem) {
  396. if let data = self._currentItemView {
  397. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  398. } else {
  399. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarConversionCreatePDFItemIdentifier), index: sender.tag, info: nil)
  400. }
  401. self._itemSetPromptFlag(itemIdentifier: KMToolbarConversionCreatePDFItemIdentifier)
  402. }
  403. @IBAction func zoomModelSelectButtonAction(_ sender: NSPopUpButton) {
  404. self.delegate?.toolbarViewController?(self, zoomModel: sender.selectedTag())
  405. for item in sender.itemArray {
  406. item.state = .off
  407. }
  408. sender.selectedItem?.state = .on
  409. }
  410. @IBAction func zoomPDFViewButtonAction(sender:KMToolbarClickButton) {
  411. if sender.tag == 0 {
  412. self.delegate?.changePDFViewZoomOutAction?()
  413. } else if sender.tag == 1 {
  414. self.delegate?.changePDFViewZoomInAction?()
  415. } else if sender.tag == 2 {
  416. self.delegate?.changePDFViewGotoBackAction?()
  417. } else if sender.tag == 3 {
  418. self.delegate?.changePDFViewGoToForwardAction?()
  419. }
  420. }
  421. @IBAction func aiTranslationButtonAction(sender:KMToolbarClickButton) {
  422. self.delegate?.aiTranslationPDFFileAction?()
  423. }
  424. @IBAction func shareButtonAction(sender:KMToolbarClickButton) {
  425. self.shareButton = sender
  426. let menu = NSMenu()
  427. menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
  428. menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
  429. menu.addItem(withTitle: NSLocalizedString("Original PDF", comment: ""), action: #selector(shareViaWithOriginalPDF), target: self)
  430. menu.popUp(positioning: nil, at: NSPoint(x: sender.frame.origin.x, y: sender.frame.origin.y-10), in: sender.superview)
  431. self.delegate?.toolbarViewController?(self, shareAction: sender.clickObject as! KMToolbarItemView)
  432. }
  433. @IBAction func shareViaWithDocument(sender:NSMenuItem) {
  434. self.delegate?.toolbarViewController?(self, shareDocument: sender)
  435. }
  436. @IBAction func shareViaWithFlatten(sender:NSMenuItem) {
  437. self.delegate?.toolbarViewController?(self, shareFlatten: sender)
  438. }
  439. @IBAction func shareViaWithOriginalPDF(sender:NSMenuItem) {
  440. self.delegate?.toolbarViewController?(self, shareOriginalPDF: sender)
  441. }
  442. @objc func mergeMenuItemAction(sender: KMToolbarClickButton) {
  443. self.delegate?.toolbarViewController?(self, clickChaildToolType: .merge, toolbar: sender.clickObject as! KMToolbarItemView)
  444. }
  445. @IBAction func scanOCRModelSelect(sender:KMToolbarClickButton) {
  446. self.delegate?.toolbarViewController?(self, scanOCRModel: sender.tag)
  447. }
  448. // Form 对齐
  449. @IBAction func formsAlignmentAction(sender:KMToolbarClickButton) {
  450. if sender.tag == 0 {
  451. self.pdfView.formsAnnotationAlign(.left)
  452. } else if sender.tag == 1 {
  453. self.pdfView.formsAnnotationAlign(.vertical)
  454. } else if sender.tag == 2 {
  455. self.pdfView.formsAnnotationAlign(.right)
  456. } else if sender.tag == 3 {
  457. self.pdfView.formsAnnotationAlign(.top)
  458. } else if sender.tag == 4 {
  459. self.pdfView.formsAnnotationAlign(.horizontally)
  460. } else if sender.tag == 5 {
  461. self.pdfView.formsAnnotationAlign(.bottom)
  462. } else if sender.tag == 6 {
  463. self.pdfView.formsAnnotationAlign(.disHorizontally)
  464. } else if sender.tag == 7 {
  465. self.pdfView.formsAnnotationAlign(.disVertical)
  466. }
  467. }
  468. @objc private func _alignmentAction(sender: NSMenuItem) {
  469. if let data = self._currentItemView {
  470. self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
  471. } else {
  472. self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolFormAlignIdentifier), index: sender.tag, info: nil)
  473. }
  474. }
  475. // Form 更多操作
  476. @IBAction func formsMoreOperationAction(sender:KMToolbarClickButton) {
  477. }
  478. func toolbarItemFindItemIdentifiers(value : String) -> KMToolbarItemView{
  479. for item in self.toolbarItems {
  480. if item.key == value {
  481. return item.value as! KMToolbarItemView
  482. }
  483. }
  484. return KMToolbarItemView()
  485. }
  486. func controlTextDidEndEditing(_ obj: Notification) {
  487. let textField = obj.object as? NSTextField
  488. if textField == self.zoomTextField {
  489. self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
  490. }
  491. }
  492. func controlTextDidChange(_ obj: Notification) {
  493. }
  494. func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
  495. switch commandSelector {
  496. case #selector(NSResponder.insertNewline(_:)):
  497. if let inputView = control as? NSTextField {
  498. // //当当前TextField按下enter
  499. if inputView == zoomTextField {
  500. KMPrint("按下 enter")
  501. self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
  502. } else if let _ = control as? NSSearchField {
  503. self.searchPDFKey(control.stringValue)
  504. }
  505. }
  506. return true
  507. default:
  508. return false
  509. }
  510. }
  511. // MARK: - Private Methods
  512. private func _itemSetPromptFlag(item: KMToolbarItemView?) {
  513. if let item_ = item {
  514. if let identifier = item_.promptIdentifier {
  515. item?.isShowPrompt = false
  516. KMDataManager.ud_set(true, forKey: identifier)
  517. }
  518. }
  519. }
  520. private func _itemSetPromptFlag(itemIdentifier: String?) {
  521. let item = self.toolbarItemFindItemIdentifiers(value: itemIdentifier ?? "")
  522. self._itemSetPromptFlag(item: item)
  523. }
  524. override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
  525. super.interfaceThemeDidChanged(appearance)
  526. self.toolbar?.appearance = .init(named: appearance)
  527. self.bottomLine.wantsLayer = true
  528. if KMAppearance.isDarkMode() {
  529. self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#393B3E", alpha: 1).cgColor
  530. } else {
  531. self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#0000001A").cgColor
  532. }
  533. }
  534. }
  535. // MARK: - Public Methods
  536. extension KMToolbarViewController {
  537. func itemAction(_ item: KMToolbarItemView) {
  538. self._itemAction(item.clickButton)
  539. }
  540. }
  541. extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidation {
  542. func toolbarLeftDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  543. if toolbarType == .Main {
  544. if let model = KMDataManager.toolbar_getData() {
  545. return model.leftCellIdentifiers ?? []
  546. }
  547. return [KMLeftControlToolbarItemIdentifier,
  548. KMNewToolbarSpaceItemIdentifier, KMDocumentZoomViewToolbarItemIdentifier,
  549. KMDocumentPreviousPageToolbarItemIdentifier, KMDocumentHomeToolbarItemIdentifier]
  550. }
  551. return []
  552. }
  553. func toolbarRightDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  554. if toolbarType == .Main {
  555. if let model = KMDataManager.toolbar_getData() {
  556. return model.rightCellIdentifiers ?? []
  557. }
  558. return [KMDocumentViewDisplayToolbarItemIdentifier, KMDocumentShareToolbarItemIdentifier,
  559. KMDocumentSearchToolbarItemIdentifier, KMRightControlToolbarItemIdentifier]
  560. } else if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
  561. return [KMToolbarAnnotationSettingItemIdentifier]
  562. }
  563. return []
  564. }
  565. func toolbarAllowedItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  566. if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
  567. return [KMNewToolbarSpaceItemIdentifier,
  568. KMToolbarPageEditInsetItemIdentifier, KMToolbarToolMergeItemIdentifier, KMToolbarPageEditSplitItemIdentifier,
  569. KMToolbarToolCompressItemIdentifier, KMToolbarToolSecureItemIdentifier, KMToolbarToolWatermarkItemIdentifier,
  570. KMToolbarToolBackgroundItemIdentifier, KMToolbarToolHeaderFooterItemIdentifier, KMToolbarToolBatesItemIdentifier,
  571. KMToolbarAIItemIdentifier,
  572. KMToolbarCropIdentifier,
  573. KMToolbarConversionWordItemIdentifier, KMToolbarConversionExcelItemIdentifier, KMToolbarConversionPPTItemIdentifier,
  574. KMToolbarConversionRTFItemIdentifier, KMToolbarConversionCSVItemIdentifier, KMToolbarConversionHTMLItemIdentifier,
  575. KMToolbarConversionTextItemIdentifier, KMToolbarConversionImageItemIdentifier,
  576. KMToolbarMoveToolModeItemIdentifier,
  577. KMToolbarMagnifyToolModeItemIdentifier,
  578. KMToolbarSelectToolModeItemIdentifier,
  579. KMToolbarZoomToSelectionItemIdentifier,
  580. KMNewToolbarSpaceItemIdentifier,
  581. KMToolbarDividerItemIdentifier,
  582. KMNewToolbarSpaceItemIdentifier,
  583. KMToolbarHighlightAnnotationItemIdentifier,
  584. KMToolbarUnderlineAnnotationItemIdentifier,
  585. KMToolbarStrikeOutAnnotationItemIdentifier,
  586. KMToolbarInkAnnotationItemIdentifier,
  587. KMToolbarFreeTextAnnotationItemIdentifier,
  588. KMToolbarAnchoredAnnotationItemIdentifier,
  589. KMToolbarSquareAnnotationItemIdentifier, KMToolbarCircleAnnotationItemIdentifier, KMToolbarArrowAnnotationItemIdentifier, KMToolbarLineAnnotationItemIdentifier,
  590. KMToolbarLinkAnnotationItemIdentifier,
  591. KMAnnotationStampToolbarItemIdentifier,
  592. KMToolbarSignSignatureAnnotationItemIdentifier,
  593. // KMToolbarDividerItemIdentifier,
  594. // KMToolbarShowToolbarItemIdentifier,
  595. KMToolbarToolRadioButtonItemIdentifier]
  596. }
  597. return []
  598. }
  599. func toolbarDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
  600. switch toolbarType {
  601. case .None:
  602. return []
  603. case .Main:
  604. if let model = KMDataManager.toolbar_getData() {
  605. return model.centerCellIdentifiers ?? []
  606. }
  607. return [KMDocumentAnnotationToolbarItemIdentifier,
  608. KMDocumentPageToolbarItemIdentifier,
  609. KMDocumentToolToolbarItemIdentifier,
  610. KMDocumentConversonToolbarItemIdentifier,
  611. KMDocumentFormToolbarItemIdentifier,
  612. KMDocumentFillSginToolbarItemIdentifier,
  613. KMDocumentEditToolbarItemIdentifier,
  614. KMDocumentDigitalSignToolbarItemIdentifier,
  615. KMDocumentRedactToolbarItemIdentifier,
  616. KMDocumentScanOCRToolbarItemIdentifier,
  617. KMDocumentAIToolsToolbarItemIdentifier]
  618. case .Annatiton,.Magnify,.Move,.Select,.SelectZoom:
  619. let itemIdentifiers: [String]? = self.toolbar?.toolbarIdentifier != nil ? (UserDefaults.standard.object(forKey: self.toolbar?.toolbarIdentifier ?? "") as? [String]) : []
  620. if itemIdentifiers == nil || itemIdentifiers!.count <= 0 {
  621. return [KMToolbarMoveToolModeItemIdentifier,
  622. KMToolbarMagnifyToolModeItemIdentifier,
  623. KMToolbarSelectToolModeItemIdentifier,
  624. KMToolbarZoomToSelectionItemIdentifier,
  625. KMNewToolbarSpaceItemIdentifier,
  626. KMNewToolbarSpaceItemIdentifier,
  627. KMToolbarHighlightAnnotationItemIdentifier,
  628. KMToolbarUnderlineAnnotationItemIdentifier,
  629. KMToolbarStrikeOutAnnotationItemIdentifier,
  630. KMToolbarInkAnnotationItemIdentifier,
  631. KMToolbarFreeTextAnnotationItemIdentifier,
  632. KMToolbarAnchoredAnnotationItemIdentifier,
  633. KMToolbarSquareAnnotationItemIdentifier, KMToolbarCircleAnnotationItemIdentifier, KMToolbarArrowAnnotationItemIdentifier, KMToolbarLineAnnotationItemIdentifier,
  634. KMToolbarLinkAnnotationItemIdentifier,
  635. KMNewToolbarSpaceItemIdentifier, KMNewToolbarSpaceItemIdentifier,
  636. KMAnnotationStampToolbarItemIdentifier, KMAnnotationImageToolbarItemIdentifier,
  637. KMToolbarSignSignatureAnnotationItemIdentifier, KMAnnotationTableToolbarItemIdentifier]
  638. }
  639. return itemIdentifiers!
  640. case .editPDF:
  641. return [KMToolbarAddTextEditPDFItemIdentifier,
  642. KMToolbarAddImageEditPDFItemIdentifier]
  643. case .Page:
  644. return []
  645. case .Tool:
  646. return [KMToolbarToolCompressItemIdentifier, KMToolbarToolMergeItemIdentifier,
  647. KMToolbarToolSecureItemIdentifier, KMToolbarComparisonItemIdentifier,
  648. KMToolbarToolWatermarkItemIdentifier, KMToolbarToolBackgroundItemIdentifier,
  649. KMToolbarToolHeaderFooterItemIdentifier, KMToolbarToolBatesItemIdentifier]
  650. case .Form:
  651. return [KMToolbarToolTextFieldItemIdentifier,
  652. KMToolbarToolCheckBoxItemIdentifier,
  653. KMToolbarToolRadioButtonItemIdentifier,
  654. KMToolbarToolListBoxItemIdentifier,
  655. KMToolbarToolPullDownmenuItemIdentifier,
  656. KMToolbarToolButtonIdentifier,
  657. KMToolbarToolSignBoxIdentifier,
  658. KMToolbarDividerItemIdentifier,
  659. KMToolbarToolFormAlignIdentifier]
  660. case .FillSign:
  661. return [
  662. // KMToolbarToolTextIdentifier,
  663. KMToolbarToolHookItemIdentifier,
  664. KMToolbarToolForkItemIdentifier,
  665. KMToolbarToolRectangleIdentifier,
  666. KMToolbarToolLineItemIdentifier,
  667. KMToolbarToolDotItemIdentifier,
  668. KMToolbarToolDateIdentifier,
  669. KMToolbarToolProfileIdentifier,
  670. KMToolbarFillSignSignatureIdentifier]
  671. case .Conversion:
  672. return [KMToolbarConversionCreatePDFItemIdentifier,
  673. KMToolbarConversionWordItemIdentifier,
  674. KMToolbarConversionExcelItemIdentifier,
  675. KMToolbarConversionPPTItemIdentifier,
  676. KMToolbarConversionRTFItemIdentifier,
  677. KMToolbarConversionCSVItemIdentifier,
  678. KMToolbarConversionHTMLItemIdentifier,
  679. KMToolbarConversionTextItemIdentifier,
  680. KMToolbarConversionImageItemIdentifier,
  681. KMToolbarDividerItemIdentifier, KMToolbarConversionOCRIdentifier, KMToolbarConversionExportImageItemIdentifier]
  682. case .ScanOCR:
  683. return [KMToolbarToolEnhancedScanIdentifier,
  684. KMToolbarToolOCRTextIdentifier]
  685. case .viewSetting:
  686. return [KMToolbarViewSettingIdentifier, KMToolbarCropIdentifier,
  687. KMToolbarSnapshotIdentifier, KMToolbarTTSIdentifier]
  688. default:
  689. break
  690. }
  691. return []
  692. }
  693. func toolbar(_ toolbar: KMToolbarView, itemFor identifier: String) -> KMToolbarItemView {
  694. var item: KMToolbarItemView? = self.toolbarItems[identifier] as? KMToolbarItemView
  695. var create = false
  696. if let data = item {
  697. let pId = parentIdentifier(data.itemIdentifier ?? "")
  698. if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) && (pId != KMDocumentAnnotationToolbarItemIdentifier || data.itemIdentifier! == KMToolbarAnnotationSettingItemIdentifier) {
  699. create = true
  700. } else {
  701. if let toolbarId = self.toolbar?.toolbarIdentifier {
  702. let itemIdentifiers = (UserDefaults.standard.object(forKey: toolbarId) as? [String]) ?? []
  703. if itemIdentifiers.contains(identifier) && annotationToolIdentifiers.contains(identifier) == false {
  704. create = true
  705. }
  706. }
  707. }
  708. }
  709. if create == false {
  710. if KMDataManager.default.toolbarConfigDataUpdated {
  711. create = true
  712. }
  713. }
  714. if item == nil || create {
  715. item = KMToolbarItemView.init(itemIdentifier: identifier)
  716. if isMainToolItem(identifier) {
  717. item = KMToolbarMainItemView(itemIdentifier: identifier)
  718. }
  719. self.toolbarItems[identifier] = item
  720. if isMainToolItem(identifier) {
  721. self._setupMainItem(item)
  722. } else {
  723. if (annotationToolIdentifiers.contains(identifier)) {
  724. self._setupAnnotationItem(item)
  725. } else if editPDFItemIdentifiers.contains(identifier) {
  726. self._setupEditItem(item)
  727. } else if conversionToolIdentifiers.contains(identifier) {
  728. self._setupConvertItem(item)
  729. } else if fillSignToolIdentifiers.contains(identifier) {
  730. self._setupFillSignItem(item)
  731. } else if formToolIdentifiers.contains(identifier) {
  732. self._setupFormItem(item)
  733. } else if toolToolIdentifiers.contains(identifier) {
  734. self._setupToolItem(item)
  735. } else if KMViewDisplayIdentifiers.contains(identifier) {
  736. self._setupViewDisplayItem(item)
  737. } else if pageEditToolIdentifiers.contains(identifier) {
  738. if (identifier == KMToolbarPageEditPageRangeItemIdentifier) {
  739. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageRange)
  740. item?.target = self
  741. item?.btnTag = KMPageEditType.pageRange.rawValue
  742. // item?.toolTip = NSLocalizedString("pageRange", comment: "")
  743. item?.titleName = NSLocalizedString("Page Range", comment: "")
  744. item?.boxImagePosition = .imageExpandLeft
  745. // item?.btnAction = #selector(pageRangeMenuAction)
  746. item?.needExpandAction = true
  747. } else if (identifier == KMToolbarPageEditRotateItemIdentifier) {
  748. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageRotate)
  749. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageRotate)
  750. item?.target = self
  751. item?.btnTag = KMPageEditType.rightRotate.rawValue
  752. item?.toolTip = NSLocalizedString("Rotate", comment: "")
  753. item?.titleName = NSLocalizedString("Rotate", comment: "")
  754. item?.boxImagePosition = .imageLeft
  755. } else if (identifier == KMToolbarPageEditLeftRotateItemIdentifier) {
  756. item?.image = NSImage(named: "KMImageNameMainToolPageLeftRotate")
  757. item?.alternateImage = NSImage(named: "KMImageNameMainToolPageLeftRotate")
  758. item?.target = self
  759. item?.btnTag = KMPageEditType.leftRotate.rawValue
  760. item?.toolTip = NSLocalizedString("Rotate Left", comment: "")
  761. item?.titleName = NSLocalizedString("", comment: "")
  762. item?.boxImagePosition = .imageLeft
  763. } else if (identifier == KMToolbarPageEditRightRotateItemIdentifier) {
  764. item?.image = NSImage(named: "KMImageNameMainToolPageRightRotate")
  765. item?.alternateImage = NSImage(named: "KMImageNameMainToolPageRightRotate")
  766. item?.target = self
  767. item?.btnTag = KMPageEditType.rightRotate.rawValue
  768. item?.toolTip = NSLocalizedString("Rotate Right", comment: "")
  769. item?.titleName = NSLocalizedString("", comment: "")
  770. item?.boxImagePosition = .imageLeft
  771. } else if (identifier == KMToolbarPageEditInsetItemIdentifier) {
  772. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageInsert)
  773. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageInsert)
  774. item?.target = self
  775. item?.btnTag = KMPageEditType.insert.rawValue
  776. item?.isShowCustomToolTip = true
  777. item?.toolTip = NSLocalizedString("Inserting pages into an existing PDF", comment: "")
  778. item?.isPopToolTip = true
  779. item?.titleName = NSLocalizedString("Insert", comment: "")
  780. item?.boxImagePosition = .imageOnly
  781. item?.btnAction = #selector(_itemAction)
  782. } else if (identifier == KMToolbarPageEditExtractItemIdentifier) {
  783. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageExtract)
  784. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageExtract)
  785. item?.target = self
  786. item?.btnTag = KMPageEditType.extract.rawValue
  787. // item?.toolTip = NSLocalizedString("Exctract selected pages", comment: "")
  788. item?.titleName = NSLocalizedString("Extract", comment: "")
  789. item?.boxImagePosition = .imageExpandLeft
  790. // item?.btnAction = #selector(extractMenuAction)
  791. item?.needExpandAction = true
  792. } else if (identifier == KMToolbarPageEditReplaceItemIdentifier) {
  793. item?.image = NSImage(named: KMImageNameToolbarReplace)
  794. item?.alternateImage = NSImage(named: KMImageNameToolbarReplace)
  795. item?.target = self
  796. item?.btnTag = KMPageEditType.replace.rawValue
  797. item?.toolTip = NSLocalizedString("Replace", comment: "")
  798. item?.titleName = NSLocalizedString("Replace", comment: "")
  799. item?.boxImagePosition = .imageLeft
  800. } else if (identifier == KMToolbarPageEditSplitItemIdentifier) {
  801. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageSplit)
  802. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageSplit)
  803. item?.target = self
  804. item?.btnTag = KMPageEditType.split.rawValue
  805. item?.isShowCustomToolTip = true
  806. item?.toolTip = NSLocalizedString("Split and save selected PDF pages as a new separate document", comment: "")
  807. item?.isPopToolTip = true
  808. item?.titleName = NSLocalizedString("Split", comment: "")
  809. item?.boxImagePosition = .imageOnly
  810. item?.btnAction = #selector(_itemAction)
  811. } else if (identifier == KMToolbarPageEditReverseItemIdentifier) {
  812. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageReverse)
  813. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageReverse)
  814. item?.target = self
  815. item?.btnTag = KMPageEditType.reverse.rawValue
  816. item?.toolTip = NSLocalizedString("Reverse", comment: "")
  817. item?.titleName = NSLocalizedString("Reverse", comment: "")
  818. item?.boxImagePosition = .imageLeft
  819. } else if (identifier == KMToolbarPageEditCopyItemIdentifier) {
  820. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageCopy)
  821. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageCopy)
  822. item?.target = self
  823. item?.btnTag = KMPageEditType.delete.rawValue
  824. item?.toolTip = NSLocalizedString("Copy", comment: "")
  825. item?.titleName = NSLocalizedString("Copy", comment: "")
  826. item?.boxImagePosition = .imageLeft
  827. } else if (identifier == KMToolbarPageEditPasteItemIdentifier) {
  828. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPagePaste)
  829. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPagePaste)
  830. item?.target = self
  831. item?.btnTag = KMPageEditType.delete.rawValue
  832. item?.toolTip = NSLocalizedString("Paste", comment: "")
  833. item?.titleName = NSLocalizedString("Paste", comment: "")
  834. item?.boxImagePosition = .imageLeft
  835. } else if (identifier == KMToolbarPageEditDeleteItemIdentifier) {
  836. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageDelete)
  837. item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageDelete)
  838. item?.target = self
  839. item?.btnTag = KMPageEditType.delete.rawValue
  840. item?.toolTip = NSLocalizedString("Delete", comment: "")
  841. item?.titleName = NSLocalizedString("Delete", comment: "")
  842. item?.boxImagePosition = .imageLeft
  843. }
  844. return item!
  845. }
  846. }
  847. }
  848. return item!
  849. }
  850. func validateToolbarItem(_ item: NSToolbarItem) -> Bool {
  851. return true
  852. }
  853. @objc func listViewAnnotationTypeChangeNotification(sender: Notification?) {
  854. // if let notiName = sender?.name, notiName == NSNotification.Name.CPDFListViewAnnotationTypeChange, self.ignoreCurrentAnnotationTypeChange {
  855. // }
  856. if (self.ignoreCurrentAnnotationTypeChange) {
  857. // 忽略后重置 这个属性是基于单次添加,所以使用后会重置
  858. // self.ignoreCurrentAnnotationTypeChange = false
  859. return
  860. }
  861. let annotationType : CAnnotationType = pdfView.annotationType
  862. if annotationType == .square || annotationType == .circle || annotationType == .arrow || annotationType == .line{
  863. UserDefaults.standard.set(pdfView.annotationType.rawValue, forKey: KMToolBarToolPDFShapeStyle)
  864. UserDefaults.standard.synchronize()
  865. }
  866. for item in self.toolbar?.items ?? [] {
  867. if self.toolbarType == .Annatiton || self.toolbarType == .Move || self.toolbarType == .Magnify ||
  868. self.toolbarType == .Select || self.toolbarType == .SelectZoom {
  869. item.isSelected = false
  870. if item.itemIdentifier == KMDocumentAnnotationToolbarItemIdentifier {
  871. item.isSelected = true
  872. } else if item.itemIdentifier == KMToolbarHighlightAnnotationItemIdentifier {
  873. if annotationType == .highlight {
  874. item.isSelected = true
  875. }
  876. } else if item.itemIdentifier == KMToolbarUnderlineAnnotationItemIdentifier {
  877. if annotationType == .underline {
  878. item.isSelected = true
  879. }
  880. } else if item.itemIdentifier == KMToolbarStrikeOutAnnotationItemIdentifier {
  881. if annotationType == .strikeOut {
  882. item.isSelected = true
  883. }
  884. } else if item.itemIdentifier == KMToolbarInkAnnotationItemIdentifier {
  885. if annotationType == .ink || annotationType == .eraser {
  886. item.isSelected = true
  887. }
  888. } else if item.itemIdentifier == KMToolbarFreeTextAnnotationItemIdentifier {
  889. if annotationType == .freeText {
  890. item.isSelected = true
  891. }
  892. } else if item.itemIdentifier == KMToolbarAnchoredAnnotationItemIdentifier {
  893. if annotationType == .anchored {
  894. item.isSelected = true
  895. }
  896. } else if item.itemIdentifier == KMToolbarSquareAnnotationItemIdentifier {
  897. if annotationType == .square {
  898. item.isSelected = true
  899. }
  900. } else if item.itemIdentifier == KMToolbarCircleAnnotationItemIdentifier {
  901. if annotationType == .circle {
  902. item.isSelected = true
  903. }
  904. } else if item.itemIdentifier == KMToolbarArrowAnnotationItemIdentifier {
  905. if annotationType == .arrow {
  906. item.isSelected = true
  907. }
  908. } else if item.itemIdentifier == KMToolbarLineAnnotationItemIdentifier {
  909. if annotationType == .line {
  910. item.isSelected = true
  911. }
  912. } else if item.itemIdentifier == KMToolbarLinkAnnotationItemIdentifier {
  913. if annotationType == .link {
  914. item.isSelected = true
  915. }
  916. } else if item.itemIdentifier == KMAnnotationStampToolbarItemIdentifier {
  917. if annotationType == .stamp {
  918. item.isSelected = true
  919. }
  920. } else if item.itemIdentifier == KMToolbarSignSignatureAnnotationItemIdentifier {
  921. if annotationType == .signSignature {
  922. item.isSelected = true
  923. }
  924. } else if pdfView.toolMode == .moveToolMode {
  925. if item.itemIdentifier == KMToolbarMoveToolModeItemIdentifier {
  926. item.isSelected = true
  927. }
  928. } else if pdfView.toolMode == .magnifyToolMode {
  929. if item.itemIdentifier == KMToolbarMagnifyToolModeItemIdentifier {
  930. item.isSelected = true
  931. }
  932. } else if pdfView.toolMode == .selectToolMode {
  933. if item.itemIdentifier == KMToolbarSelectToolModeItemIdentifier {
  934. item.isSelected = true
  935. }
  936. } else if pdfView.toolMode == .selectZoomToolMode {
  937. if item.itemIdentifier == KMToolbarZoomToSelectionItemIdentifier {
  938. item.isSelected = true
  939. }
  940. }
  941. if (item.itemIdentifier == KMToolbarShowToolbarItemIdentifier) {
  942. item.isSelected = !self.isShowAllAnnotations
  943. }
  944. } else if self.toolbarType == .FillSign {
  945. item.isSelected = false
  946. if pdfView.toolMode == .selfSignMode {
  947. if item.itemIdentifier == KMToolbarToolHookItemIdentifier {
  948. if annotationType == .signTure {
  949. item.isSelected = true
  950. }
  951. } else if item.itemIdentifier == KMToolbarToolForkItemIdentifier {
  952. if annotationType == .signFalse {
  953. item.isSelected = true
  954. }
  955. } else if item.itemIdentifier == KMToolbarToolLineItemIdentifier {
  956. if annotationType == .signLine {
  957. item.isSelected = true
  958. }
  959. } else if item.itemIdentifier == KMToolbarToolDotItemIdentifier {
  960. if annotationType == .signDot {
  961. item.isSelected = true
  962. }
  963. } else if item.itemIdentifier == KMToolbarToolRectangleIdentifier {
  964. if annotationType == .signCircle {
  965. item.isSelected = true
  966. }
  967. } else if item.itemIdentifier == KMToolbarToolDateIdentifier {
  968. if annotationType == .signDate {
  969. item.isSelected = true
  970. }
  971. } else if item.itemIdentifier == KMToolbarToolTextIdentifier {
  972. if annotationType == .signText {
  973. item.isSelected = true
  974. }
  975. } else if (item.itemIdentifier == KMToolbarFillSignSignatureIdentifier) {
  976. if (annotationType == .signSignature) {
  977. item.isSelected = true
  978. }
  979. }
  980. }
  981. } else if self.toolbarType == .Form {
  982. item.isSelected = false
  983. if pdfView.toolMode == .formToolMode {
  984. if item.itemIdentifier == KMToolbarToolTextFieldItemIdentifier {
  985. if annotationType == .textField {
  986. item.isSelected = true
  987. }
  988. } else if item.itemIdentifier == KMToolbarToolCheckBoxItemIdentifier {
  989. if annotationType == .checkBox {
  990. item.isSelected = true
  991. }
  992. } else if item.itemIdentifier == KMToolbarToolRadioButtonItemIdentifier {
  993. if annotationType == .radioButton {
  994. item.isSelected = true
  995. }
  996. } else if item.itemIdentifier == KMToolbarToolListBoxItemIdentifier {
  997. if annotationType == .listMenu {
  998. item.isSelected = true
  999. }
  1000. } else if item.itemIdentifier == KMToolbarToolPullDownmenuItemIdentifier {
  1001. if annotationType == .comboBox {
  1002. item.isSelected = true
  1003. }
  1004. } else if item.itemIdentifier == KMToolbarToolButtonIdentifier {
  1005. if annotationType == .actionButton {
  1006. item.isSelected = true
  1007. }
  1008. } else if item.itemIdentifier == KMToolbarToolSignBoxIdentifier {
  1009. if annotationType == .signature {
  1010. item.isSelected = true
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. extension KMToolbarViewController: NSSearchFieldDelegate {
  1019. }
  1020. extension KMToolbarViewController {
  1021. private func _setupMainItem(_ item: KMToolbarItemView?) {
  1022. let identifier = item?.itemIdentifier
  1023. if identifier == KMLeftControlToolbarItemIdentifier {
  1024. item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
  1025. item?.titleName = NSLocalizedString("Panel", comment: "")
  1026. item?.target = self
  1027. item?.toolTip = NSLocalizedString("View Settings", comment: "")
  1028. item?.boxImagePosition = .imageAbove
  1029. item?.selectBackgroundType = .imageBox
  1030. item?.btnAction = #selector(_itemAction)
  1031. } else if identifier == KMDocumentZoomToolbarItemIdentifier {
  1032. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
  1033. item?.titleName = NSLocalizedString("", comment: "")
  1034. item?.target = self
  1035. item?.btnTag = 1
  1036. item?.toolTip = NSLocalizedString("Zoom In", comment: "")
  1037. item?.boxImagePosition = .imageAbove
  1038. item?.btnAction = #selector(zoomPDFViewButtonAction)
  1039. } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
  1040. item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
  1041. item?.titleName = NSLocalizedString("", comment: "")
  1042. item?.target = self
  1043. item?.btnTag = 0
  1044. item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
  1045. item?.boxImagePosition = .imageAbove
  1046. item?.btnAction = #selector(zoomPDFViewButtonAction)
  1047. } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
  1048. item?.titleName = NSLocalizedString("Zoom", comment: "")
  1049. item?.target = self
  1050. let view = KMToolbarZoomItemView(zoomView: self.zoomView)
  1051. view.callback = { [weak self] idx, _ in
  1052. if idx == 2 {
  1053. self?.delegate?.changePDFViewZoomInAction?()
  1054. } else if idx == 1 {
  1055. self?.delegate?.changePDFViewZoomOutAction?()
  1056. }
  1057. }
  1058. item?.customizeView = view
  1059. } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
  1060. item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
  1061. item?.titleName = NSLocalizedString("Next", comment: "")
  1062. item?.target = self
  1063. item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
  1064. item?.boxImagePosition = .imageAbove
  1065. item?.btnAction = #selector(_itemAction)
  1066. } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
  1067. item?.titleName = NSLocalizedString("Zoom", comment: "")
  1068. item?.target = self
  1069. let view = KMToolbarPreviousNextItemView()
  1070. view.callback = { [weak self] idx, _ in
  1071. if idx == 1 {
  1072. self?.delegate?.changePDFViewGoToPreviousPageAction?()
  1073. } else if idx == 2 {
  1074. self?.delegate?.changePDFViewGotoNextPageAction?()
  1075. }
  1076. }
  1077. item?.customizeView = view
  1078. } else if identifier == KMDocumentHomeToolbarItemIdentifier {
  1079. item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
  1080. item?.titleName = NSLocalizedString("Home", comment: "")
  1081. item?.target = self
  1082. item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
  1083. item?.boxImagePosition = .imageAbove
  1084. item?.selectBackgroundType = .imageBox
  1085. item?.btnAction = #selector(_itemAction)
  1086. } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
  1087. item?.titleName = NSLocalizedString("Tools", comment: "")
  1088. item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
  1089. item?.target = self
  1090. item?.toolTip = String(format: "%@: %@, %@, %@, %@", KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
  1091. item?.btnTag = KMToolbarViewType.Annatiton.rawValue
  1092. item?.btnAction = #selector(leftControllButtonAction)
  1093. item?.boxImagePosition = .imageAbove
  1094. item?.selectBackgroundType = .imageBox
  1095. } else if identifier == KMDocumentPageToolbarItemIdentifier {
  1096. item?.titleName = NSLocalizedString("Page Edit", comment: "")
  1097. item?.target = self
  1098. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
  1099. item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
  1100. item?.btnTag = KMToolbarViewType.Page.rawValue
  1101. item?.btnAction = #selector(leftControllButtonAction)
  1102. item?.boxImagePosition = .imageAbove
  1103. item?.selectBackgroundType = .imageBox
  1104. } else if identifier == KMDocumentConversonToolbarItemIdentifier {
  1105. item?.titleName = NSLocalizedString("Converter", comment: "")
  1106. item?.target = self
  1107. item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
  1108. item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
  1109. item?.btnTag = KMToolbarViewType.Conversion.rawValue
  1110. item?.btnAction = #selector(leftControllButtonAction)
  1111. item?.boxImagePosition = .imageAbove
  1112. item?.selectBackgroundType = .imageBox
  1113. item?.promptIdentifier = identifier
  1114. } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
  1115. item?.titleName = NSLocalizedString("OCR", comment: "")
  1116. item?.target = self
  1117. item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
  1118. item?.boxImagePosition = .imageAbove
  1119. item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
  1120. item?.selectBackgroundType = .imageBox
  1121. item?.btnAction = #selector(OCRbtnAction1)
  1122. item?.promptIdentifier = identifier
  1123. let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
  1124. menuItem.representedObject = identifier
  1125. item?.menuFormRepresentation = menuItem
  1126. } else if identifier == KMToolbarToolEnhancedScanIdentifier {
  1127. item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
  1128. item?.target = self
  1129. item?.btnTag = 0
  1130. item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
  1131. item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
  1132. item?.boxImagePosition = .imageLeft
  1133. item?.selectBackgroundType = .imageBox
  1134. item?.btnAction = #selector(scanOCRModelSelect)
  1135. } else if identifier == KMToolbarToolOCRTextIdentifier {
  1136. item?.image = NSImage(named: "KMImageNameMainToolOCRText")
  1137. item?.target = self
  1138. item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
  1139. item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
  1140. item?.boxImagePosition = .imageLeft
  1141. item?.selectBackgroundType = .imageBox
  1142. item?.btnAction = #selector(scanOCRModelSelect)
  1143. item?.promptIdentifier = identifier
  1144. let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR Text Recognition", comment: ""), action: #selector(scanOCRModelSelect), target: self)
  1145. menuItem.representedObject = identifier
  1146. item?.menuFormRepresentation = menuItem
  1147. } else if identifier == KMDocumentEditToolbarItemIdentifier {
  1148. item?.titleName = NSLocalizedString("Edit PDF", comment: "")
  1149. item?.target = self
  1150. item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
  1151. item?.boxImagePosition = .imageAbove
  1152. item?.btnTag = KMToolbarViewType.editPDF.rawValue
  1153. item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
  1154. item?.selectBackgroundType = .imageBox
  1155. item?.btnAction = #selector(leftControllButtonAction)
  1156. item?.promptIdentifier = identifier
  1157. let menuItem = NSMenuItem.init(title: NSLocalizedString("Edit PDF", comment: ""), action: #selector(_menuItemAction), target: self)
  1158. menuItem.tag = item!.btnTag
  1159. menuItem.representedObject = identifier
  1160. item?.menuFormRepresentation = menuItem
  1161. } else if identifier == KMDocumentFormToolbarItemIdentifier {
  1162. item?.titleName = NSLocalizedString("Forms", comment: "")
  1163. item?.target = self
  1164. item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
  1165. item?.boxImagePosition = .imageAbove
  1166. item?.btnTag = KMToolbarViewType.Form.rawValue
  1167. item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
  1168. item?.selectBackgroundType = .imageBox
  1169. item?.btnAction = #selector(leftControllButtonAction)
  1170. item?.promptIdentifier = identifier
  1171. let menuItem = NSMenuItem.init(title: NSLocalizedString("Forms", comment: ""), action: #selector(_menuItemAction), target: self)
  1172. menuItem.tag = item!.btnTag
  1173. menuItem.representedObject = identifier
  1174. item?.menuFormRepresentation = menuItem
  1175. } else if identifier == KMDocumentFillSginToolbarItemIdentifier {
  1176. item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
  1177. item?.target = self
  1178. item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
  1179. item?.boxImagePosition = .imageAbove
  1180. item?.btnTag = KMToolbarViewType.FillSign.rawValue
  1181. item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
  1182. item?.selectBackgroundType = .imageBox
  1183. item?.btnAction = #selector(leftControllButtonAction)
  1184. item?.promptIdentifier = identifier
  1185. let menuItem = NSMenuItem.init(title: NSLocalizedString("Fill & Sign", comment: ""), action: #selector(_menuItemAction), target: self)
  1186. menuItem.tag = item!.btnTag
  1187. menuItem.representedObject = identifier
  1188. item?.menuFormRepresentation = menuItem
  1189. } else if identifier == KMDocumentToolToolbarItemIdentifier {
  1190. item?.titleName = NSLocalizedString("Editor", comment: "")
  1191. item?.target = self
  1192. item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
  1193. item?.boxImagePosition = .imageAbove
  1194. item?.btnTag = KMToolbarViewType.Tool.rawValue
  1195. item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
  1196. item?.selectBackgroundType = .imageBox
  1197. item?.btnAction = #selector(leftControllButtonAction)
  1198. item?.promptIdentifier = identifier
  1199. } else if identifier == KMDocumentRedactToolbarItemIdentifier {
  1200. item?.titleName = NSLocalizedString("Redact Text", comment: "")
  1201. item?.target = self
  1202. item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
  1203. item?.boxImagePosition = .imageAbove
  1204. item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
  1205. item?.selectBackgroundType = .imageBox
  1206. item?.btnAction = #selector(_itemAction)
  1207. item?.promptIdentifier = identifier
  1208. } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
  1209. item?.image = NSImage(named: "ic_function_other_AITranslation")
  1210. item?.titleName = "AI Translation"
  1211. item?.target = self
  1212. item?.toolTip = NSLocalizedString("AI Translation", comment: "")
  1213. item?.boxImagePosition = .imageOnly
  1214. item?.btnAction = #selector(aiTranslationButtonAction)
  1215. item?.promptIdentifier = identifier
  1216. } else if identifier == KMDocumentPrintToolbarItemIdentifier {
  1217. item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
  1218. item?.titleName = "Print"
  1219. item?.target = self
  1220. item?.toolTip = NSLocalizedString("Print", comment: "")
  1221. item?.boxImagePosition = .imageOnly
  1222. item?.btnAction = #selector(_itemAction)
  1223. } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
  1224. item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
  1225. item?.titleName = NSLocalizedString("Page Display", comment: "")
  1226. item?.target = self
  1227. item?.toolTip = NSLocalizedString("Page Display", comment: "")
  1228. item?.boxImagePosition = .imageAbove
  1229. item?.selectBackgroundType = .imageBox
  1230. item?.btnAction = #selector(_itemAction)
  1231. item?.promptIdentifier = identifier
  1232. let menuItem = NSMenuItem.init(title: NSLocalizedString("Page Display", comment: ""), action: #selector(_menuItemAction), target: self)
  1233. menuItem.representedObject = identifier
  1234. item?.menuFormRepresentation = menuItem
  1235. } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
  1236. item?.image = NSImage(named: "KMImageNameUXIconAINor")
  1237. item?.titleName = NSLocalizedString("AI Tools", comment: "")
  1238. item?.target = self
  1239. item?.toolTip = NSLocalizedString("AI Tools", comment: "")
  1240. item?.boxImagePosition = .imageAbove
  1241. item?.selectBackgroundType = .imageBox
  1242. item?.btnAction = #selector(_itemAction)
  1243. item?.promptIdentifier = identifier
  1244. let menuItem = NSMenuItem.init(title: NSLocalizedString("AI Tools", comment: ""), action: #selector(_menuItemAction), target: self)
  1245. menuItem.representedObject = identifier
  1246. item?.menuFormRepresentation = menuItem
  1247. } else if identifier == KMDocumentShareToolbarItemIdentifier {
  1248. item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
  1249. item?.titleName = NSLocalizedString("Share", comment: "")
  1250. item?.target = self
  1251. // item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
  1252. item?.boxImagePosition = .imageAbove
  1253. item?.selectBackgroundType = .imageBox
  1254. item?.btnAction = #selector(shareButtonAction)
  1255. let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: nil, target: self)
  1256. let menu = NSMenu()
  1257. _ = menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
  1258. _ = menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
  1259. _ = menu.addItem(withTitle: NSLocalizedString("Original PDF", comment: ""), action: #selector(shareViaWithOriginalPDF), target: self)
  1260. menuItem.submenu = menu
  1261. item?.menuFormRepresentation = menuItem
  1262. } else if identifier == KMDocumentSearchToolbarItemIdentifier {
  1263. item?.titleName = NSLocalizedString("Search", comment: "")
  1264. item?.target = self
  1265. let view = NSView()
  1266. view.frame = NSMakeRect(0, 0, 150, 40)
  1267. let boxView = NSView()
  1268. boxView.frame = NSMakeRect(0, 16, 150, 22)
  1269. view.addSubview(boxView)
  1270. let searchView = NSSearchField()
  1271. searchView.frame = NSMakeRect(0, 0, 150, 22)
  1272. searchView.placeholderString = NSLocalizedString("Search", comment: "")
  1273. searchView.sendsWholeSearchString = true
  1274. searchView.sendsSearchStringImmediately = true
  1275. searchView.drawsBackground = false
  1276. searchView.delegate = self
  1277. self.searchField = searchView
  1278. self.refreshSearchBarMenu()
  1279. boxView.addSubview(searchView)
  1280. let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
  1281. view.addSubview(titleLabel)
  1282. titleLabel.frame = NSMakeRect(0, 0, 130, 14)
  1283. titleLabel.alignment = .center
  1284. titleLabel.textColor = KMAppearance.subtitleColor()
  1285. titleLabel.font = KMToolbarMainItemView.textFont
  1286. item?.customizeView = view
  1287. let menuItem = NSMenuItem.init(title: NSLocalizedString("Search", comment: ""), action: #selector(_menuItemAction), target: self)
  1288. menuItem.representedObject = identifier
  1289. item?.menuFormRepresentation = menuItem
  1290. } else if identifier == KMRightControlToolbarItemIdentifier {
  1291. item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
  1292. item?.titleName = NSLocalizedString("Properties", comment: "")
  1293. item?.target = self
  1294. item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
  1295. item?.boxImagePosition = .imageAbove
  1296. item?.selectBackgroundType = .imageBox
  1297. item?.btnAction = #selector(_itemAction)
  1298. let menuItem = NSMenuItem.init(title: NSLocalizedString("Properties", comment: ""), action: #selector(_menuItemAction), target: self)
  1299. menuItem.representedObject = identifier
  1300. item?.menuFormRepresentation = menuItem
  1301. } else if identifier == KMToolbarToolRedactItemIdentifier {
  1302. item?.image = NSImage(named: "KMImageNameMainToolsRedact")
  1303. item?.target = self
  1304. item?.btnTag = KMToolbarType.redact.rawValue
  1305. item?.toolTip = NSLocalizedString("Redact", comment: "")
  1306. item?.titleName = NSLocalizedString("Redact", comment: "")
  1307. item?.selectBackgroundType = .imageBox
  1308. item?.btnAction = #selector(redactMenuAction)
  1309. item?.promptIdentifier = identifier
  1310. let menuItem = NSMenuItem.init(title: NSLocalizedString("Redact", comment: ""), action: #selector(redactMenuAction), target: self)
  1311. menuItem.tag = item!.btnTag
  1312. menuItem.representedObject = identifier
  1313. item?.menuFormRepresentation = menuItem
  1314. } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
  1315. item?.image = NSImage(named: "DigitalSign_icon")
  1316. item?.target = self
  1317. item?.toolTip = NSLocalizedString("Digital signature ensures the authenticity and integrity of digital files. Click and drag the cursor to create a signature field on the page.", comment: "")
  1318. item?.titleName = NSLocalizedString("Digital Sign", comment: "")
  1319. item?.selectBackgroundType = .imageBox
  1320. item?.boxImagePosition = .imageAbove
  1321. item?.btnAction = #selector(_itemAction)
  1322. item?.promptIdentifier = identifier
  1323. let menuItem = NSMenuItem.init(title: NSLocalizedString("Digital Sign", comment: ""), action: #selector(_menuItemAction), target: self)
  1324. menuItem.tag = item!.btnTag
  1325. menuItem.representedObject = identifier
  1326. item?.menuFormRepresentation = menuItem
  1327. } else if identifier == KMDocumentPreviousBackToolbarItemIdentifier {
  1328. let view = KMToolbarPreviousBackItemView()
  1329. item?.customizeView = view
  1330. view.callback = { [weak self] idx, _ in
  1331. if idx == 1 {
  1332. self?.delegate?.changePDFViewGoToForwardAction?()
  1333. } else if idx == 2 {
  1334. self?.delegate?.changePDFViewGotoBackAction?()
  1335. }
  1336. }
  1337. } else if identifier == KMDocumentFirstLastToolbarItemIdentifier {
  1338. let view = KMToolbarFirstLastItemView()
  1339. item?.customizeView = view
  1340. view.callback = { [weak self] idx, _ in
  1341. if let item = self?.toolbarItemFindItemIdentifiers(value: identifier!) {
  1342. self?.delegate?.toolbarViewController?(self!, viewItemDidClick: item, index: idx, info: nil)
  1343. }
  1344. }
  1345. } else if identifier == KMDocumentPageIndicatorToolbarItemIdentifier {
  1346. // let view = KMToolbarPageIndicatorItemView(zoomView: nil)
  1347. // item?.customizeView = view
  1348. } else if identifier == KMDocumentPresentationToolbarItemIdentifier {
  1349. item?.image = NSImage(named: "KMImageNameToolbarSlideshowNor")
  1350. item?.titleName = NSLocalizedString("Presentation", comment: "")
  1351. item?.selectBackgroundType = .imageBox
  1352. item?.boxImagePosition = .imageAbove
  1353. item?.target = self
  1354. item?.btnTag = KMToolbarType.conversion_image.rawValue
  1355. // item?.toolTip = NSLocalizedString("Convert PDF to JPEG, PNG, TIFF, BMP, GIF or TGA files", comment: "")
  1356. item?.btnAction = #selector(_itemAction)
  1357. item?.promptIdentifier = identifier
  1358. } else if identifier == KMToolbarFixedSpaceItemIdentifier {
  1359. let view = NSView()
  1360. view.frame = NSMakeRect(0, 0, 36, 36)
  1361. item?.customizeView = view
  1362. }
  1363. }
  1364. private func _setupAnnotationItem(_ item: KMToolbarItemView?) {
  1365. let identifier = item?.itemIdentifier
  1366. if identifier == KMToolbarMoveToolModeItemIdentifier {
  1367. item?.titleName = NSLocalizedString("Scroll Tool", comment: "")
  1368. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsPantool)
  1369. item?.target = self
  1370. item?.btnTag = KMToolbarViewType.Move.rawValue
  1371. item?.isShowCustomToolTip = true
  1372. item?.toolTip = NSLocalizedString("Scroll Tool", comment: "")
  1373. item?.isPopToolTip = true
  1374. item?.boxImagePosition = .imageOnly
  1375. item?.btnAction = #selector(leftControllButtonAction)
  1376. } else if identifier == KMToolbarMagnifyToolModeItemIdentifier {
  1377. item?.titleName = NSLocalizedString("Magnify Tool", comment: "")
  1378. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsMagnifier)
  1379. item?.target = self
  1380. item?.btnTag = KMToolbarViewType.Magnify.rawValue
  1381. item?.isShowCustomToolTip = true
  1382. item?.toolTip = NSLocalizedString("Magnify Tool", comment: "")
  1383. item?.isPopToolTip = true
  1384. item?.boxImagePosition = .imageOnly
  1385. item?.btnAction = #selector(leftControllButtonAction)
  1386. } else if identifier == KMToolbarSelectToolModeItemIdentifier {
  1387. item?.titleName = NSLocalizedString("Content Selection Tool", comment: "")
  1388. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsContentsel)
  1389. item?.target = self
  1390. item?.btnTag = KMToolbarViewType.Select.rawValue
  1391. item?.isShowCustomToolTip = true
  1392. item?.toolTip = NSLocalizedString("Content Selection Tool", comment: "")
  1393. item?.isPopToolTip = true
  1394. item?.boxImagePosition = .imageOnly
  1395. item?.btnAction = #selector(leftControllButtonAction)
  1396. } else if identifier == KMToolbarZoomToSelectionItemIdentifier {
  1397. item?.titleName = NSLocalizedString("Zoom to selected area", comment: "")
  1398. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsAreazoom)
  1399. item?.target = self
  1400. item?.btnTag = KMToolbarViewType.SelectZoom.rawValue
  1401. item?.isShowCustomToolTip = true
  1402. item?.toolTip = NSLocalizedString("Zoom to selected area", comment: "")
  1403. item?.isPopToolTip = true
  1404. item?.boxImagePosition = .imageOnly
  1405. item?.btnAction = #selector(leftControllButtonAction)
  1406. } else if identifier == KMToolbarHighlightAnnotationItemIdentifier {
  1407. item?.titleName = NSLocalizedString("Highlight", comment: "")
  1408. // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsUnderline)
  1409. let imageV = KMNoteTypeImageView()
  1410. let color = UserDefaults.standard.PDFListViewColor(forKey: CHighlightNoteColorKey) ?? .red
  1411. item?.image = imageV.noteTypeImage(withType: SKNHighlightString, color: color)
  1412. item?.target = self
  1413. item?.btnTag = CAnnotationType.highlight.rawValue
  1414. item?.isShowCustomToolTip = true
  1415. item?.toolTip = String(format: "%@ (⌃⌘H)", NSLocalizedString("Highlight", comment: ""))
  1416. item?.isPopToolTip = true
  1417. item?.boxImagePosition = .imageOnly
  1418. item?.btnAction = #selector(changeAnnotationMode)
  1419. } else if identifier == KMToolbarUnderlineAnnotationItemIdentifier {
  1420. item?.titleName = NSLocalizedString("Underline", comment: "")
  1421. // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsUnderline)
  1422. let imageV = KMNoteTypeImageView()
  1423. let color = UserDefaults.standard.PDFListViewColor(forKey: CUnderlineNoteColorKey) ?? .red
  1424. item?.image = imageV.noteTypeImage(withType: SKNUnderlineString, color: color)
  1425. item?.target = self
  1426. item?.btnTag = CAnnotationType.underline.rawValue
  1427. item?.isShowCustomToolTip = true
  1428. item?.toolTip = String(format: "%@ (⇧⌘M)", NSLocalizedString("Underline", comment: ""))
  1429. item?.isPopToolTip = true
  1430. item?.boxImagePosition = .imageOnly
  1431. item?.btnAction = #selector(changeAnnotationMode)
  1432. } else if identifier == KMToolbarStrikeOutAnnotationItemIdentifier {
  1433. item?.titleName = NSLocalizedString("Strikethrough", comment: "")
  1434. // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsStrikeout)
  1435. let imageV = KMNoteTypeImageView()
  1436. let color = UserDefaults.standard.PDFListViewColor(forKey: CStrikeOutNoteColorKey) ?? .red
  1437. item?.image = imageV.noteTypeImage(withType: SKNStrikeOutString, color: color)
  1438. item?.target = self
  1439. item?.btnTag = CAnnotationType.strikeOut.rawValue
  1440. item?.isShowCustomToolTip = true
  1441. item?.toolTip = String(format: "%@ (⌃⌘M)", NSLocalizedString("Strikethrough", comment: ""))
  1442. item?.isPopToolTip = true
  1443. item?.boxImagePosition = .imageOnly
  1444. item?.btnAction = #selector(changeAnnotationMode)
  1445. } else if identifier == KMToolbarInkAnnotationItemIdentifier {
  1446. item?.titleName = NSLocalizedString("Freehand", comment: "")
  1447. // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsPen)
  1448. let imageV = KMNoteTypeImageView()
  1449. let color = UserDefaults.standard.PDFListViewColor(forKey: CInkNoteColorKey) ?? .red
  1450. item?.image = imageV.noteTypeImage(withType: SKNInkString, color: color)
  1451. item?.target = self
  1452. item?.btnTag = CAnnotationType.ink.rawValue
  1453. item?.isShowCustomToolTip = true
  1454. item?.toolTip = NSLocalizedString("Add freehand drawings by hand writing just like you do with a pen.", comment: "")
  1455. item?.isPopToolTip = true
  1456. item?.boxImagePosition = .imageOnly
  1457. item?.btnAction = #selector(changeAnnotationMode)
  1458. } else if identifier == KMToolbarFreeTextAnnotationItemIdentifier {
  1459. item?.titleName = NSLocalizedString("Text Note", comment: "")
  1460. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsText)
  1461. item?.target = self
  1462. item?.btnTag = CAnnotationType.freeText.rawValue
  1463. item?.isShowCustomToolTip = true
  1464. item?.toolTip = String(format: "%@ (⌘N)", NSLocalizedString("Text Note", comment: ""))
  1465. item?.isPopToolTip = true
  1466. item?.boxImagePosition = .imageOnly
  1467. item?.btnAction = #selector(changeAnnotationMode)
  1468. } else if identifier == KMToolbarAnchoredAnnotationItemIdentifier {
  1469. item?.titleName = NSLocalizedString("Anchored Note", comment: "")
  1470. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsNote)
  1471. item?.target = self
  1472. item?.btnTag = CAnnotationType.anchored.rawValue
  1473. item?.isShowCustomToolTip = true
  1474. item?.toolTip = String(format: "%@ (⌥⌘N)", NSLocalizedString("Anchored Note", comment: ""))
  1475. item?.isPopToolTip = true
  1476. item?.boxImagePosition = .imageOnly
  1477. item?.btnAction = #selector(changeAnnotationMode)
  1478. } else if identifier == KMToolbarSquareAnnotationItemIdentifier {
  1479. item?.titleName = NSLocalizedString("Rectangle", comment: "")
  1480. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsRec)
  1481. item?.target = self
  1482. item?.btnTag = CAnnotationType.square.rawValue
  1483. item?.isShowCustomToolTip = true
  1484. item?.toolTip = NSLocalizedString("Draw rectangle; draw square by holding Shift key", comment: "")
  1485. item?.isPopToolTip = true
  1486. item?.boxImagePosition = .imageOnly
  1487. item?.btnAction = #selector(changeAnnotationMode)
  1488. }else if identifier == KMToolbarCircleAnnotationItemIdentifier {
  1489. item?.titleName = NSLocalizedString("Circle", comment: "")
  1490. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsOval)
  1491. item?.target = self
  1492. item?.btnTag = CAnnotationType.circle.rawValue
  1493. item?.isShowCustomToolTip = true
  1494. item?.toolTip = NSLocalizedString("Draw oval; draw circle by holding Shift key", comment: "")
  1495. item?.isPopToolTip = true
  1496. item?.boxImagePosition = .imageOnly
  1497. item?.btnAction = #selector(changeAnnotationMode)
  1498. } else if identifier == KMToolbarArrowAnnotationItemIdentifier {
  1499. item?.titleName = NSLocalizedString("Arrow", comment: "")
  1500. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsArrow)
  1501. item?.target = self
  1502. item?.btnTag = CAnnotationType.arrow.rawValue
  1503. item?.isShowCustomToolTip = true
  1504. item?.toolTip = NSLocalizedString("Draw arrow; draw straight arrow by holding Shift key", comment: "")
  1505. item?.isPopToolTip = true
  1506. item?.boxImagePosition = .imageOnly
  1507. item?.btnAction = #selector(changeAnnotationMode)
  1508. } else if identifier == KMToolbarLineAnnotationItemIdentifier {
  1509. item?.titleName = NSLocalizedString("Line", comment: "")
  1510. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsLine)
  1511. item?.target = self
  1512. item?.btnTag = CAnnotationType.line.rawValue
  1513. item?.isShowCustomToolTip = true
  1514. item?.toolTip = NSLocalizedString("Draw line; draw straight line by holding Shift key", comment: "")
  1515. item?.isPopToolTip = true
  1516. item?.boxImagePosition = .imageOnly
  1517. item?.btnAction = #selector(changeAnnotationMode)
  1518. } else if identifier == KMToolbarLinkAnnotationItemIdentifier {
  1519. item?.titleName = NSLocalizedString("Link", comment: "")
  1520. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsLink)
  1521. item?.target = self
  1522. item?.btnTag = CAnnotationType.link.rawValue
  1523. item?.isShowCustomToolTip = true
  1524. item?.toolTip = NSLocalizedString("Select an area or text on a page for a link to be inserted.", comment: "")
  1525. item?.isPopToolTip = true
  1526. item?.boxImagePosition = .imageOnly
  1527. item?.btnAction = #selector(changeAnnotationMode)
  1528. } else if identifier == KMToolbarSignSignatureAnnotationItemIdentifier {
  1529. item?.titleName = NSLocalizedString("Signature", comment: "")
  1530. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsSign)
  1531. item?.target = self
  1532. item?.btnTag = CAnnotationType.signSignature.rawValue
  1533. item?.isShowCustomToolTip = true
  1534. item?.toolTip = NSLocalizedString("Add beautiful handwriting or use your trackpad to create your own signature.", comment: "")
  1535. item?.isPopToolTip = true
  1536. item?.boxImagePosition = .imageOnly
  1537. item?.btnAction = #selector(changeAnnotationMode)
  1538. } else if identifier == KMAnnotationStampToolbarItemIdentifier {
  1539. item?.titleName = NSLocalizedString("Stamp", comment: "")
  1540. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsStamp)
  1541. item?.target = self
  1542. item?.btnTag = CAnnotationType.stamp.rawValue
  1543. item?.isShowCustomToolTip = true
  1544. item?.toolTip = NSLocalizedString("Add New Stamp", comment: "")
  1545. item?.isPopToolTip = true
  1546. item?.boxImagePosition = .imageOnly
  1547. item?.btnAction = #selector(changeAnnotationMode)
  1548. } else if identifier == KMToolbarShowToolbarItemIdentifier {
  1549. item?.image = NSImage(named: "KMImageNameMainToolShow")
  1550. item?.selectedImage = NSImage(named: "KMImageNameMainToolHide")
  1551. item?.alternateImage = NSImage(named: "KMImageNameMainToolShow")
  1552. item?.selectedBackgroundColor = NSColor.clear
  1553. item?.target = self
  1554. item?.isShowCustomToolTip = true
  1555. item?.toolTip = NSLocalizedString("Hide", comment: "")
  1556. item?.isPopToolTip = true
  1557. item?.titleName = NSLocalizedString("Hide", comment: "")
  1558. item?.boxImagePosition = .imageOnly
  1559. item?.btnAction = #selector(showPDFLayoutMode)
  1560. } else if identifier == KMToolbarAnnotationSettingItemIdentifier {
  1561. item?.image = NSImage(named: "KMImageNameUXIconBtnSetNor")
  1562. item?.target = self
  1563. item?.isShowCustomToolTip = true
  1564. item?.toolTip = String(format: "%@\n%@", NSLocalizedString("Customize Toolbar", comment: ""),NSLocalizedString("Drag-and-drop tools to change their order", comment: ""))
  1565. item?.isPopToolTip = true
  1566. item?.titleName = NSLocalizedString("Setting", comment: "")
  1567. item?.boxImagePosition = .imageOnly
  1568. item?.btnAction = #selector(_itemAction)
  1569. item?.selectBackgroundType = .imageBox
  1570. } else if identifier == KMAnnotationImageToolbarItemIdentifier {
  1571. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsImage)
  1572. item?.target = self
  1573. item?.titleName = NSLocalizedString("Image", comment: "")
  1574. item?.isShowCustomToolTip = true
  1575. item?.toolTip = NSLocalizedString("Choose an image to insert in a page.", comment: "")
  1576. item?.isPopToolTip = true
  1577. item?.boxImagePosition = .imageOnly
  1578. item?.btnAction = #selector(_itemAction)
  1579. } else if identifier == KMAnnotationTableToolbarItemIdentifier {
  1580. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsTable)
  1581. item?.target = self
  1582. item?.btnTag = CAnnotationType.table.rawValue
  1583. item?.titleName = NSLocalizedString("Table", comment: "")
  1584. item?.isShowCustomToolTip = true
  1585. item?.toolTip = NSLocalizedString("Table", comment: "")
  1586. item?.isPopToolTip = true
  1587. item?.boxImagePosition = .imageOnly
  1588. item?.btnAction = #selector(_itemAction)
  1589. }
  1590. }
  1591. private func _setupEditItem(_ item: KMToolbarItemView?) {
  1592. let identifier = item?.itemIdentifier
  1593. if identifier == KMToolbarAddTextEditPDFItemIdentifier {
  1594. item?.image = NSImage(named: "KMImageNameButtonEidtPDFText")
  1595. item?.target = self
  1596. item?.btnTag = CAnnotationType.addText.rawValue
  1597. item?.toolTip = NSLocalizedString("Add Text", comment: "")
  1598. item?.titleName = NSLocalizedString("Add Text", comment: "")
  1599. item?.boxImagePosition = .imageLeft
  1600. item?.btnAction = #selector(changeAnnotationMode)
  1601. } else if identifier == KMToolbarAddImageEditPDFItemIdentifier {
  1602. item?.image = NSImage(named: "KMImageNameButtonEidtPDFImage")
  1603. item?.target = self
  1604. item?.btnTag = CAnnotationType.addImage.rawValue
  1605. item?.toolTip = NSLocalizedString("Add Image", comment: "")
  1606. item?.titleName = NSLocalizedString("Add Image", comment: "")
  1607. item?.boxImagePosition = .imageLeft
  1608. item?.btnAction = #selector(changeAnnotationMode)
  1609. }
  1610. }
  1611. private func _setupConvertItem(_ item: KMToolbarItemView?) {
  1612. let identifier = item?.itemIdentifier
  1613. if identifier == KMToolbarConversionWordItemIdentifier {
  1614. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertWord)
  1615. item?.target = self
  1616. item?.btnTag = KMToolbarType.word.rawValue
  1617. 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: "")
  1618. item?.titleName = NSLocalizedString("To Word", comment: "")
  1619. item?.boxImagePosition = .imageLeft
  1620. item?.btnAction = #selector(conversionMenuItemAction)
  1621. item?.promptIdentifier = identifier
  1622. } else if identifier == KMToolbarConversionExcelItemIdentifier {
  1623. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertExcel)
  1624. item?.target = self
  1625. item?.btnTag = KMToolbarType.excel.rawValue
  1626. 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: "")
  1627. item?.titleName = NSLocalizedString("To Excel", comment: "")
  1628. item?.boxImagePosition = .imageLeft
  1629. item?.btnAction = #selector(conversionMenuItemAction)
  1630. item?.promptIdentifier = identifier
  1631. } else if identifier == KMToolbarConversionPPTItemIdentifier {
  1632. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPPT)
  1633. item?.target = self
  1634. item?.btnTag = KMToolbarType.ppt.rawValue
  1635. 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: "")
  1636. item?.titleName = NSLocalizedString("To PPT", comment: "")
  1637. item?.boxImagePosition = .imageLeft
  1638. item?.btnAction = #selector(conversionMenuItemAction)
  1639. item?.promptIdentifier = identifier
  1640. } else if identifier == KMToolbarConversionRTFItemIdentifier {
  1641. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertRTF)
  1642. item?.target = self
  1643. item?.btnTag = KMToolbarType.rtf.rawValue
  1644. item?.toolTip = NSLocalizedString("Turn PDF documents into Rich Text Format (RTF) files that can be opened in virtually any word processor.", comment: "")
  1645. item?.titleName = NSLocalizedString("To RTF", comment: "")
  1646. item?.boxImagePosition = .imageLeft
  1647. item?.btnAction = #selector(conversionMenuItemAction)
  1648. item?.promptIdentifier = identifier
  1649. } else if identifier == KMToolbarConversionCSVItemIdentifier {
  1650. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertCSV)
  1651. item?.target = self
  1652. item?.btnTag = KMToolbarType.csv.rawValue
  1653. item?.toolTip = NSLocalizedString("PDF To CSV", comment: "")
  1654. item?.titleName = NSLocalizedString("To CSV", comment: "")
  1655. item?.boxImagePosition = .imageLeft
  1656. item?.btnAction = #selector(conversionMenuItemAction)
  1657. item?.promptIdentifier = identifier
  1658. } else if identifier == KMToolbarConversionHTMLItemIdentifier {
  1659. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertHtml)
  1660. item?.target = self
  1661. item?.btnTag = KMToolbarType.html.rawValue
  1662. item?.toolTip = NSLocalizedString("PDF To HTML", comment: "")
  1663. item?.titleName = NSLocalizedString("To HTML", comment: "")
  1664. item?.boxImagePosition = .imageLeft
  1665. item?.btnAction = #selector(conversionMenuItemAction)
  1666. } else if identifier == KMToolbarConversionTextItemIdentifier {
  1667. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertText)
  1668. item?.target = self
  1669. item?.btnTag = KMToolbarType.conversion_text.rawValue
  1670. item?.toolTip = NSLocalizedString("PDF To Text", comment: "")
  1671. item?.titleName = NSLocalizedString("To Text", comment: "")
  1672. item?.boxImagePosition = .imageLeft
  1673. item?.btnAction = #selector(conversionMenuItemAction)
  1674. } else if identifier == KMToolbarConversionImageItemIdentifier {
  1675. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPDFToIMG)
  1676. item?.target = self
  1677. item?.btnTag = KMToolbarType.conversion_image.rawValue
  1678. // item?.toolTip = NSLocalizedString("Convert PDF to JPEG, PNG, TIFF, BMP, GIF or TGA files", comment: "")
  1679. item?.titleName = NSLocalizedString("To Image", comment: "")
  1680. item?.boxImagePosition = .imageExpandLeft
  1681. item?.needExpandAction = true
  1682. item?.btnAction = #selector(convertToImage)
  1683. item?.promptIdentifier = identifier
  1684. let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: #selector(conversionMenuItemAction), target: self)
  1685. let subMenu = NSMenu()
  1686. subMenu.addItem(title: NSLocalizedString("PDF To JPEG", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.jpeg.rawValue)
  1687. subMenu.addItem(title: NSLocalizedString("PDF To JPG", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.jpg.rawValue)
  1688. subMenu.addItem(title: NSLocalizedString("PDF To PNG", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.png.rawValue)
  1689. subMenu.addItem(title: NSLocalizedString("PDF To GIF", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.gif.rawValue)
  1690. subMenu.addItem(title: NSLocalizedString("PDF To TIFF", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.tiff.rawValue)
  1691. subMenu.addItem(title: NSLocalizedString("PDF To TGA", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.tga.rawValue)
  1692. subMenu.addItem(title: NSLocalizedString("PDF To BMP", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.bmp.rawValue)
  1693. menuItem.submenu = subMenu
  1694. item?.menuFormRepresentation = menuItem
  1695. } else if item?.itemIdentifier == KMToolbarConversionExportImageItemIdentifier {
  1696. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertExportImage)
  1697. item?.target = self
  1698. // item?.toolTip = NSLocalizedString("The range you can extract images includes current page, odd page, even page, custom page, and all pages.", comment: "")
  1699. item?.titleName = NSLocalizedString("Extract Images", comment: "")
  1700. item?.boxImagePosition = .imageExpandLeft
  1701. item?.needExpandAction = true
  1702. item?.promptIdentifier = identifier
  1703. let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: nil, target: self)
  1704. let subMenu = NSMenu()
  1705. subMenu.addItem(title: NSLocalizedString("Extract All Images", comment: ""), action: #selector(_exportImageAction), target: self, tag: 1)
  1706. subMenu.addItem(title: NSLocalizedString("Extract Images", comment: ""), action: #selector(_exportImageAction), target: self, tag: 2)
  1707. menuItem.submenu = subMenu
  1708. item?.menuFormRepresentation = menuItem
  1709. } else if item?.itemIdentifier == KMToolbarConversionOCRIdentifier {
  1710. item?.titleName = NSLocalizedString("OCR", comment: "")
  1711. item?.target = self
  1712. item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
  1713. item?.boxImagePosition = .imageLeft
  1714. item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
  1715. item?.btnAction = #selector(OCRbtnAction2)
  1716. let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
  1717. menuItem.representedObject = KMToolbarConversionOCRIdentifier
  1718. item?.menuFormRepresentation = menuItem
  1719. } else if item?.itemIdentifier == KMToolbarConversionCreatePDFItemIdentifier {
  1720. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertCreatPDF)
  1721. item?.target = self
  1722. // item?.toolTip = NSLocalizedString("Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", comment: "")
  1723. item?.titleName = NSLocalizedString("New PDF Document", comment: "")
  1724. item?.boxImagePosition = .imageExpandLeft
  1725. item?.needExpandAction = true
  1726. let menuItem = NSMenuItem.init(title: "New PDF Document", action: nil, target: self)
  1727. let subMenu = NSMenu()
  1728. subMenu.addItem(title: NSLocalizedString("New Blank Page", comment: ""), action: #selector(_newPDFAction), target: self, tag: 1)
  1729. subMenu.addItem(title: NSLocalizedString("New From Images", comment: ""), action: #selector(_newPDFAction), target: self, tag: 2)
  1730. subMenu.addItem(NSMenuItem.separator())
  1731. subMenu.addItem(title: NSLocalizedString("New From Web Page", comment: ""), action: #selector(_newPDFAction), target: self, tag: 3)
  1732. subMenu.addItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(_newPDFAction), target: self, tag: 4)
  1733. subMenu.addItem(NSMenuItem.separator())
  1734. subMenu.addItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(_newPDFAction), target: self, tag: 5)
  1735. menuItem.submenu = subMenu
  1736. item?.menuFormRepresentation = menuItem
  1737. }
  1738. }
  1739. @objc func convertToImage(_ sender: KMToolbarItem) {
  1740. // if let subMenu = sender.menuFormRepresentation?.submenu {
  1741. // subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
  1742. // }
  1743. }
  1744. private func _setupFillSignItem(_ item: KMToolbarItemView?) {
  1745. let identifier = item?.itemIdentifier
  1746. if identifier == KMToolbarToolHookItemIdentifier {
  1747. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignTick)
  1748. item?.target = self
  1749. item?.btnTag = CAnnotationType.signTure.rawValue
  1750. item?.toolTip = NSLocalizedString("Signature", comment: "")
  1751. item?.titleName = NSLocalizedString("Signature", comment: "")
  1752. item?.boxImagePosition = .imageOnly
  1753. item?.btnAction = #selector(changeAnnotationMode)
  1754. } else if identifier == KMToolbarToolForkItemIdentifier {
  1755. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignFork)
  1756. item?.target = self
  1757. item?.btnTag = CAnnotationType.signFalse.rawValue
  1758. item?.toolTip = NSLocalizedString("Add X", comment: "")
  1759. item?.boxImagePosition = .imageOnly
  1760. item?.btnAction = #selector(changeAnnotationMode)
  1761. } else if identifier == KMToolbarToolLineItemIdentifier {
  1762. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignLine)
  1763. item?.target = self
  1764. item?.btnTag = CAnnotationType.signLine.rawValue
  1765. item?.toolTip = NSLocalizedString("Add line", comment: "")
  1766. item?.boxImagePosition = .imageOnly
  1767. item?.btnAction = #selector(changeAnnotationMode)
  1768. } else if identifier == KMToolbarToolDotItemIdentifier {
  1769. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignPoint)
  1770. item?.target = self
  1771. item?.btnTag = CAnnotationType.signDot.rawValue
  1772. item?.toolTip = NSLocalizedString("Add dot", comment: "")
  1773. item?.boxImagePosition = .imageOnly
  1774. item?.btnAction = #selector(changeAnnotationMode)
  1775. } else if identifier == KMToolbarToolRectangleIdentifier {
  1776. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignRoundedrec)
  1777. item?.target = self
  1778. item?.btnTag = CAnnotationType.signCircle.rawValue
  1779. item?.toolTip = NSLocalizedString("Add circle", comment: "")
  1780. item?.boxImagePosition = .imageOnly
  1781. item?.btnAction = #selector(changeAnnotationMode)
  1782. } else if identifier == KMToolbarToolTextIdentifier {
  1783. item?.image = NSImage(named: KMImageNameToolbarFreeText)
  1784. item?.target = self
  1785. item?.btnTag = CAnnotationType.signText.rawValue
  1786. item?.toolTip = NSLocalizedString("Add text", comment: "")
  1787. item?.titleName = NSLocalizedString("Text", comment: "")
  1788. item?.boxImagePosition = .imageOnly
  1789. item?.btnAction = #selector(changeAnnotationMode)
  1790. } else if identifier == KMToolbarToolDateIdentifier {
  1791. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignDate)
  1792. item?.target = self
  1793. item?.btnTag = CAnnotationType.signDate.rawValue
  1794. item?.toolTip = NSLocalizedString("Date", comment: "")
  1795. item?.boxImagePosition = .imageOnly
  1796. item?.btnAction = #selector(changeAnnotationMode)
  1797. } else if (identifier == KMToolbarToolProfileIdentifier) {
  1798. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignMyprofile)
  1799. item?.target = self
  1800. item?.toolTip = NSLocalizedString("My Profile", comment: "")
  1801. item?.boxImagePosition = .imageOnly
  1802. item?.btnAction = #selector(_itemAction)
  1803. }else if (identifier == KMToolbarFillSignSignatureIdentifier) {
  1804. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignMysignature)
  1805. item?.target = self
  1806. item?.btnTag = CAnnotationType.signSignature.rawValue
  1807. item?.toolTip = NSLocalizedString("Sign document by typing or drawing a signature", comment: "")
  1808. item?.boxImagePosition = .imageOnly
  1809. item?.btnAction = #selector(changeAnnotationMode)
  1810. }
  1811. }
  1812. private func _setupFormItem(_ item: KMToolbarItemView?) {
  1813. let identifier = item?.itemIdentifier
  1814. if identifier == KMToolbarToolTextFieldItemIdentifier {
  1815. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormTextfield)
  1816. item?.target = self
  1817. item?.btnTag = CAnnotationType.textField.rawValue
  1818. item?.toolTip = NSLocalizedString("Text Field", comment: "")
  1819. item?.titleName = NSLocalizedString("Text Field", comment: "")
  1820. item?.boxImagePosition = .imageLeft
  1821. item?.btnAction = #selector(changeAnnotationMode)
  1822. let menuItem = NSMenuItem.init(title: "TextField", action: #selector(changeAnnotationMode), target: self)
  1823. menuItem.tag = item!.btnTag
  1824. item?.menuFormRepresentation = menuItem
  1825. } else if identifier == KMToolbarToolCheckBoxItemIdentifier {
  1826. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormCheckbox)
  1827. item?.target = self
  1828. item?.btnTag = CAnnotationType.checkBox.rawValue
  1829. item?.toolTip = NSLocalizedString("Check Box", comment: "")
  1830. item?.titleName = NSLocalizedString("Check Box", comment: "")
  1831. item?.boxImagePosition = .imageLeft
  1832. item?.btnAction = #selector(changeAnnotationMode)
  1833. } else if identifier == KMToolbarToolRadioButtonItemIdentifier {
  1834. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormRadiobutton)
  1835. item?.target = self
  1836. item?.btnTag = CAnnotationType.radioButton.rawValue
  1837. item?.toolTip = NSLocalizedString("Radio Button", comment: "")
  1838. item?.titleName = NSLocalizedString("Radio Button", comment: "")
  1839. item?.boxImagePosition = .imageLeft
  1840. item?.btnAction = #selector(changeAnnotationMode)
  1841. let menuItem = NSMenuItem.init(title: "RadioButton", action: #selector(changeAnnotationMode), target: self)
  1842. menuItem.tag = item!.btnTag
  1843. item?.menuFormRepresentation = menuItem
  1844. } else if identifier == KMToolbarToolListBoxItemIdentifier {
  1845. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormListbox)
  1846. item?.target = self
  1847. item?.btnTag = CAnnotationType.listMenu.rawValue
  1848. item?.toolTip = NSLocalizedString("List Box", comment: "")
  1849. item?.titleName = NSLocalizedString("List Box", comment: "")
  1850. item?.boxImagePosition = .imageLeft
  1851. item?.btnAction = #selector(changeAnnotationMode)
  1852. let menuItem = NSMenuItem.init(title: "List Box", action: #selector(changeAnnotationMode), target: self)
  1853. menuItem.tag = item!.btnTag
  1854. item?.menuFormRepresentation = menuItem
  1855. } else if identifier == KMToolbarToolPullDownmenuItemIdentifier {
  1856. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormPulldownmenu)
  1857. item?.target = self
  1858. item?.btnTag = CAnnotationType.comboBox.rawValue
  1859. item?.toolTip = NSLocalizedString("Combo Box", comment: "")
  1860. item?.titleName = NSLocalizedString("Combo Box", comment: "")
  1861. item?.boxImagePosition = .imageLeft
  1862. item?.btnAction = #selector(changeAnnotationMode)
  1863. let menuItem = NSMenuItem.init(title: "PullDownmenu", action: #selector(changeAnnotationMode), target: self)
  1864. menuItem.tag = item!.btnTag
  1865. item?.menuFormRepresentation = menuItem
  1866. } else if identifier == KMToolbarToolButtonIdentifier {
  1867. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormButton)
  1868. item?.target = self
  1869. item?.btnTag = CAnnotationType.actionButton.rawValue
  1870. item?.toolTip = NSLocalizedString("Button", comment: "")
  1871. item?.titleName = NSLocalizedString("Button", comment: "")
  1872. item?.boxImagePosition = .imageLeft
  1873. item?.btnAction = #selector(changeAnnotationMode)
  1874. let menuItem = NSMenuItem.init(title: "Button", action: #selector(changeAnnotationMode), target: self)
  1875. menuItem.tag = item!.btnTag
  1876. item?.menuFormRepresentation = menuItem
  1877. } else if identifier == KMToolbarToolSignBoxIdentifier {
  1878. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormSign)
  1879. item?.target = self
  1880. item?.btnTag = CAnnotationType.signature.rawValue
  1881. item?.toolTip = NSLocalizedString("Signature", comment: "")
  1882. item?.titleName = NSLocalizedString("Signature", comment: "")
  1883. item?.boxImagePosition = .imageLeft
  1884. item?.btnAction = #selector(changeAnnotationMode)
  1885. let menuItem = NSMenuItem.init(title: "SignBox", action: #selector(changeAnnotationMode), target: self)
  1886. menuItem.tag = item!.btnTag
  1887. item?.menuFormRepresentation = menuItem
  1888. } else if identifier == KMToolbarToolFormAlignIdentifier {
  1889. item?.image = NSImage(named: KMImageNameUXIconPropertybarAlignLeftToor)
  1890. item?.target = self
  1891. // item?.toolTip = NSLocalizedString("Alignment", comment: "")
  1892. item?.titleName = NSLocalizedString("", comment: "")
  1893. item?.boxImagePosition = .imageExpandLeft
  1894. item?.needExpandAction = true
  1895. item?.btnAction = #selector(formsAlignmentAction)
  1896. item?.pdfView = self.pdfView
  1897. let menuItem = NSMenuItem.init(title: "Alignment", action: nil, target: self)
  1898. let subMenu = NSMenu()
  1899. subMenu.addItem(title: NSLocalizedString("Align Left", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignLeftNor", action: #selector(formsAlignmentAction), target: self, tag: 0)
  1900. subMenu.addItem(title: NSLocalizedString("Align Vertically", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignVercenterNor", action: #selector(formsAlignmentAction), target: self, tag: 1)
  1901. subMenu.addItem(title: NSLocalizedString("Align Right", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignRightNor", action: #selector(formsAlignmentAction), target: self, tag: 2)
  1902. subMenu.addItem(NSMenuItem.separator())
  1903. subMenu.addItem(title: NSLocalizedString("Align Top", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignUpNor", action: #selector(formsAlignmentAction), target: self, tag: 3)
  1904. subMenu.addItem(title: NSLocalizedString("Align Horizontally", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignHorcenterNor", action: #selector(formsAlignmentAction), target: self, tag: 4)
  1905. subMenu.addItem(title: NSLocalizedString("Align Bottom", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignDownNor", action: #selector(formsAlignmentAction), target: self, tag: 5)
  1906. subMenu.addItem(NSMenuItem.separator())
  1907. subMenu.addItem(title: NSLocalizedString("Distribute Horizontally", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignHorsplitNor", action: #selector(formsAlignmentAction), target: self, tag: 6)
  1908. subMenu.addItem(title: NSLocalizedString("Distribute Vertically", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignVersplitNor", action: #selector(formsAlignmentAction), target: self, tag: 7)
  1909. menuItem.submenu = subMenu
  1910. menuItem.tag = item!.btnTag
  1911. item?.menuFormRepresentation = menuItem
  1912. } else if identifier == KMToolbarToolFormMoreIdentifier {
  1913. item?.image = NSImage(named: "KMImageNameMainToolFormMore")
  1914. item?.target = self
  1915. item?.toolTip = NSLocalizedString("More", comment: "")
  1916. item?.titleName = NSLocalizedString("More", comment: "")
  1917. item?.boxImagePosition = .imageExpandLeft
  1918. item?.btnAction = #selector(formsMoreOperationAction)
  1919. let menuItem = NSMenuItem.init(title: "More", action: #selector(formsMoreOperationAction), target: self)
  1920. menuItem.tag = item!.btnTag
  1921. item?.menuFormRepresentation = menuItem
  1922. }
  1923. }
  1924. private func _setupViewDisplayItem(_ item: KMToolbarItemView?) {
  1925. let identifier = item?.itemIdentifier
  1926. if identifier == KMToolbarViewSettingIdentifier {
  1927. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayView)
  1928. item?.target = self
  1929. item?.toolTip = NSLocalizedString("View Settings", comment: "")
  1930. item?.titleName = NSLocalizedString("View Settings", comment: "")
  1931. item?.boxImagePosition = .imageLeft
  1932. item?.btnAction = #selector(_itemAction)
  1933. } else if identifier == KMToolbarCropIdentifier {
  1934. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTailor)
  1935. item?.target = self
  1936. // item?.toolTip = NSLocalizedString("Note: Cropping a PDF hides some of the PDF’s content without removing it.", comment: "")
  1937. item?.titleName = NSLocalizedString("Crop", comment: "")
  1938. item?.boxImagePosition = .imageExpandLeft
  1939. item?.needExpandAction = true
  1940. // item?.btnAction = #selector(cropMenuAction)
  1941. let menuItem = NSMenuItem.init(title: "Crop", action: #selector(cropMenuAction), target: self)
  1942. let subMenu = NSMenu()
  1943. // subMenu.addItem(title: NSLocalizedString("Crop All Pages", comment: ""), action: #selector(_cropAction), target: self, tag: 1)
  1944. subMenu.addItem(title: NSLocalizedString("Crop Current Page", comment: ""), action: #selector(_cropAction), target: self, tag: 2)
  1945. subMenu.addItem(title: NSLocalizedString("Auto Crop – Separate", comment: ""), action: #selector(_cropAction), target: self, tag: 3)
  1946. subMenu.addItem(title: NSLocalizedString("Auto Crop – Combined", comment: ""), action: #selector(_cropAction), target: self, tag: 4)
  1947. subMenu.addItem(title: NSLocalizedString("Select Area", comment: ""), action: #selector(_cropAction), target: self, tag: 5)
  1948. // subMenu.addItem(title: NSLocalizedString("Crop Options...", comment: ""), action: #selector(_cropAction), target: self, tag: 6)
  1949. menuItem.submenu = subMenu
  1950. item?.menuFormRepresentation = menuItem
  1951. } else if identifier == KMToolbarSnapshotIdentifier {
  1952. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplaySnapshot)
  1953. item?.target = self
  1954. item?.toolTip = NSLocalizedString("Take Snapshot", comment: "")
  1955. item?.titleName = NSLocalizedString("Snapshot", comment: "")
  1956. item?.boxImagePosition = .imageLeft
  1957. item?.btnAction = #selector(_itemAction)
  1958. } else if identifier == KMToolbarTTSIdentifier {
  1959. item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTTS)
  1960. item?.target = self
  1961. item?.toolTip = NSLocalizedString("TTS (Text-to-speech)", comment: "")
  1962. item?.titleName = NSLocalizedString("TTS", comment: "")
  1963. item?.boxImagePosition = .imageLeft
  1964. item?.btnAction = #selector(_itemAction)
  1965. }
  1966. }
  1967. private func _setupToolItem(_ item: KMToolbarItemView?) {
  1968. let identifier = item?.itemIdentifier
  1969. if identifier == KMToolbarToolCropItemIdentifier {
  1970. item?.image = NSImage(named: "KMImageNameMainToolsCrop")
  1971. item?.alternateImage = NSImage(named: "KMImageNameMainToolsCrop")
  1972. item?.target = self
  1973. item?.btnTag = KMToolbarType.crop.rawValue
  1974. item?.toolTip = NSLocalizedString("Crop pages", comment: "")
  1975. item?.titleName = NSLocalizedString("Crop", comment: "")
  1976. item?.boxImagePosition = .imageExpandLeft
  1977. item?.btnAction = #selector(cropMenuAction)
  1978. let menuItem = NSMenuItem.init(title: "Crop", action: #selector(cropMenuAction), target: self)
  1979. item?.menuFormRepresentation = menuItem
  1980. } else if identifier == KMToolbarComparisonItemIdentifier {
  1981. item?.image = NSImage(named: KMImageNameUXIconBatchComparison)
  1982. item?.target = self
  1983. item?.btnTag = KMToolbarType.comparison.rawValue
  1984. // item?.toolTip = NSLocalizedString("Compare", comment: "")
  1985. item?.titleName = NSLocalizedString("Compare", comment: "")
  1986. item?.boxImagePosition = .imageExpandLeft
  1987. item?.needExpandAction = true
  1988. // item?.btnAction = #selector(_itemAction)
  1989. let menuItem = NSMenuItem.init(title: "Bates Number", action: #selector(_menuItemAction), target: self)
  1990. let subMenu = NSMenu()
  1991. subMenu.addItem(title: NSLocalizedString("Side-by-Side View", comment: ""), action: #selector(_comparisonAction), target: self, tag: 1)
  1992. subMenu.addItem(title: NSLocalizedString("Compare by File Overlay", comment: ""), action: #selector(_comparisonAction), target: self, tag: 2)
  1993. menuItem.submenu = subMenu
  1994. item?.menuFormRepresentation = menuItem
  1995. } else if identifier == KMToolbarToolBatesItemIdentifier {
  1996. item?.image = NSImage(named: "KMImageNameUXIconBatchBatesNor")
  1997. item?.target = self
  1998. item?.btnTag = KMToolbarType.bates.rawValue
  1999. // item?.toolTip = NSLocalizedString("Add PDF Bates numbering to your legal, medical, or business documents", comment: "")
  2000. item?.titleName = NSLocalizedString("Bates Numbers", comment: "")
  2001. item?.boxImagePosition = .imageExpandLeft
  2002. item?.needExpandAction = true
  2003. // item?.btnAction = #selector(batesMenuAction)
  2004. let menuItem = NSMenuItem.init(title: "Bates Numbers", action: #selector(batesMenuAction), target: self)
  2005. let subMenu = NSMenu()
  2006. subMenu.addItem(title: NSLocalizedString("Add Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 1)
  2007. subMenu.addItem(title: NSLocalizedString("Remove Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 2)
  2008. subMenu.addItem(title: NSLocalizedString("Batch Add Batch Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 3)
  2009. subMenu.addItem(title: NSLocalizedString("Batch Remove Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 4)
  2010. subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_batesAction), target: self, tag: 5)
  2011. menuItem.submenu = subMenu
  2012. item?.menuFormRepresentation = menuItem
  2013. } else if identifier == KMToolbarAIItemIdentifier {
  2014. item?.image = NSImage(named: "KMImageNameUXIconAINor")
  2015. item?.target = self
  2016. item?.btnTag = KMToolbarType.aiTools.rawValue
  2017. item?.titleName = NSLocalizedString("AI Tools", comment: "")
  2018. item?.boxImagePosition = .imageExpandLeft
  2019. item?.needExpandAction = true
  2020. let menuItem = NSMenuItem.init(title: "AI Tools", action: #selector(batesMenuAction), target: self)
  2021. let subMenu = NSMenu()
  2022. subMenu.addItem(title: NSLocalizedString("AI Summarize", comment: ""), action: #selector(_AIAction), target: self, tag: 1)
  2023. subMenu.addItem(title: NSLocalizedString("AI Rewrite", comment: ""), action: #selector(_AIAction), target: self, tag: 2)
  2024. subMenu.addItem(title: NSLocalizedString("AI Proofread", comment: ""), action: #selector(_AIAction), target: self, tag: 3)
  2025. subMenu.addItem(title: NSLocalizedString("AI Translate", comment: ""), action: #selector(_AIAction), target: self, tag: 4)
  2026. menuItem.submenu = subMenu
  2027. item?.menuFormRepresentation = menuItem
  2028. } else if identifier == KMToolbarToolHeaderFooterItemIdentifier {
  2029. item?.image = NSImage(named: "KMImageNameUXIconBatchHeaderandfooterNor")
  2030. item?.target = self
  2031. item?.btnTag = KMToolbarType.headerAndFooter.rawValue
  2032. // item?.toolTip = NSLocalizedString("Insert header, footer, and page numbers to PDF", comment: "")
  2033. item?.titleName = NSLocalizedString("Header & Footer", comment: "")
  2034. item?.boxImagePosition = .imageExpandLeft
  2035. item?.needExpandAction = true
  2036. // item?.btnAction = #selector(headerfooterMenuAction)
  2037. let menuItem = NSMenuItem.init(title: "Header & Footer", action: #selector(headerfooterMenuAction), target: self)
  2038. let subMenu = NSMenu()
  2039. subMenu.addItem(title: NSLocalizedString("Add Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 1)
  2040. subMenu.addItem(title: NSLocalizedString("Remove Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 2)
  2041. subMenu.addItem(title: NSLocalizedString("Batch Add Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 3)
  2042. subMenu.addItem(title: NSLocalizedString("Batch Remove Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 4)
  2043. subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 5)
  2044. menuItem.submenu = subMenu
  2045. item?.menuFormRepresentation = menuItem
  2046. } else if identifier == KMToolbarToolBackgroundItemIdentifier {
  2047. item?.image = NSImage(named: "KMImageNameUXIconBatchBackgroundNor")
  2048. item?.target = self
  2049. item?.btnTag = KMToolbarType.background.rawValue
  2050. // item?.toolTip = NSLocalizedString("Insert PDF page background by color or image", comment: "")
  2051. item?.titleName = NSLocalizedString("Background", comment: "")
  2052. item?.boxImagePosition = .imageExpandLeft
  2053. item?.needExpandAction = true
  2054. // item?.btnAction = #selector(backgroundMenuAction)
  2055. let menuItem = NSMenuItem.init(title: "Background", action: #selector(backgroundMenuAction), target: self)
  2056. let subMenu = NSMenu()
  2057. subMenu.addItem(title: NSLocalizedString("Add Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 1)
  2058. subMenu.addItem(title: NSLocalizedString("Remove Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 2)
  2059. subMenu.addItem(title: NSLocalizedString("Batch Add Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 3)
  2060. subMenu.addItem(title: NSLocalizedString("Batch Remove Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 4)
  2061. subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_backgroundAction), target: self, tag: 5)
  2062. menuItem.submenu = subMenu
  2063. item?.menuFormRepresentation = menuItem
  2064. } else if identifier == KMToolbarToolWatermarkItemIdentifier {
  2065. item?.image = NSImage(named: "KMImageNameUXIconBatchWatermarkNor")
  2066. item?.target = self
  2067. item?.btnTag = KMToolbarType.watermark.rawValue
  2068. // item?.toolTip = NSLocalizedString("Watermark", comment: "")
  2069. item?.titleName = NSLocalizedString("Watermark", comment: "")
  2070. item?.boxImagePosition = .imageExpandLeft
  2071. item?.needExpandAction = true
  2072. // item?.btnAction = #selector(watermarkMenuAction)
  2073. let menuItem = NSMenuItem.init(title: "Watermark", action: #selector(watermarkMenuAction), target: self)
  2074. let subMenu = NSMenu()
  2075. subMenu.addItem(title: NSLocalizedString("Add Watermark", comment: ""), action: #selector(_watermarkAction), target: self, tag: 1)
  2076. subMenu.addItem(title: NSLocalizedString("Remove Watermark", comment: ""), action: #selector(_watermarkAction), target: self, tag: 2)
  2077. subMenu.addItem(title: NSLocalizedString("Batch Add Watermarks", comment: ""), action: #selector(_watermarkAction), target: self, tag: 3)
  2078. subMenu.addItem(title: NSLocalizedString("Batch Remove Watermarks", comment: ""), action: #selector(_watermarkAction), target: self, tag: 4)
  2079. subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_watermarkAction), target: self, tag: 5)
  2080. menuItem.submenu = subMenu
  2081. item?.menuFormRepresentation = menuItem
  2082. } else if identifier == KMToolbarToolCompressItemIdentifier {
  2083. item?.image = NSImage(named: "KMImageNameUXIconBatchOptimizeNor")
  2084. item?.target = self
  2085. item?.btnTag = KMToolbarType.compress.rawValue
  2086. item?.boxImagePosition = .imageLeft
  2087. item?.toolTip = NSLocalizedString("Reduce file size", comment: "")
  2088. item?.titleName = NSLocalizedString("Compress", comment: "")
  2089. item?.btnAction = #selector(compressMenuAction)
  2090. } else if identifier == KMToolbarToolSecureItemIdentifier {
  2091. item?.image = NSImage(named: "KMImageNameUXIconBatchSafeNor")
  2092. item?.target = self
  2093. // item?.toolTip = NSLocalizedString("Batch encrypting PDF documents", comment: "")
  2094. item?.titleName = NSLocalizedString("Security", comment: "")
  2095. item?.boxImagePosition = .imageExpandLeft
  2096. item?.needExpandAction = true
  2097. // item?.btnAction = #selector(secureMenuAction)
  2098. let menuItem = NSMenuItem.init(title: NSLocalizedString("Security", comment: ""), action: #selector(secureMenuAction), target: self)
  2099. let subMenu = NSMenu()
  2100. subMenu.addItem(title: NSLocalizedString("Set Passwords", comment: ""), action: #selector(_secureAction), target: self, tag: 1)
  2101. subMenu.addItem(title: NSLocalizedString("Remove Security", comment: ""), action: #selector(_secureAction), target: self, tag: 2)
  2102. menuItem.submenu = subMenu
  2103. item?.menuFormRepresentation = menuItem
  2104. }else if identifier == KMToolbarToolMergeItemIdentifier {
  2105. item?.image = NSImage(named: "KMImageNameUXIconBatchMergeNor")
  2106. item?.target = self
  2107. item?.btnTag = KMToolbarType.merge.rawValue
  2108. item?.toolTip = NSLocalizedString("Combine multiple documents into a new PDF, or borrow individual pages", comment: "")
  2109. item?.titleName = NSLocalizedString("Merge", comment: "")
  2110. item?.boxImagePosition = .imageLeft
  2111. item?.btnAction = #selector(mergeMenuItemAction)
  2112. }
  2113. }
  2114. }
  2115. extension KMToolbarViewController: NSMenuItemValidation {
  2116. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  2117. if menuItem.action == #selector(toggleCaseInsensitiveSearch) {
  2118. menuItem.state = KMDataManager.ud_integer(forKey: SKCaseInsensitiveSearchKey) == 1 ? .on : .off
  2119. } else if menuItem.action == #selector(formsAlignmentAction) {
  2120. if menuItem.tag < 6 {
  2121. if self.pdfView.activeAnnotations.count >= 2 {
  2122. return true
  2123. }
  2124. } else {
  2125. if self.pdfView.activeAnnotations.count >= 3 {
  2126. return true
  2127. }
  2128. }
  2129. return false
  2130. }
  2131. return true
  2132. }
  2133. }
  2134. extension KMToolbarViewController {
  2135. func isEnable(isEnable: Bool = true) {
  2136. for item in toolbarItems {
  2137. let itemView: KMToolbarMainItemView = item.value as? KMToolbarMainItemView ?? KMToolbarMainItemView()
  2138. itemView.unEnabled = !isEnable
  2139. itemView.isSelected = false
  2140. }
  2141. }
  2142. }
  2143. extension KMToolbarViewController {
  2144. func refreshSearchBarMenu() {
  2145. let words = UserDefaults.standard.array(forKey: "kmDocumentSearchWordArrays") as? [String] ?? []
  2146. let searchMenu = NSMenu()
  2147. for word in words {
  2148. var truncatedWord = word
  2149. if word.count > 15 {
  2150. truncatedWord = String(word.prefix(15)) + "..."
  2151. }
  2152. let item = searchMenu.addItem(withTitle: truncatedWord, action: #selector(searchPDFKeyWord(_:)), keyEquivalent: "")
  2153. item.representedObject = word
  2154. }
  2155. let attributes: [NSAttributedString.Key: Any] = [.font: NSFont(name: "Helvetica", size: 12.0)!]
  2156. if !words.isEmpty {
  2157. let attributedString = NSAttributedString(string: NSLocalizedString("Search History", comment: ""), attributes: attributes)
  2158. let item = NSMenuItem()
  2159. item.attributedTitle = attributedString
  2160. searchMenu.insertItem(item, at: 0)
  2161. searchMenu.addItem(NSMenuItem.separator())
  2162. let attributedString1 = NSAttributedString(string: NSLocalizedString("Clear Search History", comment: ""), attributes: attributes)
  2163. let item1 = NSMenuItem()
  2164. item1.attributedTitle = attributedString1
  2165. item1.action = #selector(clearSearchWordHistory(_:))
  2166. item1.target = self
  2167. searchMenu.addItem(item1)
  2168. searchMenu.insertItem(NSMenuItem.separator(), at: 0)
  2169. }
  2170. let attributedString2 = NSAttributedString(string: NSLocalizedString("Ignore Case", comment: ""), attributes: attributes)
  2171. let ignoreItem = NSMenuItem()
  2172. ignoreItem.attributedTitle = attributedString2
  2173. ignoreItem.action = #selector(toggleCaseInsensitiveSearch)
  2174. ignoreItem.target = self
  2175. searchMenu.insertItem(ignoreItem, at: 0)
  2176. (self.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = searchMenu
  2177. }
  2178. @objc func toggleCaseInsensitiveSearch(_ sender: NSMenuItem) {
  2179. var value = KMDataManager.ud_integer(forKey: SKCaseInsensitiveSearchKey)
  2180. KMDataManager.ud_set(value == 0 ? 1 : 0, forKey: SKCaseInsensitiveSearchKey)
  2181. // let caseInsensitive = UserDefaults.standard.bool(forKey: "SKCaseInsensitiveFindKey")
  2182. // UserDefaults.standard.set(!caseInsensitive, forKey: "SKCaseInsensitiveFindKey")
  2183. self.searchPDFKey(self.searchField.stringValue)
  2184. }
  2185. @objc func searchPDFKeyWord(_ item: NSMenuItem) {
  2186. guard let word = item.representedObject as? String else {
  2187. return
  2188. }
  2189. self.searchPDFKey(word)
  2190. }
  2191. func searchPDFKey(_ string: String) {
  2192. self.searchField.stringValue = string
  2193. self.delegate?.toolbarViewController?(self, searchAction: string, forward: true)
  2194. let word = string
  2195. var words = UserDefaults.standard.array(forKey: "kmDocumentSearchWordArrays") as? [String] ?? []
  2196. var mutableWords = words
  2197. if let index = mutableWords.firstIndex(of: word) {
  2198. mutableWords.remove(at: index)
  2199. }
  2200. mutableWords.insert(word, at: 0)
  2201. if mutableWords.count > 10 {
  2202. mutableWords.removeLast()
  2203. }
  2204. UserDefaults.standard.set(mutableWords, forKey: "kmDocumentSearchWordArrays")
  2205. UserDefaults.standard.synchronize()
  2206. refreshSearchBarMenu()
  2207. }
  2208. @objc func clearSearchWordHistory(_ sender: Any) {
  2209. UserDefaults.standard.removeObject(forKey: "kmDocumentSearchWordArrays")
  2210. UserDefaults.standard.synchronize()
  2211. refreshSearchBarMenu()
  2212. }
  2213. }