KMToolbarViewController.swift 129 KB

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