KMToolbarViewController.swift 155 KB

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