KMToolbarViewController.swift 154 KB

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