KMToolbarViewController.swift 129 KB

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