KMToolbarViewController.swift 134 KB

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