123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475 |
- //
- // 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, findSearchAction searchString: String, forward: Bool)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
- @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, viewItemDidClick 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()
- weak var pdfView: 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
- }
- let allowsPrinting = self.pdfView?.document?.allowsPrinting ?? false
- let allowsCopying = self.pdfView?.document?.allowsCopying ?? false
- if !allowsPrinting || !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
- }
- if itemId == KMDocumentConversonToolbarItemIdentifier {
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self.leftControllButtonAction(item: item_.clickButton)
- self._itemSetPromptFlag(item: item_)
- } else if itemId == KMDocumentRedactToolbarItemIdentifier {
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self._itemAction(item_.clickButton)
- self._itemSetPromptFlag(item: item_)
- } else if itemId == KMDocumentAnnotationToolbarItemIdentifier {
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self.leftControllButtonAction(item: item_.clickButton)
- self._itemSetPromptFlag(item: item_)
- } else if itemId == KMDocumentPageToolbarItemIdentifier {
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self.leftControllButtonAction(item: item_.clickButton)
- self._itemSetPromptFlag(item: item_)
- } else if itemId == KMDocumentToolToolbarItemIdentifier {
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self.leftControllButtonAction(item: item_.clickButton)
- self._itemSetPromptFlag(item: item_)
- } else if itemId == KMDocumentPresentationToolbarItemIdentifier {
- let item_ = self.toolbarItemFindItemIdentifiers(value: itemId)
- self._itemAction(item_.clickButton)
- self._itemSetPromptFlag(item: item_)
- } else {
- 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 {
- if let model = KMDataManager.toolbar_getData() {
- return model.leftCellIdentifiers ?? []
- }
- return [KMLeftControlToolbarItemIdentifier,
- KMNewToolbarSpaceItemIdentifier, KMDocumentZoomViewToolbarItemIdentifier,
- KMDocumentPreviousPageToolbarItemIdentifier, KMDocumentHomeToolbarItemIdentifier]
- }
- return []
- }
-
- func toolbarRightDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- if toolbarType == .Main {
- if let model = KMDataManager.toolbar_getData() {
- return model.rightCellIdentifiers ?? []
- }
- return [KMDocumentViewDisplayToolbarItemIdentifier, KMDocumentShareToolbarItemIdentifier,
- KMDocumentSearchToolbarItemIdentifier, KMRightControlToolbarItemIdentifier]
- } else if [.Annatiton,.Magnify,.Move,.Select,.SelectZoom].contains(toolbarType) {
- return [KMToolbarAnnotationSettingItemIdentifier]
- }
- return []
- }
-
- func toolbarAllowedItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- switch toolbarType {
- case .None:
- return []
- case .Main:
- var defaultCellIdentifiers = mainToolIdentifiers
- if defaultCellIdentifiers.contains(KMDocumentHomeToolbarItemIdentifier) {
- defaultCellIdentifiers.removeObject(KMDocumentHomeToolbarItemIdentifier)
- }
- return defaultCellIdentifiers
- case .Annatiton,.Magnify,.Move,.Select,.SelectZoom:
- // return annotationToolIdentifiers
- 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]
- case .editPDF:
- return editPDFItemIdentifiers
- case .Page:
- return pageEditToolIdentifiers
- case .Tool:
- return toolToolIdentifiers
- case .Form:
- return formToolIdentifiers
- case .FillSign:
- return fillSignToolIdentifiers
- case .Conversion:
- return conversionToolIdentifiers
- case .viewSetting:
- return [KMToolbarViewSettingIdentifier, KMToolbarCropIdentifier,
- KMToolbarSnapshotIdentifier, KMToolbarTTSIdentifier]
- default:
- break
- }
- return []
- }
-
- func toolbarDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- switch toolbarType {
- case .None:
- return []
- case .Main:
- if let model = KMDataManager.toolbar_getData() {
- return model.centerCellIdentifiers ?? []
- }
- 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 create == false {
- if KMDataManager.default.toolbarConfigDataUpdated {
- create = true
- }
- }
- if item == nil || create {
- if isMainToolItem(identifier) {
- item = KMToolbarMainItemView(itemIdentifier: identifier)
- } else if annotationToolIdentifiers.contains(identifier) {
- item = KMToolbarCustomItemView.init(itemIdentifier: identifier)
- } else {
- item = KMToolbarCustomItemView.init(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 ?? .unkown
- if annotationType == .square || annotationType == .circle || annotationType == .arrow || annotationType == .line{
- UserDefaults.standard.set(annotationType.rawValue, forKey: KMToolBarToolPDFShapeStyle)
- UserDefaults.standard.synchronize()
- }
- let toolMode = pdfView?.toolMode ?? .none
- 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 toolMode == .moveToolMode {
- if item.itemIdentifier == KMToolbarMoveToolModeItemIdentifier {
- item.isSelected = true
- }
- } else if toolMode == .magnifyToolMode {
- if item.itemIdentifier == KMToolbarMagnifyToolModeItemIdentifier {
- item.isSelected = true
- }
- } else if toolMode == .selectToolMode {
- if item.itemIdentifier == KMToolbarSelectToolModeItemIdentifier {
- item.isSelected = true
- }
- } else if 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 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 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 == 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 == 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
-
- let menuItem = NSMenuItem(title: item?.titleName ?? "", action: #selector(_menuItemAction), keyEquivalent: "")
- menuItem.target = self
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } 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
-
- let menuItem = NSMenuItem(title: item?.titleName ?? "", action: #selector(_menuItemAction), keyEquivalent: "")
- menuItem.target = self
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } 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
-
- let menuItem = NSMenuItem(title: NSLocalizedString("Converter", comment: ""), action: #selector(_menuItemAction), keyEquivalent: "")
- menuItem.target = self
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } 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(_menuItemAction), target: self)
- menuItem.tag = item!.btnTag
- menuItem.representedObject = identifier
- 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(_menuItemAction), target: self)
- menuItem.tag = item!.btnTag
- menuItem.representedObject = identifier
- 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(_menuItemAction), target: self)
- menuItem.tag = item!.btnTag
- menuItem.representedObject = identifier
- 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
-
- let menuItem = NSMenuItem(title: item?.titleName ?? "", action: #selector(_menuItemAction), keyEquivalent: "")
- menuItem.target = self
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } 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
-
- let menuItem = NSMenuItem(title: item?.titleName ?? "", action: #selector(_menuItemAction), keyEquivalent: "")
- menuItem.target = self
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } 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: "KMImageNameToolbarPrintNor")
- 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
- menuItem.representedObject = identifier
- 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
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMDocumentPreviousBackToolbarItemIdentifier {
- let view = KMToolbarPreviousBackItemView()
- item?.customizeView = view
- view.callback = { [weak self] idx, _ in
- if idx == 1 {
- self?.delegate?.changePDFViewGoToForwardAction?()
- } else if idx == 2 {
- self?.delegate?.changePDFViewGotoBackAction?()
- }
- }
- } else if identifier == KMDocumentFirstLastToolbarItemIdentifier {
- let view = KMToolbarFirstLastItemView()
- item?.customizeView = view
- view.callback = { [weak self] idx, _ in
- if let item = self?.toolbarItemFindItemIdentifiers(value: identifier!) {
- self?.delegate?.toolbarViewController?(self!, viewItemDidClick: item, index: idx, info: nil)
- }
- }
- } else if identifier == KMDocumentPageIndicatorToolbarItemIdentifier {
- // let view = KMToolbarPageIndicatorItemView(zoomView: nil)
- // item?.customizeView = view
- } else if identifier == KMDocumentPresentationToolbarItemIdentifier {
- item?.image = NSImage(named: "KMImageNameToolbarSlideshowNor")
- item?.titleName = NSLocalizedString("Presentation", comment: "")
- item?.selectBackgroundType = .imageBox
- item?.boxImagePosition = .imageAbove
-
- 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?.btnAction = #selector(_itemAction)
- item?.promptIdentifier = identifier
-
- let menuItem = NSMenuItem(title: item?.titleName ?? "", action: #selector(_menuItemAction), keyEquivalent: "")
- menuItem.target = self
- menuItem.representedObject = identifier
- item?.menuFormRepresentation = menuItem
- } else if identifier == KMToolbarFixedSpaceItemIdentifier {
- let view = NSView()
- view.frame = NSMakeRect(0, 0, 36, 36)
- item?.customizeView = view
- }
- }
-
- 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: nil, 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) {
- let cnt = self.pdfView?.activeAnnotations.count ?? 0
- if menuItem.tag < 6 {
- if cnt >= 2 {
- return true
- }
- } else {
- if cnt >= 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
-
- if let cv = itemView.customizeView {
- self.subviewsdEnable(view: cv, isEnable: isEnable)
- }
- }
- }
-
- func subviewsdEnable(view: NSView, isEnable: Bool) {
- if let data = view as? NSButton {
- data.isEnabled = isEnable
- }
-
- if let data = (view as? NSTextField) {
- data.isEnabled = isEnable
- }
-
- for subview in view.subviews {
- if subview.subviews.count != 0 {
- self.subviewsdEnable(view: subview, isEnable: isEnable)
- }
- if let data = subview as? NSButton {
- data.isEnabled = isEnable
- }
-
- if let data = (subview as? NSTextField) {
- data.isEnabled = isEnable
- }
- }
- }
- }
- 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()
- }
- }
|