KMToolbarViewController.swift 144 KB

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