1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326 |
- //
- // KMToolbarViewController.swift
- // PDF Reader Pro
- //
- // Created by lxy on 2022/12/2.
- //
- import Cocoa
- @objc enum KMToolbarViewType : Int {
- case None
- case Main
- case Annatiton
- case Page
- case Conversion
- case ScanOCR
- case editPDF
- case Form
- case FillSign
- case Tool
- case redact
- case Move
- case Magnify
- case Select
- case SelectZoom
- case LeftPanel
- case RightPanel
- case viewSetting
- case AITools
-
- func isToolMode() -> Bool {
- return (self == .Move || self == .Magnify || self == .Select || self == .SelectZoom)
- }
-
- func itemIdentifier() -> String {
- if (self == .Annatiton) {
- return KMDocumentAnnotationToolbarItemIdentifier
- } else if (self == .Page) {
- return KMDocumentPageToolbarItemIdentifier
- } else if (self == .Conversion) {
- return KMDocumentConversonToolbarItemIdentifier
- } else if (self == .ScanOCR) {
- return KMDocumentScanOCRToolbarItemIdentifier
- } else if (self == .editPDF) {
- return KMDocumentEditToolbarItemIdentifier
- } else if (self == .Form) {
- return KMDocumentFormToolbarItemIdentifier
- } else if (self == .FillSign) {
- return KMDocumentFillSginToolbarItemIdentifier
- } else if (self == .Tool) {
- return KMDocumentToolToolbarItemIdentifier
- } else if (self == .Move) {
- return KMToolbarMoveToolModeItemIdentifier
- } else if (self == .Magnify) {
- return KMToolbarMagnifyToolModeItemIdentifier
- } else if (self == .Select) {
- return KMToolbarSelectToolModeItemIdentifier
- } else if (self == .SelectZoom) {
- return KMToolbarZoomToSelectionItemIdentifier
- } else if (self == .LeftPanel) {
- return KMLeftControlToolbarItemIdentifier
- } else if (self == .RightPanel) {
- return KMRightControlToolbarItemIdentifier
- } else if (self == .AITools) {
- return KMDocumentAIToolsToolbarItemIdentifier
- }
- return ""
- }
- }
- @objc enum KMToolbarType: Int {
- /// conversion
- case word = 3000
- case excel = 3001
- case ppt = 3002
- case rtf = 3003
- case csv = 3004
- case html = 3005
- case conversion_text = 3006
- case conversion_image = 3007
-
- /// tool
- case compress = 8000
- case merge = 8001
- case fileCompare = 8002
- case secure = 8003
- case redact = 8004
- case watermark = 8005
- case background = 8006
- case headerAndFooter = 8007
- case bates = 8008
- case crop = 8009
- case comparison = 8010
- case aiTools = 8011
- }
- @objc protocol KMToolbarViewControllerDelegate {
- @objc optional func changeAnnotationModeAction(item:KMToolbarClickButton)
- @objc optional func showPDFLayoutModeAction(show:Bool)
- @objc optional func changePDFViewZoomInAction()
- @objc optional func changePDFViewZoomOutAction()
- @objc optional func changePDFViewGotoNextPageAction()
- @objc optional func changePDFViewGoToPreviousPageAction()
- @objc optional func changePDFViewGotoBackAction()
- @objc optional func changePDFViewGoToForwardAction()
- @objc optional func aiTranslationPDFFileAction()
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareAction toolbarItem: KMToolbarItemView)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareOriginalPDF item:NSMenuItem)
- @objc optional func toolbarViewController(_ viewController: KMToolbarViewController, clickMode toolMode: KMToolbarViewType, toolbar toolbarItem: KMToolbarItemView, _ pages: [Int])
- @objc optional func toolbarViewController(_ viewController: KMToolbarViewController, clickChaildToolType: KMToolbarType, toolbar toolbarItem: KMToolbarItemView)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
-
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String, forward: Bool)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
- }
- class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
- var toolbar : KMToolbarView?
- var toolbarType : KMToolbarViewType = KMToolbarViewType.None
- var toolbarItems : [String : Any] = [:]
- @IBOutlet weak var mainWindowController : MainWindowController!
- open weak var delegate: KMToolbarViewControllerDelegate?
- @IBOutlet var zoomButton: NSPopUpButton!
- @IBOutlet var zoomView: NSView!
- @IBOutlet weak var zoomTextField: NSTextField!
-
- var searchField: NSSearchField = NSSearchField()
- var pdfView : CPDFListView = CPDFListView()
- var shareButton = KMToolbarClickButton()
- private var bottomLine = NSView()
-
- // 是否显示所有注释
- var isShowAllAnnotations = true
- var ignoreCurrentAnnotationTypeChange = false
- private var _currentItemView: KMToolbarItemView?
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.zoomTextField.delegate = self
- for item in self.zoomButton.itemArray {
- let string = item.title
- item.title = NSLocalizedString(string, comment: "")
- }
-
- NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewAnnotationTypeChangeNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewToolModeChangeNotification"), object: nil)
- }
-
- override func loadView() {
- super.loadView()
-
- self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
- self.toolbar?.frame = self.view.bounds
- self.toolbar?.autoresizingMask = [.width,.height]
- self.toolbar?.delegate = self
- self.view.addSubview(self.toolbar!)
-
- self.view.addSubview(self.bottomLine)
- self.bottomLine.frame = NSMakeRect(0, 0, NSWidth(self.view.bounds), 1)
- self.bottomLine.autoresizingMask = [.width]
- self.bottomLine.wantsLayer = true
- self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#0000001A").cgColor
- }
-
- func updateType(newType:KMToolbarViewType) {
- if newType != toolbarType {
- toolbarType = newType
- if self.toolbar != nil && self.toolbar?.superview != nil {
- self.toolbar?.removeFromSuperview()
- }
- self.toolbar = KMToolbarView.init(identifier: "KMToolbar_New")
- self.toolbar?.frame = self.view.bounds
- self.toolbar?.autoresizingMask = [.width,.height]
- self.toolbar?.delegate = self
- self.view.addSubview(self.toolbar!)
- }
- }
-
- func reloadateToolbar() -> Void {
- self.toolbar?.reloadData()
- }
-
- func resetToolbar() -> Void {
- for item in self.toolbar?.items ?? [] {
- item.isSelected = false
- }
- }
-
- // MARK: Action
-
- @IBAction func changeAnnotationMode(item: KMToolbarClickButton) {
- self.delegate?.changeAnnotationModeAction?(item: item)
- if item.isKind(of: KMToolbarClickButton.self) {
- self._itemSetPromptFlag(item: item.clickObject as? KMToolbarItemView)
- } else {
-
- }
- }
-
- @IBAction func leftControllButtonAction(item: KMToolbarClickButton) {
- let tag = KMToolbarViewType(rawValue: item.tag) ?? .None
- if tag == .editPDF {
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- KMPreference.shared.openDocumentType = .newWindow
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- return
- }
- if !self.pdfView.document!.allowsPrinting || !self.pdfView.document!.allowsCopying {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
- alert.runModal()
- return
- }
- Task { @MainActor in
- self.delegate?.toolbarViewController?(self, clickMode: tag, toolbar: item.clickObject as! KMToolbarItemView, [])
- }
- } else {
- self.delegate?.toolbarViewController?(self, clickMode: tag, toolbar: item.clickObject as! KMToolbarItemView, [])
- }
- self._itemSetPromptFlag(item: item.clickObject as? KMToolbarItemView)
- }
-
- @objc private func _itemAction(_ item: KMToolbarClickButton) {
- if item.clickObject?.itemIdentifier == KMAnnotationImageToolbarItemIdentifier || item.clickObject?.itemIdentifier == KMAnnotationTableToolbarItemIdentifier {
- self.pdfView.toolMode = .textToolMode
- self.pdfView.annotationType = .unkown
- }
- if let data = item.clickObject as? KMToolbarItemView {
- if data.itemIdentifier == KMToolbarComparisonItemIdentifier {
- self._currentItemView = data
- if let subMenu = data.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: item.frame.origin, in: item.superview)
- }
- return
- }
- }
- if let itemView = item.clickObject as? KMToolbarItemView {
- if itemView.itemIdentifier == KMDocumentRedactToolbarItemIdentifier {
- self.delegate?.toolbarViewController?(self, clickMode: .redact, toolbar: itemView, [])
- } else {
- self.delegate?.toolbarViewController?(self, itemDidClick: itemView)
- }
- self._itemSetPromptFlag(item: itemView)
- }
- }
-
- @objc private func OCRbtnAction1(_ item: KMToolbarClickButton) {
- FMTrackEventManager.defaultManager.trackEvent(event: "Tbr", withProperties: ["Tbr_Btn": "Btn_Tbr_OCR"])
- self._itemAction(item)
- }
- @objc private func OCRbtnAction2(_ item: KMToolbarClickButton) {
- FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Converter", withProperties: ["SubTbr_Btn": "Btn_SubTbr_Converter_OCR"])
- self._itemAction(item)
- }
-
- @objc private func _menuItemAction(_ item: NSMenuItem) {
- guard let itemId = item.representedObject as? String else {
- NSSound.beep()
- return
- }
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self.delegate?.toolbarViewController?(self, menuItemDidClick: item_, index: 0, info: nil)
- self._itemSetPromptFlag(item: item_)
- }
-
- @objc private func _comparisonAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarComparisonItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarComparisonItemIdentifier)
- }
-
- @IBAction func showPDFLayoutMode(sender: KMToolbarClickButton) {
- if let item = sender.clickObject as? KMToolbarItemView {
- item.isSelected = !item.isSelected
- self.delegate?.showPDFLayoutModeAction?(show: true)
- self._itemSetPromptFlag(item: item)
- }
- }
-
- @objc func cropMenuAction(item: KMToolbarItemView) {
- self.delegate?.toolbarViewController?(self, clickChaildToolType: .crop, toolbar: item)
- }
-
- @objc private func _cropAction(_ sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarCropIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarCropIdentifier)
- }
-
- @objc func batesMenuAction(sender: KMToolbarClickButton) {
- self._currentItemView = sender.clickObject as? KMToolbarItemView
- if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- }
- }
- @objc private func _batesAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolBatesItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
-
- @objc private func _AIAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarAIItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
-
- @objc func headerfooterMenuAction(sender: KMToolbarClickButton) {
- self._currentItemView = sender.clickObject as? KMToolbarItemView
- if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- }
- }
- @objc private func _headerfooterAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolHeaderFooterItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
- }
-
- @objc func backgroundMenuAction(sender: KMToolbarClickButton) {
- self._currentItemView = sender.clickObject as? KMToolbarItemView
- if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- }
- }
- @objc private func _backgroundAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolBackgroundItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
- }
-
- @objc func watermarkMenuAction(sender: KMToolbarClickButton) {
- self._currentItemView = sender.clickObject as? KMToolbarItemView
- if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- }
- }
- @objc private func _watermarkAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolWatermarkItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
- }
-
- @objc func redactMenuAction(sender: KMToolbarClickButton) {
- self.delegate?.toolbarViewController?(self, clickChaildToolType: .redact, toolbar: sender.clickObject as! KMToolbarItemView)
- self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
- }
-
- @objc func compressMenuAction(sender: KMToolbarClickButton) {
- self.delegate?.toolbarViewController?(self, clickChaildToolType: .compress, toolbar: sender.clickObject as! KMToolbarItemView)
- self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
- }
-
- @objc func secureMenuAction(sender: KMToolbarClickButton) {
- self.delegate?.toolbarViewController?(self, clickChaildToolType: .secure, toolbar: sender.clickObject as! KMToolbarItemView)
- self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
- }
- @objc private func _secureAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolSecureItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarToolSecureItemIdentifier)
- }
-
- @objc func conversionMenuItemAction(sender: KMToolbarClickButton) {
- if let item: KMToolbarItemView = sender.clickObject as? KMToolbarItemView {
- var type: KMToolbarType = .word
- if (item.btnTag == KMToolbarType.excel.rawValue) {
- type = .excel
- } else if (item.btnTag == KMToolbarType.ppt.rawValue) {
- type = .ppt
- } else if (item.btnTag == KMToolbarType.rtf.rawValue) {
- type = .rtf
- } else if (item.btnTag == KMToolbarType.csv.rawValue) {
- type = .csv
- } else if (item.btnTag == KMToolbarType.html.rawValue) {
- type = .html
- } else if (item.btnTag == KMToolbarType.conversion_text.rawValue) {
- type = .conversion_text
- } else if (item.btnTag == KMToolbarType.conversion_image.rawValue) {
- type = .conversion_image
- }
- self.delegate?.toolbarViewController?(self, clickChaildToolType: type, toolbar: item)
- self._itemSetPromptFlag(item: item)
- }
- }
-
- @objc private func _pdfToImageAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarConversionImageItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarConversionImageItemIdentifier)
- }
-
- @objc private func _exportImageAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarConversionExportImageItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarConversionExportImageItemIdentifier)
- }
-
- @objc private func _newPDFAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarConversionCreatePDFItemIdentifier), index: sender.tag, info: nil)
- }
- self._itemSetPromptFlag(itemIdentifier: KMToolbarConversionCreatePDFItemIdentifier)
- }
-
- @IBAction func zoomModelSelectButtonAction(_ sender: NSPopUpButton) {
- self.delegate?.toolbarViewController?(self, zoomModel: sender.selectedTag())
- for item in sender.itemArray {
- item.state = .off
- }
- sender.selectedItem?.state = .on
- }
-
- @IBAction func zoomPDFViewButtonAction(sender:KMToolbarClickButton) {
- if sender.tag == 0 {
- self.delegate?.changePDFViewZoomOutAction?()
- } else if sender.tag == 1 {
- self.delegate?.changePDFViewZoomInAction?()
- } else if sender.tag == 2 {
- self.delegate?.changePDFViewGotoBackAction?()
- } else if sender.tag == 3 {
- self.delegate?.changePDFViewGoToForwardAction?()
- }
- }
-
- @IBAction func aiTranslationButtonAction(sender:KMToolbarClickButton) {
- self.delegate?.aiTranslationPDFFileAction?()
- }
-
- @IBAction func shareButtonAction(sender:KMToolbarClickButton) {
- self.shareButton = sender
- let menu = NSMenu()
- menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
- menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
- menu.addItem(withTitle: NSLocalizedString("Original PDF", comment: ""), action: #selector(shareViaWithOriginalPDF), target: self)
- menu.popUp(positioning: nil, at: NSPoint(x: sender.frame.origin.x, y: sender.frame.origin.y-10), in: sender.superview)
-
- self.delegate?.toolbarViewController?(self, shareAction: sender.clickObject as! KMToolbarItemView)
- }
-
- @IBAction func shareViaWithDocument(sender:NSMenuItem) {
- self.delegate?.toolbarViewController?(self, shareDocument: sender)
- }
-
- @IBAction func shareViaWithFlatten(sender:NSMenuItem) {
- self.delegate?.toolbarViewController?(self, shareFlatten: sender)
- }
-
- @IBAction func shareViaWithOriginalPDF(sender:NSMenuItem) {
- self.delegate?.toolbarViewController?(self, shareOriginalPDF: sender)
- }
-
- @objc func mergeMenuItemAction(sender: KMToolbarClickButton) {
- self.delegate?.toolbarViewController?(self, clickChaildToolType: .merge, toolbar: sender.clickObject as! KMToolbarItemView)
- }
-
- @IBAction func scanOCRModelSelect(sender:KMToolbarClickButton) {
- self.delegate?.toolbarViewController?(self, scanOCRModel: sender.tag)
- }
-
- // Form 对齐
- @IBAction func formsAlignmentAction(sender:KMToolbarClickButton) {
- if sender.tag == 0 {
- self.pdfView.formsAnnotationAlign(.left)
- } else if sender.tag == 1 {
- self.pdfView.formsAnnotationAlign(.vertical)
- } else if sender.tag == 2 {
- self.pdfView.formsAnnotationAlign(.right)
- } else if sender.tag == 3 {
- self.pdfView.formsAnnotationAlign(.top)
- } else if sender.tag == 4 {
- self.pdfView.formsAnnotationAlign(.horizontally)
- } else if sender.tag == 5 {
- self.pdfView.formsAnnotationAlign(.bottom)
- } else if sender.tag == 6 {
- self.pdfView.formsAnnotationAlign(.disHorizontally)
- } else if sender.tag == 7 {
- self.pdfView.formsAnnotationAlign(.disVertical)
- }
- }
-
- @objc private func _alignmentAction(sender: NSMenuItem) {
- if let data = self._currentItemView {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
- } else {
- self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolFormAlignIdentifier), index: sender.tag, info: nil)
- }
- }
-
- // Form 更多操作
- @IBAction func formsMoreOperationAction(sender:KMToolbarClickButton) {
-
- }
-
- func toolbarItemFindItemIdentifiers(value : String) -> KMToolbarItemView{
- for item in self.toolbarItems {
- if item.key == value {
- return item.value as! KMToolbarItemView
- }
- }
- return KMToolbarItemView()
- }
-
- func controlTextDidEndEditing(_ obj: Notification) {
- let textField = obj.object as? NSTextField
- if textField == self.zoomTextField {
- self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
- }
- }
-
- func controlTextDidChange(_ obj: Notification) {
-
- }
-
- func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
- switch commandSelector {
- case #selector(NSResponder.insertNewline(_:)):
- if let inputView = control as? NSTextField {
- // //当当前TextField按下enter
- if inputView == zoomTextField {
- KMPrint("按下 enter")
- self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
- } else if let _ = control as? NSSearchField {
- self.searchPDFKey(control.stringValue)
- }
- }
- return true
- default:
- return false
- }
- }
-
- // MARK: - Private Methods
-
- private func _itemSetPromptFlag(item: KMToolbarItemView?) {
- if let item_ = item {
- if let identifier = item_.promptIdentifier {
- item?.isShowPrompt = false
- KMDataManager.ud_set(true, forKey: identifier)
- }
- }
- }
-
- private func _itemSetPromptFlag(itemIdentifier: String?) {
- let item = self.toolbarItemFindItemIdentifiers(value: itemIdentifier ?? "")
- self._itemSetPromptFlag(item: item)
- }
-
- override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
- super.interfaceThemeDidChanged(appearance)
-
- self.toolbar?.appearance = .init(named: appearance)
- self.bottomLine.wantsLayer = true
- if KMAppearance.isDarkMode() {
- self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#393B3E", alpha: 1).cgColor
- } else {
- self.bottomLine.layer?.backgroundColor = NSColor.km_init(hex: "#0000001A").cgColor
- }
- }
- }
- // MARK: - Public Methods
- extension KMToolbarViewController {
- func itemAction(_ item: KMToolbarItemView) {
- self._itemAction(item.clickButton)
- }
- }
- extension KMToolbarViewController : KMToolbarViewDelegate,NSToolbarItemValidation {
- func toolbarLeftDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- if toolbarType == .Main {
- return [KMLeftControlToolbarItemIdentifier,
- KMNewToolbarSpaceItemIdentifier, KMDocumentZoomViewToolbarItemIdentifier,
- KMDocumentPreviousPageToolbarItemIdentifier, KMDocumentHomeToolbarItemIdentifier]
- }
- return []
- }
-
- func toolbarRightDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- if toolbarType == .Main {
- return [KMDocumentViewDisplayToolbarItemIdentifier, KMDocumentShareToolbarItemIdentifier,
- KMDocumentSearchToolbarItemIdentifier, KMRightControlToolbarItemIdentifier]
- } else if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
- return [KMToolbarAnnotationSettingItemIdentifier]
- }
- return []
- }
-
- func toolbarAllowedItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
- return [KMNewToolbarSpaceItemIdentifier,
- KMToolbarPageEditInsetItemIdentifier, KMToolbarToolMergeItemIdentifier, KMToolbarPageEditSplitItemIdentifier,
- KMToolbarToolCompressItemIdentifier, KMToolbarToolSecureItemIdentifier, KMToolbarToolWatermarkItemIdentifier,
- KMToolbarToolBackgroundItemIdentifier, KMToolbarToolHeaderFooterItemIdentifier, KMToolbarToolBatesItemIdentifier,
- KMToolbarAIItemIdentifier,
- KMToolbarCropIdentifier,
- KMToolbarConversionWordItemIdentifier, KMToolbarConversionExcelItemIdentifier, KMToolbarConversionPPTItemIdentifier,
- KMToolbarConversionRTFItemIdentifier, KMToolbarConversionCSVItemIdentifier, KMToolbarConversionHTMLItemIdentifier,
- KMToolbarConversionTextItemIdentifier, KMToolbarConversionImageItemIdentifier,
-
- KMToolbarMoveToolModeItemIdentifier,
- KMToolbarMagnifyToolModeItemIdentifier,
- KMToolbarSelectToolModeItemIdentifier,
- KMToolbarZoomToSelectionItemIdentifier,
- KMNewToolbarSpaceItemIdentifier,
- KMToolbarDividerItemIdentifier,
- KMNewToolbarSpaceItemIdentifier,
- KMToolbarHighlightAnnotationItemIdentifier,
- KMToolbarUnderlineAnnotationItemIdentifier,
- KMToolbarStrikeOutAnnotationItemIdentifier,
- KMToolbarInkAnnotationItemIdentifier,
- KMToolbarFreeTextAnnotationItemIdentifier,
- KMToolbarAnchoredAnnotationItemIdentifier,
- KMToolbarSquareAnnotationItemIdentifier, KMToolbarCircleAnnotationItemIdentifier, KMToolbarArrowAnnotationItemIdentifier, KMToolbarLineAnnotationItemIdentifier,
- KMToolbarLinkAnnotationItemIdentifier,
- KMAnnotationStampToolbarItemIdentifier,
- KMToolbarSignSignatureAnnotationItemIdentifier,
- // KMToolbarDividerItemIdentifier,
- // KMToolbarShowToolbarItemIdentifier,
-
- KMToolbarToolRadioButtonItemIdentifier]
- }
- return []
- }
-
- func toolbarDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- switch toolbarType {
- case .None:
- return []
- case .Main:
- return [KMDocumentAnnotationToolbarItemIdentifier,
- KMDocumentPageToolbarItemIdentifier,
- KMDocumentToolToolbarItemIdentifier,
- KMDocumentConversonToolbarItemIdentifier,
- KMDocumentFormToolbarItemIdentifier,
- KMDocumentFillSginToolbarItemIdentifier,
- KMDocumentEditToolbarItemIdentifier,
- KMDocumentDigitalSignToolbarItemIdentifier,
- KMDocumentRedactToolbarItemIdentifier,
- KMDocumentScanOCRToolbarItemIdentifier,
- KMDocumentAIToolsToolbarItemIdentifier]
- case .Annatiton,.Magnify,.Move,.Select,.SelectZoom:
- let itemIdentifiers: [String]? = self.toolbar?.toolbarIdentifier != nil ? (UserDefaults.standard.object(forKey: self.toolbar?.toolbarIdentifier ?? "") as? [String]) : []
- if itemIdentifiers == nil || itemIdentifiers!.count <= 0 {
- return [KMToolbarMoveToolModeItemIdentifier,
- KMToolbarMagnifyToolModeItemIdentifier,
- KMToolbarSelectToolModeItemIdentifier,
- KMToolbarZoomToSelectionItemIdentifier,
- KMNewToolbarSpaceItemIdentifier,
- KMNewToolbarSpaceItemIdentifier,
- KMToolbarHighlightAnnotationItemIdentifier,
- KMToolbarUnderlineAnnotationItemIdentifier,
- KMToolbarStrikeOutAnnotationItemIdentifier,
- KMToolbarInkAnnotationItemIdentifier,
- KMToolbarFreeTextAnnotationItemIdentifier,
- KMToolbarAnchoredAnnotationItemIdentifier,
- KMToolbarSquareAnnotationItemIdentifier, KMToolbarCircleAnnotationItemIdentifier, KMToolbarArrowAnnotationItemIdentifier, KMToolbarLineAnnotationItemIdentifier,
- KMToolbarLinkAnnotationItemIdentifier,
- KMNewToolbarSpaceItemIdentifier, KMNewToolbarSpaceItemIdentifier,
- KMAnnotationStampToolbarItemIdentifier, KMAnnotationImageToolbarItemIdentifier,
- KMToolbarSignSignatureAnnotationItemIdentifier, KMAnnotationTableToolbarItemIdentifier]
- }
- return itemIdentifiers!
- case .editPDF:
- return [KMToolbarAddTextEditPDFItemIdentifier,
- KMToolbarAddImageEditPDFItemIdentifier]
- case .Page:
- return []
- case .Tool:
- return [KMToolbarToolCompressItemIdentifier, KMToolbarToolMergeItemIdentifier,
- KMToolbarToolSecureItemIdentifier, KMToolbarComparisonItemIdentifier,
- KMToolbarToolWatermarkItemIdentifier, KMToolbarToolBackgroundItemIdentifier,
- KMToolbarToolHeaderFooterItemIdentifier, KMToolbarToolBatesItemIdentifier]
- case .Form:
- return [KMToolbarToolTextFieldItemIdentifier,
- KMToolbarToolCheckBoxItemIdentifier,
- KMToolbarToolRadioButtonItemIdentifier,
- KMToolbarToolListBoxItemIdentifier,
- KMToolbarToolPullDownmenuItemIdentifier,
- KMToolbarToolButtonIdentifier,
- KMToolbarToolSignBoxIdentifier,
- KMToolbarDividerItemIdentifier,
- KMToolbarToolFormAlignIdentifier]
- case .FillSign:
- return [
- // KMToolbarToolTextIdentifier,
- KMToolbarToolHookItemIdentifier,
- KMToolbarToolForkItemIdentifier,
- KMToolbarToolRectangleIdentifier,
- KMToolbarToolLineItemIdentifier,
- KMToolbarToolDotItemIdentifier,
- KMToolbarToolDateIdentifier,
- KMToolbarToolProfileIdentifier,
- KMToolbarFillSignSignatureIdentifier]
- case .Conversion:
- return [KMToolbarConversionCreatePDFItemIdentifier,
- KMToolbarConversionWordItemIdentifier,
- KMToolbarConversionExcelItemIdentifier,
- KMToolbarConversionPPTItemIdentifier,
- KMToolbarConversionRTFItemIdentifier,
- KMToolbarConversionCSVItemIdentifier,
- KMToolbarConversionHTMLItemIdentifier,
- KMToolbarConversionTextItemIdentifier,
- KMToolbarConversionImageItemIdentifier,
- KMToolbarDividerItemIdentifier, KMToolbarConversionOCRIdentifier, KMToolbarConversionExportImageItemIdentifier]
- case .ScanOCR:
- return [KMToolbarToolEnhancedScanIdentifier,
- KMToolbarToolOCRTextIdentifier]
- case .viewSetting:
- return [KMToolbarViewSettingIdentifier, KMToolbarCropIdentifier,
- KMToolbarSnapshotIdentifier, KMToolbarTTSIdentifier]
- default:
- break
- }
- return []
- }
-
- func toolbar(_ toolbar: KMToolbarView, itemFor identifier: String) -> KMToolbarItemView {
- var item: KMToolbarItemView? = self.toolbarItems[identifier] as? KMToolbarItemView
- var create = false
- if let data = item {
- let pId = parentIdentifier(data.itemIdentifier ?? "")
- if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) && (pId != KMDocumentAnnotationToolbarItemIdentifier || data.itemIdentifier! == KMToolbarAnnotationSettingItemIdentifier) {
- create = true
- } else {
- if let toolbarId = self.toolbar?.toolbarIdentifier {
- let itemIdentifiers = (UserDefaults.standard.object(forKey: toolbarId) as? [String]) ?? []
- if itemIdentifiers.contains(identifier) && annotationToolIdentifiers.contains(identifier) == false {
- create = true
- }
- }
- }
- }
- if item == nil || create {
- item = KMToolbarItemView.init(itemIdentifier: identifier)
- if isMainToolItem(identifier) {
- item = KMToolbarMainItemView(itemIdentifier: identifier)
- }
- self.toolbarItems[identifier] = item
- if isMainToolItem(identifier) {
- self._setupMainItem(item)
- } else {
- if (annotationToolIdentifiers.contains(identifier)) {
- self._setupAnnotationItem(item)
- } else if editPDFItemIdentifiers.contains(identifier) {
- self._setupEditItem(item)
- } else if conversionToolIdentifiers.contains(identifier) {
- self._setupConvertItem(item)
- } else if fillSignToolIdentifiers.contains(identifier) {
- self._setupFillSignItem(item)
- } else if formToolIdentifiers.contains(identifier) {
- self._setupFormItem(item)
- } else if toolToolIdentifiers.contains(identifier) {
- self._setupToolItem(item)
- } else if KMViewDisplayIdentifiers.contains(identifier) {
- self._setupViewDisplayItem(item)
- } else if pageEditToolIdentifiers.contains(identifier) {
- if (identifier == KMToolbarPageEditPageRangeItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageRange)
- item?.target = self
- item?.btnTag = KMPageEditType.pageRange.rawValue
- // item?.toolTip = NSLocalizedString("pageRange", comment: "")
- item?.titleName = NSLocalizedString("Page Range", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- // item?.btnAction = #selector(pageRangeMenuAction)
- item?.needExpandAction = true
- } else if (identifier == KMToolbarPageEditRotateItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageRotate)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageRotate)
- item?.target = self
- item?.btnTag = KMPageEditType.rightRotate.rawValue
- item?.toolTip = NSLocalizedString("Rotate", comment: "")
- item?.titleName = NSLocalizedString("Rotate", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditLeftRotateItemIdentifier) {
- item?.image = NSImage(named: "KMImageNameMainToolPageLeftRotate")
- item?.alternateImage = NSImage(named: "KMImageNameMainToolPageLeftRotate")
- item?.target = self
- item?.btnTag = KMPageEditType.leftRotate.rawValue
- item?.toolTip = NSLocalizedString("Rotate Left", comment: "")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditRightRotateItemIdentifier) {
- item?.image = NSImage(named: "KMImageNameMainToolPageRightRotate")
- item?.alternateImage = NSImage(named: "KMImageNameMainToolPageRightRotate")
- item?.target = self
- item?.btnTag = KMPageEditType.rightRotate.rawValue
- item?.toolTip = NSLocalizedString("Rotate Right", comment: "")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditInsetItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageInsert)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageInsert)
- item?.target = self
- item?.btnTag = KMPageEditType.insert.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Inserting pages into an existing PDF", comment: "")
- item?.isPopToolTip = true
- item?.titleName = NSLocalizedString("Insert", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- } else if (identifier == KMToolbarPageEditExtractItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageExtract)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageExtract)
- item?.target = self
- item?.btnTag = KMPageEditType.extract.rawValue
- // item?.toolTip = NSLocalizedString("Exctract selected pages", comment: "")
- item?.titleName = NSLocalizedString("Extract", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- // item?.btnAction = #selector(extractMenuAction)
- item?.needExpandAction = true
- } else if (identifier == KMToolbarPageEditReplaceItemIdentifier) {
- item?.image = NSImage(named: KMImageNameToolbarReplace)
- item?.alternateImage = NSImage(named: KMImageNameToolbarReplace)
- item?.target = self
- item?.btnTag = KMPageEditType.replace.rawValue
- item?.toolTip = NSLocalizedString("Replace", comment: "")
- item?.titleName = NSLocalizedString("Replace", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditSplitItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageSplit)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageSplit)
- item?.target = self
- item?.btnTag = KMPageEditType.split.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Split and save selected PDF pages as a new separate document", comment: "")
- item?.isPopToolTip = true
- item?.titleName = NSLocalizedString("Split", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- } else if (identifier == KMToolbarPageEditReverseItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageReverse)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageReverse)
- item?.target = self
- item?.btnTag = KMPageEditType.reverse.rawValue
- item?.toolTip = NSLocalizedString("Reverse", comment: "")
- item?.titleName = NSLocalizedString("Reverse", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditCopyItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageCopy)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageCopy)
- item?.target = self
- item?.btnTag = KMPageEditType.delete.rawValue
- item?.toolTip = NSLocalizedString("Copy", comment: "")
- item?.titleName = NSLocalizedString("Copy", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditPasteItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPagePaste)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPagePaste)
- item?.target = self
- item?.btnTag = KMPageEditType.delete.rawValue
- item?.toolTip = NSLocalizedString("Paste", comment: "")
- item?.titleName = NSLocalizedString("Paste", comment: "")
- item?.boxImagePosition = .imageLeft
- } else if (identifier == KMToolbarPageEditDeleteItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageDelete)
- item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageDelete)
- item?.target = self
- item?.btnTag = KMPageEditType.delete.rawValue
- item?.toolTip = NSLocalizedString("Delete", comment: "")
- item?.titleName = NSLocalizedString("Delete", comment: "")
- item?.boxImagePosition = .imageLeft
- }
-
- return item!
- }
- }
- }
- return item!
- }
-
- func validateToolbarItem(_ item: NSToolbarItem) -> Bool {
- return true
- }
-
- @objc func listViewAnnotationTypeChangeNotification(sender: Notification?) {
- // if let notiName = sender?.name, notiName == NSNotification.Name.CPDFListViewAnnotationTypeChange, self.ignoreCurrentAnnotationTypeChange {
-
- // }
- if (self.ignoreCurrentAnnotationTypeChange) {
- // 忽略后重置 这个属性是基于单次添加,所以使用后会重置
- // self.ignoreCurrentAnnotationTypeChange = false
- return
- }
-
- let annotationType : CAnnotationType = pdfView.annotationType
- if annotationType == .square || annotationType == .circle || annotationType == .arrow || annotationType == .line{
- UserDefaults.standard.set(pdfView.annotationType.rawValue, forKey: KMToolBarToolPDFShapeStyle)
- UserDefaults.standard.synchronize()
- }
- for item in self.toolbar?.items ?? [] {
- if self.toolbarType == .Annatiton || self.toolbarType == .Move || self.toolbarType == .Magnify ||
- self.toolbarType == .Select || self.toolbarType == .SelectZoom {
- item.isSelected = false
- if item.itemIdentifier == KMDocumentAnnotationToolbarItemIdentifier {
- item.isSelected = true
- } else if item.itemIdentifier == KMToolbarHighlightAnnotationItemIdentifier {
- if annotationType == .highlight {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarUnderlineAnnotationItemIdentifier {
- if annotationType == .underline {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarStrikeOutAnnotationItemIdentifier {
- if annotationType == .strikeOut {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarInkAnnotationItemIdentifier {
- if annotationType == .ink || annotationType == .eraser {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarFreeTextAnnotationItemIdentifier {
- if annotationType == .freeText {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarAnchoredAnnotationItemIdentifier {
- if annotationType == .anchored {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarSquareAnnotationItemIdentifier {
- if annotationType == .square {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarCircleAnnotationItemIdentifier {
- if annotationType == .circle {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarArrowAnnotationItemIdentifier {
- if annotationType == .arrow {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarLineAnnotationItemIdentifier {
- if annotationType == .line {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarLinkAnnotationItemIdentifier {
- if annotationType == .link {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMAnnotationStampToolbarItemIdentifier {
- if annotationType == .stamp {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarSignSignatureAnnotationItemIdentifier {
- if annotationType == .signSignature {
- item.isSelected = true
- }
- } else if pdfView.toolMode == .moveToolMode {
- if item.itemIdentifier == KMToolbarMoveToolModeItemIdentifier {
- item.isSelected = true
- }
- } else if pdfView.toolMode == .magnifyToolMode {
- if item.itemIdentifier == KMToolbarMagnifyToolModeItemIdentifier {
- item.isSelected = true
- }
- } else if pdfView.toolMode == .selectToolMode {
- if item.itemIdentifier == KMToolbarSelectToolModeItemIdentifier {
- item.isSelected = true
- }
- } else if pdfView.toolMode == .selectZoomToolMode {
- if item.itemIdentifier == KMToolbarZoomToSelectionItemIdentifier {
- item.isSelected = true
- }
- }
-
- if (item.itemIdentifier == KMToolbarShowToolbarItemIdentifier) {
- item.isSelected = !self.isShowAllAnnotations
- }
- } else if self.toolbarType == .FillSign {
- item.isSelected = false
- if pdfView.toolMode == .selfSignMode {
- if item.itemIdentifier == KMToolbarToolHookItemIdentifier {
- if annotationType == .signTure {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolForkItemIdentifier {
- if annotationType == .signFalse {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolLineItemIdentifier {
- if annotationType == .signLine {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolDotItemIdentifier {
- if annotationType == .signDot {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolRectangleIdentifier {
- if annotationType == .signCircle {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolDateIdentifier {
- if annotationType == .signDate {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolTextIdentifier {
- if annotationType == .signText {
- item.isSelected = true
- }
- } else if (item.itemIdentifier == KMToolbarFillSignSignatureIdentifier) {
- if (annotationType == .signSignature) {
- item.isSelected = true
- }
- }
- }
- } else if self.toolbarType == .Form {
- item.isSelected = false
- if pdfView.toolMode == .formToolMode {
- if item.itemIdentifier == KMToolbarToolTextFieldItemIdentifier {
- if annotationType == .textField {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolCheckBoxItemIdentifier {
- if annotationType == .checkBox {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolRadioButtonItemIdentifier {
- if annotationType == .radioButton {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolListBoxItemIdentifier {
- if annotationType == .listMenu {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolPullDownmenuItemIdentifier {
- if annotationType == .comboBox {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolButtonIdentifier {
- if annotationType == .actionButton {
- item.isSelected = true
- }
- } else if item.itemIdentifier == KMToolbarToolSignBoxIdentifier {
- if annotationType == .signature {
- item.isSelected = true
- }
- }
- }
- }
- }
- }
- }
- extension KMToolbarViewController: NSSearchFieldDelegate {
- }
- extension KMToolbarViewController {
- private func _setupMainItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMLeftControlToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
- item?.titleName = NSLocalizedString("Panel", comment: "")
- item?.target = self
- item?.toolTip = NSLocalizedString("View Settings", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMDocumentZoomToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.target = self
- item?.btnTag = 1
- item?.toolTip = NSLocalizedString("Zoom In", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.btnAction = #selector(zoomPDFViewButtonAction)
- } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.target = self
- item?.btnTag = 0
- item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.btnAction = #selector(zoomPDFViewButtonAction)
- } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
- item?.titleName = NSLocalizedString("Zoom", comment: "")
- item?.target = self
-
- let view = KMToolbarZoomItemView(zoomView: self.zoomView)
- view.callback = { [weak self] idx, _ in
- if idx == 2 {
- self?.delegate?.changePDFViewZoomInAction?()
- } else if idx == 1 {
- self?.delegate?.changePDFViewZoomOutAction?()
- }
- }
- item?.customizeView = view
- } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
- item?.titleName = NSLocalizedString("Next", comment: "")
- item?.target = self
- item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Zoom", comment: "")
- item?.target = self
-
- let view = KMToolbarPreviousNextItemView()
- view.callback = { [weak self] idx, _ in
- if idx == 1 {
- self?.delegate?.changePDFViewGoToPreviousPageAction?()
- } else if idx == 2 {
- self?.delegate?.changePDFViewGotoNextPageAction?()
- }
- }
- item?.customizeView = view
- } else if identifier == KMDocumentHomeToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
- item?.titleName = NSLocalizedString("Home", comment: "")
- item?.target = self
- item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Tools", comment: "")
- item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
- item?.target = self
- item?.toolTip = String(format: "%@: %@, %@, %@, %@", KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
- item?.btnTag = KMToolbarViewType.Annatiton.rawValue
- item?.btnAction = #selector(leftControllButtonAction)
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- } else if identifier == KMDocumentPageToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Page Edit", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
- item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
- item?.btnTag = KMToolbarViewType.Page.rawValue
- item?.btnAction = #selector(leftControllButtonAction)
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- } else if identifier == KMDocumentConversonToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Converter", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
- item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
- item?.btnTag = KMToolbarViewType.Conversion.rawValue
- item?.btnAction = #selector(leftControllButtonAction)
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.promptIdentifier = identifier
-
- } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("OCR", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
- item?.boxImagePosition = .imageAbove
- item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(OCRbtnAction1)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolEnhancedScanIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
- item?.target = self
- item?.btnTag = 0
- item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
- item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(scanOCRModelSelect)
- } else if identifier == KMToolbarToolOCRTextIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolOCRText")
- item?.target = self
- item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
- item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(scanOCRModelSelect)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR Text Recognition", comment: ""), action: #selector(scanOCRModelSelect), target: self)
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentEditToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Edit PDF", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
- item?.boxImagePosition = .imageAbove
- item?.btnTag = KMToolbarViewType.editPDF.rawValue
- item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(leftControllButtonAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Edit PDF", comment: ""), action: #selector(leftControllButtonAction), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentFormToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Forms", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
- item?.boxImagePosition = .imageAbove
- item?.btnTag = KMToolbarViewType.Form.rawValue
- item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(leftControllButtonAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Forms", comment: ""), action: #selector(leftControllButtonAction), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentFillSginToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
- item?.boxImagePosition = .imageAbove
- item?.btnTag = KMToolbarViewType.FillSign.rawValue
- item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(leftControllButtonAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Fill & Sign", comment: ""), action: #selector(leftControllButtonAction), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentToolToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Editor", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
- item?.boxImagePosition = .imageAbove
- item?.btnTag = KMToolbarViewType.Tool.rawValue
- item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(leftControllButtonAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMDocumentRedactToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Redact Text", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
- item?.boxImagePosition = .imageAbove
- item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(_itemAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
- item?.image = NSImage(named: "ic_function_other_AITranslation")
- item?.titleName = "AI Translation"
- item?.target = self
- item?.toolTip = NSLocalizedString("AI Translation", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(aiTranslationButtonAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMDocumentPrintToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
- item?.titleName = "Print"
- item?.target = self
- item?.toolTip = NSLocalizedString("Print", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
- item?.titleName = NSLocalizedString("Page Display", comment: "")
- item?.target = self
- item?.toolTip = NSLocalizedString("Page Display", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(_itemAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Page Display", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconAINor")
- item?.titleName = NSLocalizedString("AI Tools", comment: "")
- item?.target = self
- item?.toolTip = NSLocalizedString("AI Tools", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(_itemAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("AI Tools", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentShareToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
- item?.titleName = NSLocalizedString("Share", comment: "")
- item?.target = self
- // item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(shareButtonAction)
-
- let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: nil, target: self)
- let menu = NSMenu()
- _ = menu.addItem(withTitle: NSLocalizedString("Document", comment: ""), action: #selector(shareViaWithDocument), target: self)
- _ = menu.addItem(withTitle: NSLocalizedString("Flattened Copy", comment: ""), action: #selector(shareViaWithFlatten), target: self)
- _ = menu.addItem(withTitle: NSLocalizedString("Original PDF", comment: ""), action: #selector(shareViaWithOriginalPDF), target: self)
- menuItem.submenu = menu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentSearchToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Search", comment: "")
- item?.target = self
- let view = NSView()
- view.frame = NSMakeRect(0, 0, 150, 40)
- let boxView = NSView()
- boxView.frame = NSMakeRect(0, 16, 150, 22)
- view.addSubview(boxView)
- let searchView = NSSearchField()
- searchView.frame = NSMakeRect(0, 0, 150, 22)
- searchView.placeholderString = NSLocalizedString("Search", comment: "")
- searchView.sendsWholeSearchString = true
- searchView.sendsSearchStringImmediately = true
- searchView.drawsBackground = false
- searchView.delegate = self
- self.searchField = searchView
-
- self.refreshSearchBarMenu()
-
- boxView.addSubview(searchView)
- let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
- view.addSubview(titleLabel)
- titleLabel.frame = NSMakeRect(0, 0, 130, 14)
- titleLabel.alignment = .center
- titleLabel.textColor = KMAppearance.subtitleColor()
- titleLabel.font = KMToolbarMainItemView.textFont
-
- item?.customizeView = view
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Search", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMRightControlToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
- item?.titleName = NSLocalizedString("Properties", comment: "")
- item?.target = self
- item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
- item?.boxImagePosition = .imageAbove
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(_itemAction)
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Properties", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolRedactItemIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolsRedact")
- item?.target = self
- item?.btnTag = KMToolbarType.redact.rawValue
- item?.toolTip = NSLocalizedString("Redact", comment: "")
- item?.titleName = NSLocalizedString("Redact", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.btnAction = #selector(redactMenuAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Redact", comment: ""), action: #selector(redactMenuAction), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
- item?.image = NSImage(named: "DigitalSign_icon")
- item?.target = self
- 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: "")
- item?.titleName = NSLocalizedString("Digital Sign", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.boxImagePosition = .imageAbove
- item?.btnAction = #selector(_itemAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Digital Sign", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- }
- }
-
- private func _setupAnnotationItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarMoveToolModeItemIdentifier {
- item?.titleName = NSLocalizedString("Scroll Tool", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsPantool)
- item?.target = self
- item?.btnTag = KMToolbarViewType.Move.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Scroll Tool", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(leftControllButtonAction)
- } else if identifier == KMToolbarMagnifyToolModeItemIdentifier {
- item?.titleName = NSLocalizedString("Magnify Tool", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsMagnifier)
- item?.target = self
- item?.btnTag = KMToolbarViewType.Magnify.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Magnify Tool", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(leftControllButtonAction)
- } else if identifier == KMToolbarSelectToolModeItemIdentifier {
- item?.titleName = NSLocalizedString("Content Selection Tool", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsContentsel)
- item?.target = self
- item?.btnTag = KMToolbarViewType.Select.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Content Selection Tool", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(leftControllButtonAction)
- } else if identifier == KMToolbarZoomToSelectionItemIdentifier {
- item?.titleName = NSLocalizedString("Zoom to selected area", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsAreazoom)
- item?.target = self
- item?.btnTag = KMToolbarViewType.SelectZoom.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Zoom to selected area", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(leftControllButtonAction)
- } else if identifier == KMToolbarHighlightAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Highlight", comment: "")
- // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsUnderline)
- let imageV = KMNoteTypeImageView()
- let color = UserDefaults.standard.PDFListViewColor(forKey: CHighlightNoteColorKey) ?? .red
- item?.image = imageV.noteTypeImage(withType: SKNHighlightString, color: color)
- item?.target = self
- item?.btnTag = CAnnotationType.highlight.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = String(format: "%@ (⌃⌘H)", NSLocalizedString("Highlight", comment: ""))
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
-
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarUnderlineAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Underline", comment: "")
- // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsUnderline)
- let imageV = KMNoteTypeImageView()
- let color = UserDefaults.standard.PDFListViewColor(forKey: CUnderlineNoteColorKey) ?? .red
- item?.image = imageV.noteTypeImage(withType: SKNUnderlineString, color: color)
- item?.target = self
- item?.btnTag = CAnnotationType.underline.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = String(format: "%@ (⇧⌘M)", NSLocalizedString("Underline", comment: ""))
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarStrikeOutAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Strikethrough", comment: "")
- // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsStrikeout)
- let imageV = KMNoteTypeImageView()
- let color = UserDefaults.standard.PDFListViewColor(forKey: CStrikeOutNoteColorKey) ?? .red
- item?.image = imageV.noteTypeImage(withType: SKNStrikeOutString, color: color)
- item?.target = self
- item?.btnTag = CAnnotationType.strikeOut.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = String(format: "%@ (⌃⌘M)", NSLocalizedString("Strikethrough", comment: ""))
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarInkAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Freehand", comment: "")
- // item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsPen)
- let imageV = KMNoteTypeImageView()
- let color = UserDefaults.standard.PDFListViewColor(forKey: CInkNoteColorKey) ?? .red
- item?.image = imageV.noteTypeImage(withType: SKNInkString, color: color)
- item?.target = self
- item?.btnTag = CAnnotationType.ink.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Add freehand drawings by hand writing just like you do with a pen.", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarFreeTextAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Text Note", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsText)
- item?.target = self
- item?.btnTag = CAnnotationType.freeText.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = String(format: "%@ (⌘N)", NSLocalizedString("Text Note", comment: ""))
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarAnchoredAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Anchored Note", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsNote)
- item?.target = self
- item?.btnTag = CAnnotationType.anchored.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = String(format: "%@ (⌥⌘N)", NSLocalizedString("Anchored Note", comment: ""))
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarSquareAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Rectangle", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsRec)
- item?.target = self
- item?.btnTag = CAnnotationType.square.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Draw rectangle; draw square by holding Shift key", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- }else if identifier == KMToolbarCircleAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Circle", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsOval)
- item?.target = self
- item?.btnTag = CAnnotationType.circle.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Draw oval; draw circle by holding Shift key", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarArrowAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Arrow", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsArrow)
- item?.target = self
- item?.btnTag = CAnnotationType.arrow.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Draw arrow; draw straight arrow by holding Shift key", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarLineAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Line", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsLine)
- item?.target = self
- item?.btnTag = CAnnotationType.line.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Draw line; draw straight line by holding Shift key", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarLinkAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Link", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsLink)
- item?.target = self
- item?.btnTag = CAnnotationType.link.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Select an area or text on a page for a link to be inserted.", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarSignSignatureAnnotationItemIdentifier {
- item?.titleName = NSLocalizedString("Signature", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsSign)
- item?.target = self
- item?.btnTag = CAnnotationType.signSignature.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Add beautiful handwriting or use your trackpad to create your own signature.", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMAnnotationStampToolbarItemIdentifier {
- item?.titleName = NSLocalizedString("Stamp", comment: "")
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsStamp)
- item?.target = self
- item?.btnTag = CAnnotationType.stamp.rawValue
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Add New Stamp", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarShowToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolShow")
- item?.selectedImage = NSImage(named: "KMImageNameMainToolHide")
- item?.alternateImage = NSImage(named: "KMImageNameMainToolShow")
- item?.selectedBackgroundColor = NSColor.clear
- item?.target = self
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Hide", comment: "")
- item?.isPopToolTip = true
- item?.titleName = NSLocalizedString("Hide", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(showPDFLayoutMode)
- } else if identifier == KMToolbarAnnotationSettingItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBtnSetNor")
- item?.target = self
- item?.isShowCustomToolTip = true
- item?.toolTip = String(format: "%@\n%@", NSLocalizedString("Customize Toolbar", comment: ""),NSLocalizedString("Drag-and-drop tools to change their order", comment: ""))
- item?.isPopToolTip = true
- item?.titleName = NSLocalizedString("Setting", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- item?.selectBackgroundType = .imageBox
- } else if identifier == KMAnnotationImageToolbarItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsImage)
- item?.target = self
- item?.titleName = NSLocalizedString("Image", comment: "")
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Choose an image to insert in a page.", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMAnnotationTableToolbarItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarMytoolsTable)
- item?.target = self
- item?.btnTag = CAnnotationType.table.rawValue
- item?.titleName = NSLocalizedString("Table", comment: "")
- item?.isShowCustomToolTip = true
- item?.toolTip = NSLocalizedString("Table", comment: "")
- item?.isPopToolTip = true
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- }
- }
-
- private func _setupEditItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarAddTextEditPDFItemIdentifier {
- item?.image = NSImage(named: "KMImageNameButtonEidtPDFText")
- item?.target = self
- item?.btnTag = CAnnotationType.addText.rawValue
- item?.toolTip = NSLocalizedString("Add Text", comment: "")
- item?.titleName = NSLocalizedString("Add Text", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarAddImageEditPDFItemIdentifier {
- item?.image = NSImage(named: "KMImageNameButtonEidtPDFImage")
- item?.target = self
- item?.btnTag = CAnnotationType.addImage.rawValue
- item?.toolTip = NSLocalizedString("Add Image", comment: "")
- item?.titleName = NSLocalizedString("Add Image", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
- }
- }
-
- private func _setupConvertItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarConversionWordItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertWord)
- item?.target = self
- item?.btnTag = KMToolbarType.word.rawValue
- 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: "")
- item?.titleName = NSLocalizedString("To Word", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMToolbarConversionExcelItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertExcel)
- item?.target = self
- item?.btnTag = KMToolbarType.excel.rawValue
- 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: "")
- item?.titleName = NSLocalizedString("To Excel", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMToolbarConversionPPTItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPPT)
- item?.target = self
- item?.btnTag = KMToolbarType.ppt.rawValue
- 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: "")
- item?.titleName = NSLocalizedString("To PPT", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMToolbarConversionRTFItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertRTF)
- item?.target = self
- item?.btnTag = KMToolbarType.rtf.rawValue
- item?.toolTip = NSLocalizedString("Turn PDF documents into Rich Text Format (RTF) files that can be opened in virtually any word processor.", comment: "")
- item?.titleName = NSLocalizedString("To RTF", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMToolbarConversionCSVItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertCSV)
- item?.target = self
- item?.btnTag = KMToolbarType.csv.rawValue
- item?.toolTip = NSLocalizedString("PDF To CSV", comment: "")
- item?.titleName = NSLocalizedString("To CSV", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- item?.promptIdentifier = identifier
- } else if identifier == KMToolbarConversionHTMLItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertHtml)
- item?.target = self
- item?.btnTag = KMToolbarType.html.rawValue
- item?.toolTip = NSLocalizedString("PDF To HTML", comment: "")
- item?.titleName = NSLocalizedString("To HTML", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- } else if identifier == KMToolbarConversionTextItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertText)
- item?.target = self
- item?.btnTag = KMToolbarType.conversion_text.rawValue
- item?.toolTip = NSLocalizedString("PDF To Text", comment: "")
- item?.titleName = NSLocalizedString("To Text", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(conversionMenuItemAction)
- } else if identifier == KMToolbarConversionImageItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPDFToIMG)
- item?.target = self
- item?.btnTag = KMToolbarType.conversion_image.rawValue
- // item?.toolTip = NSLocalizedString("Convert PDF to JPEG, PNG, TIFF, BMP, GIF or TGA files", comment: "")
- item?.titleName = NSLocalizedString("To Image", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- item?.btnAction = #selector(convertToImage)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: #selector(conversionMenuItemAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("PDF To JPEG", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.jpeg.rawValue)
- subMenu.addItem(title: NSLocalizedString("PDF To JPG", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.jpg.rawValue)
- subMenu.addItem(title: NSLocalizedString("PDF To PNG", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.png.rawValue)
- subMenu.addItem(title: NSLocalizedString("PDF To GIF", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.gif.rawValue)
- subMenu.addItem(title: NSLocalizedString("PDF To TIFF", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.tiff.rawValue)
- subMenu.addItem(title: NSLocalizedString("PDF To TGA", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.tga.rawValue)
- subMenu.addItem(title: NSLocalizedString("PDF To BMP", comment: ""), action: #selector(_pdfToImageAction), target: self, tag: KMPDFConvertType.bmp.rawValue)
-
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if item?.itemIdentifier == KMToolbarConversionExportImageItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertExportImage)
- item?.target = self
- // item?.toolTip = NSLocalizedString("The range you can extract images includes current page, odd page, even page, custom page, and all pages.", comment: "")
- item?.titleName = NSLocalizedString("Extract Images", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem.init(title: item?.titleName ?? "", action: nil, target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Extract All Images", comment: ""), action: #selector(_exportImageAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Extract Images", comment: ""), action: #selector(_exportImageAction), target: self, tag: 2)
-
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if item?.itemIdentifier == KMToolbarConversionOCRIdentifier {
- item?.titleName = NSLocalizedString("OCR", comment: "")
- item?.target = self
- item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
- item?.boxImagePosition = .imageLeft
- item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
- item?.btnAction = #selector(OCRbtnAction2)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
- menuItem.representedObject = KMToolbarConversionOCRIdentifier
- item?.menuFormRepresentation = menuItem
- } else if item?.itemIdentifier == KMToolbarConversionCreatePDFItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertCreatPDF)
- item?.target = self
- // item?.toolTip = NSLocalizedString("Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", comment: "")
- item?.titleName = NSLocalizedString("New PDF Document", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
-
- let menuItem = NSMenuItem.init(title: "New PDF Document", action: nil, target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("New Blank Page", comment: ""), action: #selector(_newPDFAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("New From Images", comment: ""), action: #selector(_newPDFAction), target: self, tag: 2)
- subMenu.addItem(NSMenuItem.separator())
- subMenu.addItem(title: NSLocalizedString("New From Web Page", comment: ""), action: #selector(_newPDFAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Import From Camera", comment: ""), action: #selector(_newPDFAction), target: self, tag: 4)
- subMenu.addItem(NSMenuItem.separator())
- subMenu.addItem(title: NSLocalizedString("Import From Scanner", comment: ""), action: #selector(_newPDFAction), target: self, tag: 5)
-
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- }
-
- }
-
- @objc func convertToImage(_ sender: KMToolbarItem) {
- // if let subMenu = sender.menuFormRepresentation?.submenu {
- // subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- // }
- }
-
- private func _setupFillSignItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarToolHookItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignTick)
- item?.target = self
- item?.btnTag = CAnnotationType.signTure.rawValue
- item?.toolTip = NSLocalizedString("Signature", comment: "")
- item?.titleName = NSLocalizedString("Signature", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolForkItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignFork)
- item?.target = self
- item?.btnTag = CAnnotationType.signFalse.rawValue
- item?.toolTip = NSLocalizedString("Add X", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolLineItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignLine)
- item?.target = self
- item?.btnTag = CAnnotationType.signLine.rawValue
- item?.toolTip = NSLocalizedString("Add line", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolDotItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignPoint)
- item?.target = self
- item?.btnTag = CAnnotationType.signDot.rawValue
- item?.toolTip = NSLocalizedString("Add dot", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolRectangleIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignRoundedrec)
- item?.target = self
- item?.btnTag = CAnnotationType.signCircle.rawValue
- item?.toolTip = NSLocalizedString("Add circle", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolTextIdentifier {
- item?.image = NSImage(named: KMImageNameToolbarFreeText)
- item?.target = self
- item?.btnTag = CAnnotationType.signText.rawValue
- item?.toolTip = NSLocalizedString("Add text", comment: "")
- item?.titleName = NSLocalizedString("Text", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolDateIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignDate)
- item?.target = self
- item?.btnTag = CAnnotationType.signDate.rawValue
- item?.toolTip = NSLocalizedString("Date", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- } else if (identifier == KMToolbarToolProfileIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignMyprofile)
- item?.target = self
- item?.toolTip = NSLocalizedString("My Profile", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(_itemAction)
- }else if (identifier == KMToolbarFillSignSignatureIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignMysignature)
- item?.target = self
- item?.btnTag = CAnnotationType.signSignature.rawValue
- item?.toolTip = NSLocalizedString("Sign document by typing or drawing a signature", comment: "")
- item?.boxImagePosition = .imageOnly
- item?.btnAction = #selector(changeAnnotationMode)
- }
- }
-
- private func _setupFormItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarToolTextFieldItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormTextfield)
- item?.target = self
- item?.btnTag = CAnnotationType.textField.rawValue
- item?.toolTip = NSLocalizedString("Text Field", comment: "")
- item?.titleName = NSLocalizedString("Text Field", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
-
- let menuItem = NSMenuItem.init(title: "TextField", action: #selector(changeAnnotationMode), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolCheckBoxItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormCheckbox)
- item?.target = self
- item?.btnTag = CAnnotationType.checkBox.rawValue
- item?.toolTip = NSLocalizedString("Check Box", comment: "")
- item?.titleName = NSLocalizedString("Check Box", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
- } else if identifier == KMToolbarToolRadioButtonItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormRadiobutton)
- item?.target = self
- item?.btnTag = CAnnotationType.radioButton.rawValue
- item?.toolTip = NSLocalizedString("Radio Button", comment: "")
- item?.titleName = NSLocalizedString("Radio Button", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
-
- let menuItem = NSMenuItem.init(title: "RadioButton", action: #selector(changeAnnotationMode), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolListBoxItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormListbox)
- item?.target = self
- item?.btnTag = CAnnotationType.listMenu.rawValue
- item?.toolTip = NSLocalizedString("List Box", comment: "")
- item?.titleName = NSLocalizedString("List Box", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
-
- let menuItem = NSMenuItem.init(title: "List Box", action: #selector(changeAnnotationMode), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolPullDownmenuItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormPulldownmenu)
- item?.target = self
- item?.btnTag = CAnnotationType.comboBox.rawValue
- item?.toolTip = NSLocalizedString("Combo Box", comment: "")
- item?.titleName = NSLocalizedString("Combo Box", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
-
- let menuItem = NSMenuItem.init(title: "PullDownmenu", action: #selector(changeAnnotationMode), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolButtonIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormButton)
- item?.target = self
- item?.btnTag = CAnnotationType.actionButton.rawValue
- item?.toolTip = NSLocalizedString("Button", comment: "")
- item?.titleName = NSLocalizedString("Button", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
-
- let menuItem = NSMenuItem.init(title: "Button", action: #selector(changeAnnotationMode), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolSignBoxIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFormSign)
- item?.target = self
- item?.btnTag = CAnnotationType.signature.rawValue
- item?.toolTip = NSLocalizedString("Signature", comment: "")
- item?.titleName = NSLocalizedString("Signature", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(changeAnnotationMode)
-
- let menuItem = NSMenuItem.init(title: "SignBox", action: #selector(changeAnnotationMode), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolFormAlignIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconPropertybarAlignLeftToor)
- item?.target = self
- // item?.toolTip = NSLocalizedString("Alignment", comment: "")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- item?.btnAction = #selector(formsAlignmentAction)
- item?.pdfView = self.pdfView
-
- let menuItem = NSMenuItem.init(title: "Alignment", action: nil, target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Align Left", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignLeftNor", action: #selector(formsAlignmentAction), target: self, tag: 0)
- subMenu.addItem(title: NSLocalizedString("Align Vertically", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignVercenterNor", action: #selector(formsAlignmentAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Align Right", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignRightNor", action: #selector(formsAlignmentAction), target: self, tag: 2)
- subMenu.addItem(NSMenuItem.separator())
- subMenu.addItem(title: NSLocalizedString("Align Top", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignUpNor", action: #selector(formsAlignmentAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Align Horizontally", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignHorcenterNor", action: #selector(formsAlignmentAction), target: self, tag: 4)
- subMenu.addItem(title: NSLocalizedString("Align Bottom", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignDownNor", action: #selector(formsAlignmentAction), target: self, tag: 5)
- subMenu.addItem(NSMenuItem.separator())
- subMenu.addItem(title: NSLocalizedString("Distribute Horizontally", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignHorsplitNor", action: #selector(formsAlignmentAction), target: self, tag: 6)
- subMenu.addItem(title: NSLocalizedString("Distribute Vertically", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignVersplitNor", action: #selector(formsAlignmentAction), target: self, tag: 7)
-
- menuItem.submenu = subMenu
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolFormMoreIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolFormMore")
- item?.target = self
- item?.toolTip = NSLocalizedString("More", comment: "")
- item?.titleName = NSLocalizedString("More", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.btnAction = #selector(formsMoreOperationAction)
-
- let menuItem = NSMenuItem.init(title: "More", action: #selector(formsMoreOperationAction), target: self)
- menuItem.tag = item!.btnTag
- item?.menuFormRepresentation = menuItem
- }
- }
-
- private func _setupViewDisplayItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarViewSettingIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayView)
- item?.target = self
- item?.toolTip = NSLocalizedString("View Settings", comment: "")
- item?.titleName = NSLocalizedString("View Settings", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMToolbarCropIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTailor)
- item?.target = self
- // item?.toolTip = NSLocalizedString("Note: Cropping a PDF hides some of the PDF’s content without removing it.", comment: "")
- item?.titleName = NSLocalizedString("Crop", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(cropMenuAction)
-
- let menuItem = NSMenuItem.init(title: "Crop", action: #selector(cropMenuAction), target: self)
- let subMenu = NSMenu()
- // subMenu.addItem(title: NSLocalizedString("Crop All Pages", comment: ""), action: #selector(_cropAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Crop Current Page", comment: ""), action: #selector(_cropAction), target: self, tag: 2)
- subMenu.addItem(title: NSLocalizedString("Auto Crop – Separate", comment: ""), action: #selector(_cropAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Auto Crop – Combined", comment: ""), action: #selector(_cropAction), target: self, tag: 4)
- subMenu.addItem(title: NSLocalizedString("Select Area", comment: ""), action: #selector(_cropAction), target: self, tag: 5)
- // subMenu.addItem(title: NSLocalizedString("Crop Options...", comment: ""), action: #selector(_cropAction), target: self, tag: 6)
-
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarSnapshotIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplaySnapshot)
- item?.target = self
- item?.toolTip = NSLocalizedString("Take Snapshot", comment: "")
- item?.titleName = NSLocalizedString("Snapshot", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(_itemAction)
- } else if identifier == KMToolbarTTSIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTTS)
- item?.target = self
- item?.toolTip = NSLocalizedString("TTS (Text-to-speech)", comment: "")
- item?.titleName = NSLocalizedString("TTS", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(_itemAction)
- }
- }
-
- private func _setupToolItem(_ item: KMToolbarItemView?) {
- let identifier = item?.itemIdentifier
- if identifier == KMToolbarToolCropItemIdentifier {
- item?.image = NSImage(named: "KMImageNameMainToolsCrop")
- item?.alternateImage = NSImage(named: "KMImageNameMainToolsCrop")
- item?.target = self
- item?.btnTag = KMToolbarType.crop.rawValue
- item?.toolTip = NSLocalizedString("Crop pages", comment: "")
- item?.titleName = NSLocalizedString("Crop", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.btnAction = #selector(cropMenuAction)
-
- let menuItem = NSMenuItem.init(title: "Crop", action: #selector(cropMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarComparisonItemIdentifier {
- item?.image = NSImage(named: KMImageNameUXIconBatchComparison)
- item?.target = self
- item?.btnTag = KMToolbarType.comparison.rawValue
- // item?.toolTip = NSLocalizedString("Compare", comment: "")
- item?.titleName = NSLocalizedString("Compare", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(_itemAction)
-
- let menuItem = NSMenuItem.init(title: "Bates Number", action: #selector(_menuItemAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Side-by-Side View", comment: ""), action: #selector(_comparisonAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Compare by File Overlay", comment: ""), action: #selector(_comparisonAction), target: self, tag: 2)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolBatesItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchBatesNor")
- item?.target = self
- item?.btnTag = KMToolbarType.bates.rawValue
- // item?.toolTip = NSLocalizedString("Add PDF Bates numbering to your legal, medical, or business documents", comment: "")
- item?.titleName = NSLocalizedString("Bates Numbers", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(batesMenuAction)
-
- let menuItem = NSMenuItem.init(title: "Bates Numbers", action: #selector(batesMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Add Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Remove Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 2)
- subMenu.addItem(title: NSLocalizedString("Batch Add Batch Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Batch Remove Bates Numbers", comment: ""), action: #selector(_batesAction), target: self, tag: 4)
- subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_batesAction), target: self, tag: 5)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarAIItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconAINor")
- item?.target = self
- item?.btnTag = KMToolbarType.aiTools.rawValue
- item?.titleName = NSLocalizedString("AI Tools", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
-
- let menuItem = NSMenuItem.init(title: "AI Tools", action: #selector(batesMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("AI Summarize", comment: ""), action: #selector(_AIAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("AI Rewrite", comment: ""), action: #selector(_AIAction), target: self, tag: 2)
- subMenu.addItem(title: NSLocalizedString("AI Proofread", comment: ""), action: #selector(_AIAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("AI Translate", comment: ""), action: #selector(_AIAction), target: self, tag: 4)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolHeaderFooterItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchHeaderandfooterNor")
- item?.target = self
- item?.btnTag = KMToolbarType.headerAndFooter.rawValue
- // item?.toolTip = NSLocalizedString("Insert header, footer, and page numbers to PDF", comment: "")
- item?.titleName = NSLocalizedString("Header & Footer", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(headerfooterMenuAction)
-
- let menuItem = NSMenuItem.init(title: "Header & Footer", action: #selector(headerfooterMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Add Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Remove Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 2)
- subMenu.addItem(title: NSLocalizedString("Batch Add Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Batch Remove Header & Footer", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 4)
- subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_headerfooterAction), target: self, tag: 5)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolBackgroundItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchBackgroundNor")
- item?.target = self
- item?.btnTag = KMToolbarType.background.rawValue
- // item?.toolTip = NSLocalizedString("Insert PDF page background by color or image", comment: "")
- item?.titleName = NSLocalizedString("Background", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(backgroundMenuAction)
-
- let menuItem = NSMenuItem.init(title: "Background", action: #selector(backgroundMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Add Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Remove Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 2)
- subMenu.addItem(title: NSLocalizedString("Batch Add Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Batch Remove Background", comment: ""), action: #selector(_backgroundAction), target: self, tag: 4)
- subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_backgroundAction), target: self, tag: 5)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolWatermarkItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchWatermarkNor")
- item?.target = self
- item?.btnTag = KMToolbarType.watermark.rawValue
- // item?.toolTip = NSLocalizedString("Watermark", comment: "")
- item?.titleName = NSLocalizedString("Watermark", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(watermarkMenuAction)
-
- let menuItem = NSMenuItem.init(title: "Watermark", action: #selector(watermarkMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Add Watermark", comment: ""), action: #selector(_watermarkAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Remove Watermark", comment: ""), action: #selector(_watermarkAction), target: self, tag: 2)
- subMenu.addItem(title: NSLocalizedString("Batch Add Watermarks", comment: ""), action: #selector(_watermarkAction), target: self, tag: 3)
- subMenu.addItem(title: NSLocalizedString("Batch Remove Watermarks", comment: ""), action: #selector(_watermarkAction), target: self, tag: 4)
- subMenu.addItem(title: NSLocalizedString("Manage Templates", comment: ""), action: #selector(_watermarkAction), target: self, tag: 5)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarToolCompressItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchOptimizeNor")
- item?.target = self
- item?.btnTag = KMToolbarType.compress.rawValue
- item?.boxImagePosition = .imageLeft
- item?.toolTip = NSLocalizedString("Reduce file size", comment: "")
- item?.titleName = NSLocalizedString("Compress", comment: "")
- item?.btnAction = #selector(compressMenuAction)
- } else if identifier == KMToolbarToolSecureItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchSafeNor")
- item?.target = self
- // item?.toolTip = NSLocalizedString("Batch encrypting PDF documents", comment: "")
- item?.titleName = NSLocalizedString("Security", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(secureMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Security", comment: ""), action: #selector(secureMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Set Passwords", comment: ""), action: #selector(_secureAction), target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Remove Security", comment: ""), action: #selector(_secureAction), target: self, tag: 2)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- }else if identifier == KMToolbarToolMergeItemIdentifier {
- item?.image = NSImage(named: "KMImageNameUXIconBatchMergeNor")
- item?.target = self
- item?.btnTag = KMToolbarType.merge.rawValue
- item?.toolTip = NSLocalizedString("Combine multiple documents into a new PDF, or borrow individual pages", comment: "")
- item?.titleName = NSLocalizedString("Merge", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(mergeMenuItemAction)
- }
- }
- }
- extension KMToolbarViewController: NSMenuItemValidation {
- func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
- if menuItem.action == #selector(toggleCaseInsensitiveSearch) {
- menuItem.state = KMDataManager.ud_integer(forKey: SKCaseInsensitiveSearchKey) == 1 ? .on : .off
- } else if menuItem.action == #selector(formsAlignmentAction) {
- if menuItem.tag < 6 {
- if self.pdfView.activeAnnotations.count >= 2 {
- return true
- }
- } else {
- if self.pdfView.activeAnnotations.count >= 3 {
- return true
- }
- }
- return false
- }
- return true
- }
- }
- extension KMToolbarViewController {
- func isEnable(isEnable: Bool = true) {
- for item in toolbarItems {
- let itemView: KMToolbarMainItemView = item.value as? KMToolbarMainItemView ?? KMToolbarMainItemView()
- itemView.unEnabled = !isEnable
- itemView.isSelected = false
- }
- }
- }
- extension KMToolbarViewController {
- func refreshSearchBarMenu() {
- let words = UserDefaults.standard.array(forKey: "kmDocumentSearchWordArrays") as? [String] ?? []
- let searchMenu = NSMenu()
-
- for word in words {
- var truncatedWord = word
- if word.count > 15 {
- truncatedWord = String(word.prefix(15)) + "..."
- }
- let item = searchMenu.addItem(withTitle: truncatedWord, action: #selector(searchPDFKeyWord(_:)), keyEquivalent: "")
- item.representedObject = word
- }
-
- let attributes: [NSAttributedString.Key: Any] = [.font: NSFont(name: "Helvetica", size: 12.0)!]
- if !words.isEmpty {
- let attributedString = NSAttributedString(string: NSLocalizedString("Search History", comment: ""), attributes: attributes)
- let item = NSMenuItem()
- item.attributedTitle = attributedString
- searchMenu.insertItem(item, at: 0)
- searchMenu.addItem(NSMenuItem.separator())
-
- let attributedString1 = NSAttributedString(string: NSLocalizedString("Clear Search History", comment: ""), attributes: attributes)
- let item1 = NSMenuItem()
- item1.attributedTitle = attributedString1
- item1.action = #selector(clearSearchWordHistory(_:))
- item1.target = self
- searchMenu.addItem(item1)
-
- searchMenu.insertItem(NSMenuItem.separator(), at: 0)
- }
-
- let attributedString2 = NSAttributedString(string: NSLocalizedString("Ignore Case", comment: ""), attributes: attributes)
- let ignoreItem = NSMenuItem()
- ignoreItem.attributedTitle = attributedString2
- ignoreItem.action = #selector(toggleCaseInsensitiveSearch)
- ignoreItem.target = self
- searchMenu.insertItem(ignoreItem, at: 0)
- (self.searchField.cell as? NSSearchFieldCell)?.searchMenuTemplate = searchMenu
-
- }
-
- @objc func toggleCaseInsensitiveSearch(_ sender: NSMenuItem) {
- var value = KMDataManager.ud_integer(forKey: SKCaseInsensitiveSearchKey)
- KMDataManager.ud_set(value == 0 ? 1 : 0, forKey: SKCaseInsensitiveSearchKey)
-
- // let caseInsensitive = UserDefaults.standard.bool(forKey: "SKCaseInsensitiveFindKey")
- // UserDefaults.standard.set(!caseInsensitive, forKey: "SKCaseInsensitiveFindKey")
-
- self.searchPDFKey(self.searchField.stringValue)
- }
-
- @objc func searchPDFKeyWord(_ item: NSMenuItem) {
- guard let word = item.representedObject as? String else {
- return
- }
-
- self.searchPDFKey(word)
- }
-
- func searchPDFKey(_ string: String) {
- self.searchField.stringValue = string
- self.delegate?.toolbarViewController?(self, searchAction: string, forward: true)
-
- let word = string
- var words = UserDefaults.standard.array(forKey: "kmDocumentSearchWordArrays") as? [String] ?? []
- var mutableWords = words
-
- if let index = mutableWords.firstIndex(of: word) {
- mutableWords.remove(at: index)
- }
-
- mutableWords.insert(word, at: 0)
-
- if mutableWords.count > 10 {
- mutableWords.removeLast()
- }
-
- UserDefaults.standard.set(mutableWords, forKey: "kmDocumentSearchWordArrays")
- UserDefaults.standard.synchronize()
-
- refreshSearchBarMenu()
- }
- @objc func clearSearchWordHistory(_ sender: Any) {
- UserDefaults.standard.removeObject(forKey: "kmDocumentSearchWordArrays")
- UserDefaults.standard.synchronize()
-
- refreshSearchBarMenu()
- }
- }
|