KMToolbarViewController.swift 166 KB

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