123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192 |
- //
- // KMBrowserWindowController.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2022/12/9.
- //
- import Cocoa
- @objcMembers class KMBrowserWindowController: CTBrowserWindowController {
- var rightSegmentControl: KMSegmentedBox?
- var modeType: KMHomeToolState = .Home
- var filterType: Int = 0
- var mainViewController: NSViewController?
- var isShowingTokenTimeOutAlert: Bool = false
- var currentTimer: Timer?
- private(set) var isMultiTabMode: Bool = false
-
- var rightMessageVC: KMVerificationMessageViewController!
- var rightToolbarItemView: NSView!
-
- private var homeVC: KMHomeViewController?
-
- var savedNormalSetup: NSMutableDictionary = NSMutableDictionary()
-
- // 记录当前显示模式
- // var _mwcFlags: MwcFlags = MwcFlags()
-
- deinit {
- KMPrint("KMBrowserWindowController deinit...")
-
- // self.removeObserverForAppearanceChange()
- DistributedNotificationCenter.default().removeObserver(self)
- NotificationCenter.default.removeObserver(self)
- }
-
- override func loadWindow() {
- super.loadWindow()
-
- // self.window?.titlebarAppearsTransparent = true
- }
- override func windowDidLoad() {
- super.windowDidLoad()
-
- NSImage.makeTextAlignImages()
- NSImage.makeAdornImages()
- window?.backgroundColor = NSColor.km_init(hex: "#DFE1E5")
- self.window?.appearance = NSApp.appearance
- self.window?.titlebarAppearsTransparent = true
- // self.window?.standardWindowButton(.closeButton)?.superview?.needsLayout = true
-
- // window?.setFrameAutosaveName("")
- rightTabStripView_.delete = self
- homeRightTabStripView_.delete = self
- rightTabStripView_.updateView()
- fileUploadPanel.delete = self
- homeRightTabStripView_.homeRightSearchField.delegate = self
-
- isMultiTabMode = true
- // self.addObserverForAppearanceChange()
-
- refreshToolBar(homeToolState: .Home)
-
- NotificationCenter.default.addObserver(self, selector: #selector(closeAllTabs(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseAllTabs"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(openNewWindow(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerOpenNewWindow"), object: nil)
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(_themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
-
- // if (KMWelcomeWindowController.welcomeHasShow() == false) {
- // //AI 版本禁掉首次开启帮助文档
- //// KMTools.openQuickStartStudy()
- //
- // DispatchQueue.main.async {
- // let welcome = KMWelcomeWindowController()
- // self.km_beginSheet(windowC: welcome)
- // welcome.itemClick = { [weak self] idx, param in
- // if (idx == 1) { // 关闭
- // self?.km_endSheet()
- // } else if (idx == 2) { // 以后提醒
- // self?.km_endSheet()
- // } else if (idx == 3) { // 注册
- // self?.km_endSheet()
- //
- // guard let window_ = self?.window else {
- // return
- // }
- // _ = KMLoginWindowController.show(window: window_, .Batch, .register)
- // }
- // }
- // }
- // }
- updateViewColor()
-
- var tabbingMode = NSWindow.TabbingMode.automatic
- let openDocumentType = KMPreference.shared.openDocumentType
- if openDocumentType == .inSameWindow {
- tabbingMode = .preferred
- } else if openDocumentType == .newWindow {
- tabbingMode = .disallowed
- }
- #if VERSION_FREE
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- tabbingMode = .disallowed
- }
- #endif
- // self.window?.tabbingMode = tabbingMode
-
-
- let windowSizeOption = KMPreferenceManager.shared.openFileType
- // if (hasWindowSetup) {
- // NSString *rectString = [savedNormalSetup objectForKey:MAINWINDOWFRAME_KEY];
- // if (rectString)
- // [window setFrame:NSRectFromString(rectString) display:NO];
- // } else
- if (windowSizeOption == .maxim) {
- Task {
- self.window?.setFrame(NSScreen.main?.visibleFrame ?? (self.window?.frame ?? .zero), display: false)
- }
- }
- // }
- if windowSizeOption == .fit {
- self.performFit(nil)
- }
- }
-
- @objc func closeAction() {
- self.window?.performClose(nil)
- }
-
- override func windowShouldClose(_ sender: NSWindow) -> Bool {
- if self.browser.tabStripModel.count() > 1 {
- self.browser.windowDidBeginToClose()
- return false
- }
- return true
- }
-
- override func windowWillClose(_ notification: Notification) {
- // iRate.sharedInstance().appLaunched()
- }
-
- override func layoutSubviews() {
- super.layoutSubviews()
-
- // if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.closeButton) {
- // button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
- // }
- // if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.zoomButton) {
- // button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
- // }
- // if let button = (self.window as? CTBrowserWindow)?.standardWindowButton(.miniaturizeButton) {
- // button.frame = NSMakeRect(button.frame.minX, 0, button.frame.width, button.frame.height)
- // }
- }
-
- // MARK: Dark&Light
-
- // func addObserverForAppearanceChange() -> Void {
- // window?.contentView?.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil)
- // }
-
- // func removeObserverForAppearanceChange() -> Void {
- // window?.contentView?.removeObserver(self, forKeyPath: "effectiveAppearance")
- // }
-
- // override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
- // if keyPath == "effectiveAppearance" {
- // self.updateViewColor()
- // }
- // }
-
- @objc private func _themeChanged(_ sender: Notification) {
-
- let isDarkModel = KMAdvertisementConfig.isDarkModel()
- if isDarkModel {
- self.window?.appearance = .init(named: .darkAqua)
- } else {
- self.window?.appearance = .init(named: .aqua)
- }
- self.window?.contentView?.appearance = self.window?.appearance ?? .init(named: .aqua)
-
- self.interfaceThemeDidChanged(self.window?.appearance?.name ?? .aqua)
- }
-
- override func updateViewColor() {
- super.updateViewColor()
-
- window?.backgroundColor = KMTabAppearance.tabsViewBackgroundColor()
- }
-
- // MARK: Public Methods
-
- func refreshToolBar(homeToolState toolState: KMHomeToolState) -> Void {
- modeType = toolState
-
- let document = browser.activeTabContents()
- if document != nil {
- if document!.isHome {
- homeRightTabStripView_.isHidden = modeType == .Home
- } else {
- self.homeRightStripView.isHidden = true
- }
- } else {
- self.homeRightStripView.isHidden = true
- }
-
- homeRightTabStripView_.homeRefreshButton.isEnabled = true
- homeRightTabStripView_.homeUploadButton.isEnabled = true
-
- filterType = 0
- rightTabStripView_.sortPopUpButton.removeAllItems()
- rightTabStripView_.filterPopUpButton.removeAllItems()
- rightTabStripView_.updateView()
- }
-
- override var hasToolbar: Bool {
- get {
- return false
- }
- }
-
- func showSnapshots(setups: NSArray?) {
- let doc = self.document as? KMMainDocument
- doc?.mainViewController?.showSnapshots(setups: setups)
- }
-
- var km_browser: KMBrowser? {
- get {
- return self.browser as? KMBrowser
- }
- }
-
- // MARK: Private Methods
-
- func openDocumentWindow() -> Void {
- // let panel = NSOpenPanel()
- // panel.allowsMultipleSelection = false
- // panel.allowedFileTypes = ["pdf"]
- // panel.beginSheetModal(for: NSApp.mainWindow!) { response in
- // if response == .OK {
- // let openPath = panel.url?.path
- // let selectDocument = self.selectTabContents(path: openPath!)
- // if selectDocument != nil {
- // let currentIndex = selectDocument!.browser.tabStripModel.index(of: selectDocument)
- // self.browser.tabStripModel.selectTabContents(at: Int32(currentIndex), userGesture: true)
- // return
- // }
- // if !panel.url!.path.isPDFValid() {
- // let alert = NSAlert()
- // alert.alertStyle = .critical
- // alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
- // alert.runModal()
- // return
- // }
- // NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { pdfDocument, documentWasAlreadyOpen, error in
- // print("openDocumentWindow")
- // }
- // }
- // }
-
- // MARK TODO: + 号开启
- // self.browser.addHomeTabContents()
- self.tabStripView?.addTabButton?.layer?.backgroundColor = .clear
- self.km_browser?.addNewTabContents()
- }
-
- // override func openDocument(_ sender: Any!) {
- // self.openDocumentWindow()
- // }
-
- func selectTabContents(path filePath: String) -> KMMainDocument? {
- let document = NSDocumentController.shared.document(for: URL(fileURLWithPath: filePath))
- var selectDocument: KMMainDocument?
- if document != nil {
- if document!.isKind(of: KMMainDocument.self) {
- selectDocument = document as! KMMainDocument
- }
- }
- return selectDocument
- }
-
-
- // MARK: Getter
-
- override var rightStripView: NSView! {
- get {
- if self.rightToolbarItemView == nil {
- self.rightToolbarItemView = NSView.init(frame: CGRectMake(0, 10, 184, 40))
- self.rightToolbarItemView.wantsLayer = true
-
- if self.rightMessageVC == nil {
- self.rightMessageVC = KMVerificationMessageViewController.init()
- }
- self.rightMessageVC.frameUpdateHandle = { [weak self] rect in
- guard let rsView = self?.rightToolbarItemView else {
- return
- }
- var superRect = rsView.frame
- if (superRect.size.width < self!.rightMessageVC.view.frame.size.width + 8) {
- superRect.size.width = self!.rightMessageVC.view.frame.size.width + 8
- }
-
- if let supView = rsView.superview {
- let viewRect = supView.frame
- if (superRect.origin.x) + (superRect.size.width) > (viewRect.origin.x) + (viewRect.size.width) {
- let offsetValue = ((superRect.origin.x) + (superRect.size.width) - (viewRect.origin.x) - (viewRect.size.width))
- superRect.origin.x -= offsetValue
- }
- }
-
- self?.rightToolbarItemView.frame = superRect
- }
- var rect = self.rightMessageVC.view.frame;
- rect.origin.x = CGRectGetWidth(self.rightToolbarItemView.frame) - rect.size.width - 8
- rect.origin.y = (CGRectGetHeight(self.rightToolbarItemView.frame) - rect.size.height)/2
- self.rightMessageVC.view.frame = rect
- self.rightMessageVC.view.autoresizingMask = [ .maxXMargin]
- self.rightToolbarItemView.addSubview(self.rightMessageVC.view)
-
- }
- return self.rightToolbarItemView
- }
- }
-
- override var homeRightStripView: NSView! {
- get {
- return homeRightTabStripView_
- }
- }
-
- // MARK: Button Action
-
- func commandDispatch(_ sender: Any) -> Void {
- var needShowChooseWindow = false
- //#if VERSION_FREE
- //#if VERSION_DMG
- if (!IAPProductsManager.default().isAvailableAllFunction()) {
- needShowChooseWindow = true
- }
- //#endif
- if needShowChooseWindow {
- let preferenceNoteShow = UserDefaults.standard.bool(forKey: KMTabbingHintShowFlag)
- if preferenceNoteShow {
- menuItemAction_newTagPageToNewWindow("")
- } else {
- if !KMDataManager.default.isTabbingWin{
- KMDataManager.default.isTabbingWin = true
- let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
- tabbingWin.selectCallBack = {[weak self] continueOrNot in
- KMDataManager.default.isTabbingWin = false
- if continueOrNot {
- self?.reopenDocument(forPaths: nil)
- } else {
-
- }
- }
- self.km_beginSheet(windowC: tabbingWin)
- }
- }
- } else {
- openDocumentWindow()
- }
- }
-
- func reopenDocument(forPaths path: String?) -> Void {
- if path == nil {
- let browser = KMBrowser.init() as KMBrowser
- browser.windowController = KMBrowserWindowController.init(browser: browser)
- browser.addHomeTabContents()
- browser.windowController.showWindow(self)
- }else {
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: path!), display: true) { doc, open, err in
-
- }
- }
- }
- func closeAllTabs(_ sender: Any) -> Void {
- if let noti = sender as? NSNotification, noti.object is CTTabController {
- if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
- return
- }
- }
- if self.browser != nil {
- self.browser.closeAllTabs()
- }
- }
-
- func openNewWindow(_ sender: Any) -> Void {
- if let noti = sender as? NSNotification, noti.object is CTTabController {
- if let window_ = (noti.object as! CTTabController).view.window, window_.isEqual(to: self.window) == false {
- return
- }
- }
-
- // 分离 Tab
- let windowC = self.detachTab(toNewWindow: self.activeTabView() as? CTTabView)
- // 新增 home Tab
- (windowC as? CTBrowserWindowController)?.browser.addHomeTabContentsWithDrag()
- windowC?.showWindow(nil)
- // if self.browser != nil {
- // let activeInt = self.browser.activeTabIndex()
- // let activeTab = self.browser.activeTabContents()
- //
- // self.browser.closeTab(at: activeInt, makeHistory: false)
- //
- // let browser: KMBrowser = KMBrowser.init()
- // browser.windowController = KMBrowserWindowController.init(browser: browser)
- // browser.addHomeTabContents()
- // browser.windowController.showWindow(self)
- //
- //// browser.add(activeTab, inForeground: false)
- //// browser.selectTab(at: 1)
- // if activeTab?.fileURL == nil {
- // return
- // }
- // let pdfDoc = CPDFDocument.init(url: (activeTab?.fileURL)!)
- // let document = NSDocumentController.shared.document(for: (activeTab?.fileURL)!)
- // KMMainDocument().tryToUnlockDocument(pdfDoc!)
- //
- // if ((pdfDoc?.isLocked)! == true) {
- // KMPasswordInputWindow.openWindow(window: self.window!, url: (activeTab?.fileURL)!) { result, password in
- // if result == .cancel { /// 关闭
- // return
- // }
- // /// 解密成功
- // var selectDocument: KMMainDocument? = nil
- // if ((document?.isKind(of: KMMainDocument.self)) != nil) {
- // selectDocument = (document as! KMMainDocument)
- // }
- // if selectDocument != nil {
- // let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
- // selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
- // if (selectDocument?.browser.window.isVisible)! as Bool {
- // selectDocument?.browser.window.orderFront(nil)
- // } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
- // selectDocument?.browser.window.orderFront(nil)
- // }
- // } else {
- // NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { document, _, error in
- // if (error == nil) {
- // (document as! KMMainDocument).mainViewController?.model.password = password
- // }
- // }
- // }
- // }
- // } else {
- // var selectDocument: KMMainDocument? = nil
- // if ((document?.isKind(of: KMMainDocument.self)) != nil) {
- // selectDocument = (document as! KMMainDocument)
- // }
- // if selectDocument != nil {
- // let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
- // selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
- // if (selectDocument?.browser.window.isVisible)! as Bool {
- // selectDocument?.browser.window.orderFront(nil)
- // } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
- // selectDocument?.browser.window.orderFront(nil)
- // }
- // } else {
- // NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
- //
- // }
- // }
- // }
- // }
- }
-
- func canMergeAllWindow() -> Bool {
- return self.fetchBrowserWindowControllers().count > 0
- }
-
- fileprivate func fetchBrowserWindowControllers() -> [KMBrowserWindowController] {
- var windowArray: [KMBrowserWindowController] = []
- for window in NSApp.windows {
- guard let windowController = window.windowController, windowController is KMBrowserWindowController else {
- continue
- }
- if let _tabScripC = (windowController as? KMBrowserWindowController)?.tabStripController, _tabScripC.viewsCount() <= 1 {
- continue
- }
- if (window.isVisible && (windowController.isEqual(to: self) == false)) {
- windowArray.append(windowController as! KMBrowserWindowController)
- }
- }
- return windowArray
- }
-
- func mergeAllWindow(_ sender: Any) {
- let windowArray = self.fetchBrowserWindowControllers()
- if (windowArray.count <= 0) {
- return
- }
- for windowC in windowArray {
- // 拼接窗口 [拼接窗口里的标签,除了home标签]
- self.append(windowC, toTabView: NSView())
- if let browser = windowC.browser {
- if (browser.tabCount() <= 1 && browser.activeTabContents().isHome) {
- windowC.close()
- }
- }
- }
- }
-
- override func tabDidSelect(_ notification: Notification!) {
- super.tabDidSelect(notification)
-
- if let _userInfo = notification.userInfo, let _newContents = _userInfo[CTTabNewContentsUserInfoKey] as? KMMainDocument {
- _newContents.addWindowController(self)
- }
- }
-
- override func layoutTabContentArea(_ frame: NSRect) {
- super.layoutTabContentArea(frame)
-
- self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
- }
-
- override func openDocument(_ sender: Any!) {
- guard let _window = self.window else {
- KMPrint("openDocument error: window is nil.", beep: true)
- return
- }
- if self.browser.tabCount() > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
- if !KMDataManager.default.isTabbingWin{
- KMDataManager.default.isTabbingWin = true
- let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
- tabbingWin.selectCallBack = { [weak self] continueOrNot in
- KMDataManager.default.isTabbingWin = false
- if continueOrNot {
- self?.reopenDocument(forPaths: nil)
- } else {
-
- }
- }
- self.km_beginSheet(windowC: tabbingWin)
- }
- return
- }
- NSOpenPanel.km_open_multi_success(_window) { panel in
- panel.allowedFileTypes = KMTools.imageExtensions + KMTools.pdfExtensions
- } completion: { urls in
- var imageUrls: [URL] = []
- for url in urls {
- if KMTools.isPDFType(url.pathExtension.lowercased()) {
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
-
- }
- } else {
- imageUrls.append(url)
- }
- }
- if imageUrls.isEmpty == false {
- NSApplication.ShowImageToPDFWindow(urls: imageUrls)
- }
- }
- }
- }
- // MARK: - KMInterfaceThemeChangedProtocol
- extension KMBrowserWindowController: KMInterfaceThemeChangedProtocol {
- func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
- Task { @MainActor in
- self.updateViewColor()
-
- let selector = #selector(interfaceThemeDidChanged)
- let mainWindow = self.window
- var responder = mainWindow?.firstResponder
- while (responder != nil) {
- // KMPrint("res: \(responder)")
- //
- if self.isEqual(to: responder) {
- responder = responder?.nextResponder
- continue
- }
- if let res = responder?.responds(to: selector), res {
- responder?.perform(selector, with: appearance)
- }
- responder = responder!.nextResponder
- }
- }
- }
- }
- // MARK: - KMToolbarRightViewDelegate
- extension KMBrowserWindowController: KMToolbarRightViewDelegate {
- func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
- self.trackEvent_upgrade()
- // KMComparativeTableViewController.show(window: self.window!, .upgrade)
- DispatchQueue.main.async {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- }
- }
-
- func userInfoButtonAction(_ sender: NSButton) {
- if KMLightMemberManager.manager.isLogin() {
- Task { @MainActor in
- if await KMLightMemberManager.manager.canUseAdvanced(needNetworking: true) {
- KMAccountInfoWindowController.show(window: self.window!)
- } else {
- KMLoginWindowController.show(window: self.window!)
- }
- }
- } else {
- KMLoginWindowController.show(window: self.window!)
- }
- }
-
- func homeRefreshButtonAction(_ sender: NSButton?) {
- self.layoutSubviews()
- }
-
- func homeUploadButtonAction(_ sender: NSButton) {
-
- }
-
- func homeMenuSortAction(_ sender: NSPopUpButton) {
-
- }
-
- func homeMenuFilterAction(_ sender: NSPopUpButton) {
-
- }
- }
- // MARK: - KMUploadFileDelegate
- extension KMBrowserWindowController: KMUploadFileDelegate {
- // override func cancelOperation(_ sender: Any?) {
- //
- // }
- }
- // MARK: - NSSearchFieldDelegate
- extension KMBrowserWindowController: NSSearchFieldDelegate {
- func controlTextDidChange(_ obj: Notification) {
-
- }
-
- func controlTextDidEndEditing(_ obj: Notification) {
-
- }
-
- func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
- var result = false
- return result
- }
- }
- // MARK: -
- // MARK: Menu Actions
- extension KMBrowserWindowController {
- func canResponseDocumentAction() -> Bool {
- if (self.browser == nil) {
- return false
- }
- guard let _ = self.browser.activeTabContents() as? KMMainDocument else {
- return false
- }
- return true
- }
- }
- // MARK: -
- // MARK: File Menu
- extension KMBrowserWindowController: NSMenuDelegate, NSMenuItemValidation {
- func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
- if (self.browser == nil) {
- return false
- }
- guard let action = menuItem.action else {
- return false
- }
- guard let document = self.browser.activeTabContents() as? KMMainDocument else {
- return false
- }
- if (KMSystemMenu.isFileSelector(sel: action)) {
- if action == KMSystemMenu.File.screenShotSelectAreaSelector ||
- action == KMSystemMenu.File.screenShotWindowSelector ||
- action == KMSystemMenu.File.screenShotFullScreenSelector ||
- action == KMSystemMenu.File.screenShotFullScreenDelaySelector {
- return true
- }
- if (document.isHome) {
- if (menuItem.action == KMSystemMenu.File.closeTagPageSelector ||
- menuItem.action == KMSystemMenu.File.propertySelector ||
- menuItem.action == KMSystemMenu.File.showInFinderSelector ||
- menuItem.action == KMSystemMenu.File.printSelector ||
- menuItem.action == KMSystemMenu.File.saveAsFlattenedPDFSelector) {
- return false
- }
- return document.homeViewController!.validateMenuItem(menuItem)
- } else {
- return document.mainViewController!.validateMenuItem(menuItem)
- }
- }
- if (KMSystemMenu.isEditSelector(sel: action)) {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- if (KMSystemMenu.isViewSelector(sel: action)) {
- if action == KMSystemMenu.Edit.changeFontSelector {
- return true
- } else {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- }
- if (KMSystemMenu.isAnnotationSelector(sel: action)) {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- if (KMSystemMenu.isPDFSelector(sel: action)) {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- if (KMSystemMenu.isGotoSelector(sel: action)) {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- if (KMSystemMenu.isToolSelector(sel: action)) {
- if action == KMSystemMenu.Tool.orderFrontNotesPanelSelector {
- if KMNotesPanelController.sharedControllerExists() {
- if let data = KMNotesPanelController.shared.window?.isVisible, data {
- menuItem.title = NSLocalizedString("Hide Note Type", comment: "Menu item title")
- } else {
- menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
- }
- } else {
- menuItem.title = NSLocalizedString("Show Note Type", comment: "Menu item title")
- }
- return true
- } else {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- }
- if (KMSystemMenu.isWindowSelector(sel: action)) {
- return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
- }
-
- if action == #selector(redactAction) {
- return document.isHome ? false : true
- }
- if action == #selector(pasteAsPlainText) {
- return document.isHome ? false : true
- }
- if action == #selector(addWatermark) || action == #selector(templateWatermark) || action == #selector(removeWatermark) || action == #selector(batchAddWatermark) || action == #selector(batchRemoveWatermark) {
- return document.isHome ? false : true
- }
-
- if action == #selector(addBackground) || action == #selector(removeBackground) || action == #selector(batchAddBackground) || action == #selector(batchRemoveBackground) || action == #selector(templateBackground) {
- return document.isHome ? false : true
- }
-
- if action == #selector(addHeaderFooter) || action == #selector(removeHeaderFooter) || action == #selector(batchAddHeaderFooter) || action == #selector(batchRemoveHeaderFooter) || action == #selector(templateHeaderFooter) {
- return document.isHome ? false : true
- }
-
- if action == #selector(addHeaderFooterBates) || action == #selector(removeHeaderFooterBates) || action == #selector(batchAddBates) || action == #selector(batchRemoveBates) || action == #selector(templateBates) {
- return document.isHome ? false : true
- }
- if action == #selector(alignLeft) || action == #selector(alignCenter) || action == #selector(alignRight){
- return document.isHome ? false : true
- }
- return true
- }
- }
- extension KMBrowserWindowController {
- @IBAction func menuItemAction_openFile(_ sender: Any) {
- super.openDocument(sender)
- }
-
- @IBAction func importFromFile(_ sender: Any) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.importFromFile(sender)
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.importFromFile(sender)
- }
- }
-
- @IBAction func openBlankPage(_ sender: Any) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.openBlankPage()
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.openBlankPage()
- }
- }
-
- @IBAction func importFromScanner(_ sender: Any) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.importFromScanner()
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.importFromScanner()
- }
- }
-
- @IBAction func menuItemAction_newTab(_ sender: Any) {
- self.openDocumentWindow()
- }
-
- @IBAction func pasteAsPlainText(_ sender: Any?) {
- KMPrint("pasteAsPlainText")
- }
-
- @IBAction func deselectAll(_ sender: Any?) {
- KMPrint("deselectAll")
- }
-
- @IBAction func searchPDF(_ sender: Any?) {
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.leftSideViewController.showSearchMode("")
- }
- }
- }
-
- @IBAction func changeColor(_ sender: Any?) {
- KMPrint("changeColor ...")
- }
-
- @IBAction func changeAttributes(_ sender: Any?) {
- KMPrint("changeAttributes ...")
- }
-
- @IBAction func alignLeft(_ sender: Any?) {
- KMPrint("alignLeft ...")
- }
-
- @IBAction func alignRight(_ sender: Any?) {
- KMPrint("alignRight ...")
- }
-
- @IBAction func alignCenter(_ sender: Any?) {
- KMPrint("alignCenter ...")
- }
-
- @IBAction func createNewNote(_ sender: Any?) {
- KMPrint("createNewNote ...")
- }
-
- @IBAction func toggleHideNotes(_ sender: Any?) {
- KMPrint("toggleHideNotes ...")
- }
-
- @IBAction func changeDisplaySinglePages(_ sender: Any?) {
- KMPrint("changeDisplaySinglePages ...")
- }
-
- @IBAction func changeDisplayContinuous(_ sender: Any?) {
- KMPrint("changeDisplayContinuous ...")
- }
-
- @IBAction func doGoToNextPage(_ sender: Any?) {
- KMPrint("doGoToNextPage ...")
- }
-
- @IBAction func doGoToPreviousPage(_ sender: Any?) {
- KMPrint("doGoToPreviousPage ...")
- }
-
- @IBAction func doGoToFirstPage(_ sender: Any?) {
- KMPrint("doGoToFirstPage ...")
- }
-
- @IBAction func doGoToLastPage(_ sender: Any?) {
- KMPrint("doGoToLastPage ...")
- }
-
- @IBAction func allGoToNextPage(_ sender: Any?) {
- KMPrint("allGoToNextPage ...")
- }
-
- @IBAction func allGoToPreviousPage(_ sender: Any?) {
- KMPrint("allGoToPreviousPage ...")
- }
-
- @IBAction func allGoToFirstPage(_ sender: Any?) {
- KMPrint("allGoToFirstPage ...")
- }
- @IBAction func allGoToLastPage(_ sender: Any?) {
- KMPrint("allGoToLastPage ...")
- }
-
- @IBAction func doGoToPage(_ sender: Any?) {
- KMPrint("doGoToPage ...")
- }
-
- @IBAction func doGoBack(_ sender: Any?) {
- KMPrint("doGoBack ...")
- }
- @IBAction func doGoForward(_ sender: Any?) {
- KMPrint("doGoForward ...")
- }
- @IBAction func doZoomToPhysicalSize(_ sender: Any?) {
- KMPrint("doZoomToPhysicalSize ...")
- }
- @IBAction func alternateZoomToFit(_ sender: Any?) {
- KMPrint("alternateZoomToFit ...")
- }
- @IBAction func doZoomToSelection(_ sender: Any?) {
- KMPrint("doZoomToSelection ...")
- }
- @IBAction func doAutoScale(_ sender: Any?) {
- KMPrint("doAutoScale ...")
- }
- // @IBAction func delete(_ sender: Any?) {
- // KMPrint("delete ...")
- // }
- // @IBAction func paste(_ sender: Any?) {
- // KMPrint("paste ...")
- // }
- @IBAction func alternatePaste(_ sender: Any?) {
- KMPrint("alternatePaste ...")
- }
- @IBAction func copy(_ sender: Any?) {
- KMPrint("copy ...")
- }
- @IBAction func cut(_ sender: Any?) {
- KMPrint("cut ...")
- }
- @IBAction func toggleFullscreen(_ sender: Any?) {
- KMPrint("toggleFullscreen ...")
- }
- @IBAction func toggleRightSidePane(_ sender: Any?) {
- KMPrint("toggleRightSidePane ...")
- }
- @IBAction func changeRightSidePaneState(_ sender: Any?) {
- KMPrint("changeRightSidePaneState ...")
- }
- @IBAction func changeFindPaneState(_ sender: Any?) {
- KMPrint("changeFindPaneState ...")
- }
- @IBAction func toggleSplitPDF(_ sender: Any?) {
- KMPrint("toggleSplitPDF ...")
- }
- @IBAction func search(_ sender: Any?) {
- KMPrint("search ...")
- }
- @IBAction func searchNotes(_ sender: Any?) {
- KMPrint("searchNotes ...")
- }
- @IBAction func password(_ sender: Any?) {
- KMPrint("password ...")
- }
- @IBAction func toggleCaseInsensitiveSearch(_ sender: Any?) {
- KMPrint("toggleCaseInsensitiveSearch ...")
- }
- @IBAction func toggleWholeWordSearch(_ sender: Any?) {
- KMPrint("toggleWholeWordSearch ...")
- }
- @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
- KMPrint("toggleCaseInsensitiveNoteSearch ...")
- }
- @IBAction func performFindPanelAction(_ sender: NSMenuItem) {
- var forward = true
- var findString: String?
- switch sender.tag {
- case 1:
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if document.isHome == false {
- document.mainViewController?.toolbarController.showFindBar()
- }
- }
- case 3:
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if document.isHome == false {
- document.mainViewController?.toolbarController.showFindString(forward: false)
- }
- }
- case 2:
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if document.isHome == false {
- document.mainViewController?.toolbarController.showFindString(forward: true)
- }
- }
- case 7:
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if document.isHome == false {
- document.mainViewController?.toolbarController.showAllAction()
- }
- }
- default: break
-
- }
- }
- @IBAction func scrollUp(_ sender: Any?) {
- KMPrint("scrollUp ...")
- }
- @IBAction func scrollDown(_ sender: Any?) {
- KMPrint("scrollDown ...")
- }
- @IBAction func scrollRight(_ sender: Any?) {
- KMPrint("scrollRight ...")
- }
- @IBAction func scrollLeft(_ sender: Any?) {
- KMPrint("scrollLeft ...")
- }
- @IBAction func selectSelectedNote(_ sender: Any?) {
- KMPrint("selectSelectedNote ...")
- }
- @IBAction func goToSelectedOutlineItem(_ sender: Any?) {
- KMPrint("goToSelectedOutlineItem ...")
- }
- @IBAction func goToSelectedFindResults(_ sender: Any?) {
- KMPrint("goToSelectedFindResults ...")
- }
- @IBAction func toggleSelectedSnapshots(_ sender: Any?) {
- KMPrint("toggleSelectedSnapshots ...")
- }
- @IBAction func selfSignProfile(_ sender: Any?) {
- KMPrint("selfSignProfile ...")
- }
- @IBAction func link(_ sender: Any?) {
- KMPrint("link ...")
- }
- @IBAction func insertPage(_ sender: Any?) {
- KMPrint("insertPage ...")
- }
- @IBAction func split(_ sender: Any?) {
- KMPrint("split ...")
- }
- @IBAction func comparison(_ sender: Any?) {
- KMPrint("comparison ...")
- }
- @IBAction func contentComparison(_ sender: Any?) {
- KMPrint("contentComparison ...")
- }
- @IBAction func coverageComparison(_ sender: Any?) {
- KMPrint("coverageComparison ...")
- }
- @IBAction func readMode(_ sender: Any?) {
- KMPrint("readMode ...")
- }
- @IBAction func changeFormType(_ sender: Any?) {
- KMPrint("changeFormType ...")
- }
- @IBAction func changeSelfSignType(_ sender: Any?) {
- KMPrint("changeSelfSignType ...")
- }
- @IBAction func clearAllForm(_ sender: Any?) {
- KMPrint("clearAllForm ...")
- }
- @IBAction func thumbnailSizeScaling(_ sender: Any?) {
- KMPrint("thumbnailSizeScaling ...")
- }
- @IBAction func redactAction(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if document.isHome == false {
- document.mainViewController?.menuItemAction_redact(sender)
- }
- }
- }
- }
- // MARK: - KMSystemFileMenuProtocol
- extension KMBrowserWindowController: KMSystemFileMenuProtocol {
-
- func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
- }
- }
- }
-
- func menuItemClick_mergePDF(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemClick_mergePDF(sender)
- } else {
- document.mainViewController?.menuItemClick_mergePDF(sender)
- }
- }
- }
-
- func menuItemClick_Compress(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemClick_Compress(sender)
- } else {
- document.mainViewController?.menuItemClick_Compress(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToWord(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToWord(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToWord(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToExcel(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToExcel(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToExcel(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToPPT(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToPPT(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToPPT(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToRTF(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToRTF(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToRTF(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToHTML(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToHTML(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToHTML(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToText(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToText(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToText(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToCSV(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToCSV(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToCSV(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToImage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToImage(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToImage(sender)
- }
- }
- }
-
- func menuItemClick_SettingPassword(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemClick_SettingPassword(sender)
- } else {
- document.mainViewController?.menuItemClick_SettingPassword(sender)
- }
- }
- }
-
- func menuItemClick_RemovePassword(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemClick_RemovePassword(sender)
- }
- }
-
- func menuItemAction_closeWindow(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_closeWindow(sender)
- } else {
- document.mainViewController?.menuItemAction_closeWindow(sender)
- }
- }
- }
-
- func menuItemAction_closeAllWindows(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_closeAllWindows(sender)
- } else {
- document.mainViewController?.menuItemAction_closeAllWindows(sender)
- }
- }
- }
-
- func menuItemAction_closeTagPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_closeTagPage(sender)
- }
- }
-
- func menuItemAction_showInFinder(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_showInFinder(sender)
- }
- }
-
- func menuItemAction_property(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_property(sender)
- }
- }
-
- func menuItemAction_print(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_print(sender)
- }
- }
-
- func isEncapsulatedPostScriptData(_ data: Data) -> Bool {
- let epsHeaderData = Data(bytes: [69, 80, 83, 70, 45], count: 5)
- let rg: Range = (14..<20)
- return (data.count >= 20 && (data.range(of: epsHeaderData, options: .anchored, in: rg) != nil))
- }
-
- func convertTIFFDataToPDF(_ tiffData: Data) -> Data? {
- guard let imsrc = CGImageSourceCreateWithData(tiffData as CFData, [kCGImageSourceTypeIdentifierHint: kUTTypeTIFF] as CFDictionary), CGImageSourceGetCount(imsrc) > 0, let cgImage = CGImageSourceCreateImageAtIndex(imsrc, 0, nil) else { return nil }
- let pdfData = NSMutableData(capacity: tiffData.count)
- let consumer = CGDataConsumer(data: pdfData! as CFMutableData)!
-
- var rect = CGRect(x: 0, y: 0, width: CGFloat(cgImage.width), height: CGFloat(cgImage.height))
- let ctxt = CGContext(consumer: consumer, mediaBox: &rect, nil)
- ctxt!.beginPDFPage(nil)
- ctxt!.draw(cgImage, in: rect)
- ctxt!.endPDFPage()
- ctxt!.flush()
-
- return pdfData as? Data
- }
-
- func openDocumentWithImageFromPasteboard(_ pboard: NSPasteboard, error outError: AutoreleasingUnsafeMutablePointer<NSError?>?) -> Any? {
- var document: CPDFDocument? = nil
- var data: Data? = nil
-
- if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.pdf.rawValue]) {
- // pboard.types
- data = pboard.data(forType: NSPasteboard.PasteboardType.pdf)
- } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.postScript.rawValue]) {
- // pboard.types
- data = pboard.data(forType: NSPasteboard.PasteboardType.postScript)
- } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.tiff.rawValue]) {
- // pboard.types
- data = convertTIFFDataToPDF(pboard.data(forType: NSPasteboard.PasteboardType.tiff) ?? Data())
- } else {
- let images = pboard.readObjects(forClasses: [NSImage.self], options: [:])
- let strings = pboard.readObjects(forClasses: [NSAttributedString.self], options: [:])
- if images?.count ?? 0 > 0 {
- data = convertTIFFDataToPDF((images![0] as AnyObject).tiffRepresentation!)
- } else if strings?.count ?? 0 > 0 {
- data = KMOCTool.convertStringsToPDF(withString: strings ?? [""]) // convertStringsToPDF(strings!)
- }
- }
-
- if let data = data {
- _ = NSDocumentController.shared
- document = CPDFDocument(data: data)
-
- let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
- let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
- let filePath = savePath.deletingLastPathComponent
- if FileManager.default.fileExists(atPath: filePath) == false {
- try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
- }
-
- document?.write(to: URL(fileURLWithPath: savePath))
- NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
- if error != nil {
- NSApp.presentError(error!)
- } else {
- if document is KMMainDocument {
- let newDocument = document
- (newDocument as! KMMainDocument).isNewCreated = true
- }
- }
- }
-
- } else if let outError = outError {
- outError.pointee = NSError(domain: "SKDocumentErrorDomain", code: 3, userInfo: [NSLocalizedDescriptionKey: NSLocalizedString("Unable to load data from clipboard", comment: "Error description")])
-
- }
-
- return document
- }
- func openDocument(withURLFromPasteboard pboard: NSPasteboard, showNotes: Bool, error outError: inout NSError?) -> Any? {
- let theURLs = NSURL.readURLs(from: pboard)
- let url = theURLs?.count ?? 0 > 0 ? theURLs?[0] : nil
- let theURL: NSURL? = url as? NSURL
- var documentC = NSDocumentController.shared
- var document: NSDocument? = nil
- if (theURL as AnyObject).isFileURL == true {
- var _: NSError? = nil
- let type = try? documentC.typeForContents(of: theURL as! URL)//ForContents(ofURL: theURL, error: &error)
-
- if showNotes == false || NSDocument.readableTypes.contains(type ?? "") {
- documentC.openDocument(withContentsOf: theURL as! URL, display: true, completionHandler: { resultDocument, success, err in
- document = resultDocument
- })//openDocument(withContentsOfURL: theURL, display: true, error: &outError)
- } else if NSDocument.readableTypes.contains(type ?? "") {
- for doc in documentC.documents {
- let sel = NSSelectorFromString("sourceFileURL")
- if doc.responds(to: sel) && doc.fileURL == theURL as? URL {
- document = doc
- break
- }
- }
- if let document: NSDocument = document {
- document.showWindows()
- } else {
- var data: Data? = nil
-
- // if NSWorkspace.shared.type(type ?? "", conformsToType: KMPDFBundleDocumentType) {
- // let skimFileURL = FileManager.default.exte
- // data = skimFileURL != nil ? try? Data(contentsOf: skimFileURL!) : nil
- // } else {
- // data = SKNExtendedAttributeManager.shared().extendedAttributeNamed(SKIM_NOTES_KEY, atPath: theURL.path, traverseLink: true, error: &error)
- // }
- // let documentNew: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
-
- if let document = try? documentC.makeUntitledDocument(ofType: KMNotesDocumentType) {
- document.fileURL = URL(fileURLWithPath: theURL?.path ?? "")
-
- // if data == nil || document.read(fromData: data!, ofType: SKNotesDocumentType, error: &error) {
- documentC.addDocument(document)
- document.makeWindowControllers()
- document.showWindows()
- // } else {
- // document = nil
- // if let error = error {
- // outError = error
- // }
- // }
- }
- }
- }
- }
- // else if showNotes == false && theURL != nil {
- // document = SKDownloadController.shared().addDownload(for: theURL!)
- // } else if outError != nil {
- // outError = NSError.readPasteboardError(withLocalizedDescription: NSLocalizedString("Unable to load data from clipboard", comment: "Error description"))
- // }
-
- return document
- }
-
- @IBAction func newDocumentFromClipboard(_ sender: Any?) {
- KMPrint("newDocumentFromClipboard")
- var error: NSError?
- let pboard = NSPasteboard.general
- var document = openDocumentWithImageFromPasteboard(pboard, error: &error)
-
- if document == nil{
- document = openDocument(withURLFromPasteboard: pboard, showNotes: false, error: &error)
- }
- }
-
- @IBAction func newDocumentFromImage(_ sender: Any?) {
- KMPrint("importFromWebPage")
- createPDFFromImage()
- }
-
- @IBAction func importFromWebPage(_ sender: Any?) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.importFromWebPage()
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.importFromWebPage()
- }
- }
-
- @IBAction func screenShot_SelectArea(_ sender: Any?) {
- KMScreenShotHandler.beginScreenshot_SelectRectWithCompleteHandler { ima in
- if let image = ima {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
- let folderPath = self.createBaseFoldPath()
- let savePathOld = folderPath + "/screenShot.pdf"
- var savePath = self.filePathCheck(path: savePathOld)
- let newDocument = CPDFDocument()
- _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
- let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
- if writeSuccess ?? false {
- if self.checkOpenNewDocument(path: savePath) {
- self.savePdf(savePath)
- }
- // try? FileManager.default.removeItem(atPath: savePath)
- } else {
-
- }
- }
- }
- }
- }
- func checkOpenNewDocument(path: String) -> Bool {
- if !IAPProductsManager.default().isAvailableAllFunction() && self.browser.tabCount() > 1 {
- let preferenceNoteShow = UserDefaults.standard.bool(forKey: KMTabbingHintShowFlag)
- if preferenceNoteShow {
- menuItemAction_newTagPageToNewWindow("")
- } else {
- if !KMDataManager.default.isTabbingWin{
- KMDataManager.default.isTabbingWin = true
- let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
- tabbingWin.selectCallBack = {[weak self] continueOrNot in
- KMDataManager.default.isTabbingWin = false
- if continueOrNot {
- self?.reopenDocumentForNewWindow(savePath: path)
- } else {
-
- }
- }
- self.km_beginSheet(windowC: tabbingWin)
- }
- }
- return false
- }
- return true
- }
-
- func reopenDocumentForNewWindow(savePath: String) {
- let browser = KMBrowser.init() as KMBrowser
- browser.windowController = KMBrowserWindowController.init(browser: browser)
- browser.addHomeTabContents()
- browser.windowController.showWindow(self)
- self.savePdf(savePath)
- }
- func filePathCheck(path: String) -> String {
- var i: Int = 0
- let fileURL = URL(fileURLWithPath: path)
- var newPath: String = path
- let fileManager = FileManager.default
- while fileManager.fileExists(atPath: newPath) {
- i += 1
-
- newPath = fileURL.deletingPathExtension().path
- newPath.append("(\(i))")
- newPath.append(".")
- newPath.append(fileURL.pathExtension)
- }
- return newPath
- }
- @IBAction func screenShot_Window(_ sender: Any?) {
- KMPrint("screenShot_Window")
- KMScreenShotHandler.beginScreenShot_SelectWindowCompleteHandler { ima in
- if let image = ima {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
- let folderPath = self.createBaseFoldPath()
- let savePathOld = folderPath + "/screenShot.pdf"
- var savePath = self.filePathCheck(path: savePathOld)
- let newDocument = CPDFDocument()
- _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
- let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
- if writeSuccess == true {
- if self.checkOpenNewDocument(path: savePath) {
- self.savePdf(savePath)
- }
- // try? FileManager.default.removeItem(atPath: savePath)
- } else {
-
- }
- }
- }
- }
- }
- @IBAction func screenShot_FullScreenDelay(_ sender: Any?) {
- KMPrint("screenShot_FullScreenDelay")
- KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(3) { ima in
- if let image = ima {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
- let folderPath = self.createBaseFoldPath()
- let savePathOld = folderPath + "/screenShot.pdf"
-
- var savePath = self.filePathCheck(path: savePathOld)
- let newDocument = CPDFDocument()
- _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
- let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
- if writeSuccess == true {
- if self.checkOpenNewDocument(path: savePath) {
- self.savePdf(savePath)
- }
- // try? FileManager.default.removeItem(atPath: savePath)
- } else {
-
- }
- }
- }
- }
- }
- @IBAction func screenShot_FullScreen(_ sender: Any?) {
- KMPrint("screenShot_FullScreen")
- KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(0) { ima in
- if let image = ima {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
- let folderPath = self.createBaseFoldPath()
- let savePathOld = folderPath + "/screenShot.pdf"
-
- var savePath = self.filePathCheck(path: savePathOld)
- let newDocument = CPDFDocument()
- _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
- let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
- if writeSuccess == true {
- self.savePdf(savePath)
- // try? FileManager.default.removeItem(atPath: savePath)
- } else {
-
- }
- }
- }
- }
- }
-
- func createBaseFoldPath() -> String {
- let folderPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last?.appending("/\(Bundle.main.bundleIdentifier!)")
- if (FileManager.default.fileExists(atPath: folderPath!) == false) {
- try?FileManager.default.createDirectory(atPath: folderPath!, withIntermediateDirectories: false)
- }
- return folderPath ?? ""
- }
- }
- // MARK: - KMSystemViewMenuProtocol
- extension KMBrowserWindowController: KMSystemViewMenuProtocol {
- func createPDFFromImage() {
- let openPanel = NSOpenPanel()
- openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
- openPanel.allowsMultipleSelection = true
- openPanel.message = NSLocalizedString("Select images to create a new document. To select multiple files press cmd ⌘ button on keyboard and click on the target files one by one.", comment: "")
- openPanel.beginSheetModal(for: NSApp.mainWindow!) { response in
- if response == .OK {
- self.creatPdfFromImg(urls: openPanel.urls)
- }
- }
- }
- func creatPdfFromImg(urls: Array<URL>) {
- // let savePath = self.newDocumentTempSavePath("convertToPDF.pdf")
- let pdf = CPDFDocument()
- // var isSucceed = true
-
- let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
- let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
- let filePath = savePath.deletingLastPathComponent
- if FileManager.default.fileExists(atPath: filePath) == false {
- try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
- }
-
- for fileURL in urls {
- if let imag = NSImage(contentsOfFile: fileURL.path ) {
- _ = pdf?.km_insertPage(imag.size, withImage: fileURL.path , at: pdf?.pageCount ?? 0)
- pdf?.write(to: URL(fileURLWithPath: savePath))
- }
- }
- NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
- if error != nil {
- NSApp.presentError(error!)
- } else {
- if document is KMMainDocument {
- let newDocument = document
- (newDocument as! KMMainDocument).isNewCreated = true
- }
- }
- // self.homeContentView?.reloadData()
- }
- }
-
- func createPdfWithParam() {
- let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
- let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
- let filePath = savePath.deletingLastPathComponent
- if FileManager.default.fileExists(atPath: filePath) == false {
- try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
- }
-
- let pdfDocument = CPDFDocument()
- pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
- pdfDocument?.write(to: URL(fileURLWithPath: savePath))
- NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
- if error != nil {
- NSApp.presentError(error!)
- } else {
- if document is KMMainDocument {
- let newDocument = document
- (newDocument as! KMMainDocument).isNewCreated = true
- }
- }
- // self.homeContentView?.reloadData()
- }
- }
-
- func savePdf(_ filePath: String) -> Void {
- let docVc = KMDocumentController.shared
-
- docVc.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
- if error != nil {
- NSApp.presentError(error!)
- } else {
- if document is KMMainDocument {
- let newDocument = document
- (newDocument as! KMMainDocument).isNewCreated = true
- }
- }
- }
- }
-
- func newDocumentTempSavePath(_ fileName: String) -> String {
- let searchPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last
- let append1 = searchPath?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!)
- let append2 = append1!.stringByAppendingPathComponent(String(format: "%@", fileName))
- return append2
- }
-
- func fetchUniquePath(_ originalPath: String) -> String {
- var path = originalPath
- let dManager = FileManager.default
- if !dManager.fileExists(atPath: path) {
- if path.extension.count < 1 {
- path = path.stringByAppendingPathExtension("pdf")
- }
- return path
- } else {
- let originalFullFileName = path.lastPathComponent
- let originalFileName = path.lastPathComponent.deletingPathExtension.lastPathComponent
- let originalExtension = path.extension
- let startIndex: Int = 0
- let endIndex: Int = startIndex + originalPath.count - originalFullFileName.count - 1
- let fileLocatePath = originalPath.substring(to: endIndex)
- var i = 1
- while (1 != 0) {
- var newName = String(format: "%@%ld", originalFileName, i)
- newName = String(format: "%@%@", newName, originalExtension)
- let newPath = fileLocatePath.stringByAppendingPathComponent(newName)
- if !dManager.fileExists(atPath: newPath) {
- return newPath
- } else {
- i+=1
- continue
- }
- }
- }
- }
-
- func menuItemAction_adjustWidth(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_adjustWidth(sender)
- }
- }
-
- func menuItemAction_adjustPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_adjustPage(sender)
- }
- }
-
- func menuItemAction_size(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_size(sender)
- }
- }
-
- func menuItemAction_zoomOut(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_zoomOut(sender)
- }
- }
-
- func menuItemAction_zoomIn(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_zoomIn(sender)
- }
- }
-
- func menuItemAction_singlePage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_singlePage(sender)
- }
- }
-
- func menuItemAction_singlePageContinue(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_singlePageContinue(sender)
- }
- }
-
- func menuItemAction_doublePage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_doublePage(sender)
- }
- }
-
- func menuItemAction_doublePageContinue(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_doublePageContinue(sender)
- }
- }
-
- func menuItemAction_bookMode(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_bookMode(sender)
- }
- }
-
- func menuItemAction_readMode(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_readMode(sender)
- }
- }
-
- func menuItemAction_showSplitPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_showSplitPage(sender)
- }
- }
-
- func menuItemAction_rotateLeft(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_rotateLeft(sender)
- }
- }
-
- func menuItemAction_rotateRight(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_rotateRight(sender)
- }
- }
-
- func menuItemAction_rotateAllPageLeft(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_rotateAllPageLeft(sender)
- }
- }
-
- func menuItemAction_rotateAllPageRight(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_rotateAllPageRight(sender)
- }
- }
-
- func menuItemAction_view_readMode(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_view_readMode(sender)
- }
- }
-
- func menuItemAction_hiddenLeftSide(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_hiddenLeftSide(sender)
- }
- }
-
- func menuItemAction_hiddenRightSide(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_hiddenRightSide(sender)
- }
- }
-
- func menuItemAction_thumai(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_thumai(sender)
- }
- }
-
- func menuItemAction_outline(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_outline(sender)
- }
- }
-
- func menuItemAction_bookmark(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_bookmark(sender)
- }
- }
-
- func menuItemAction_annotation(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_annotation(sender)
- }
- }
-
- func menuItemAction_search(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_search(sender)
- }
- }
-
- func menuItemAction_hiddenPageIndicator(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_hiddenPageIndicator(sender)
- }
- }
-
- @IBAction func togglePresentation(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.togglePresentation(sender)
- }
- }
-
- @IBAction func chooseTransition(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.chooseTransition(sender)
- }
- }
-
- @IBAction func toggleAutoFlow(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleAutoFlow(sender)
- }
- }
- @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.chooseAutoFlowSetting(sender)
- }
- }
-
- @IBAction func toggleReadingBar(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleReadingBar(sender)
- }
- }
-
- @IBAction func toggleLeftSidePane(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleLeftSidePane(sender)
- }
- }
-
- @IBAction func changeLeftSidePaneState(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.changeLeftSidePaneState(sender)
- }
- }
-
- @IBAction func splitViewAction(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.splitViewAction(sender)
- }
- }
-
- @IBAction func themesColor(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.themesColor(sender)
- }
- }
-
- @IBAction func toggleStatusBar(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleStatusBar(sender)
- }
- }
-
- @IBAction func toggleToolbarShow(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleToolbarShow(sender)
- }
- }
- }
- // MARK: - KMSystemEditMenuProtocol
- extension KMBrowserWindowController: KMSystemEditMenuProtocol {
- func menuItemAction_find(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_find(sender)
- }
- }
-
- @IBAction func changeFont(_ sender: Any?) {
- KMPrint("changeFont ...")
- }
- }
- // MARK: - Annotation Menu
- extension KMBrowserWindowController {
- @IBAction func menuItemAction_highlight(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_highlight(sender)
- }
- }
- @IBAction func menuItemAction_underline(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_underline(sender)
- }
- }
-
- @IBAction func menuItemAction_deleteLine(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_deleteLine(sender)
- }
- }
-
- @IBAction func menuItemAction_freehand(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_freehand(sender)
- }
- }
- @IBAction func menuItemAction_text(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_text(sender)
- }
- }
-
- @IBAction func menuItemAction_note(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_note(sender)
- }
- }
-
- @IBAction func menuItemAction_squre(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_squre(sender)
- }
- }
- @IBAction func menuItemAction_circle(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_circle(sender)
- }
- }
-
- @IBAction func menuItemAction_arrow(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_arrow(sender)
- }
- }
-
- @IBAction func menuItemAction_line(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_line(sender)
- }
- }
- // link
-
- @IBAction func menuItemAction_link(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_link(sender)
- }
- }
-
- @IBAction func menuItemAction_linkPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_linkPage(sender)
- }
- }
-
- // stamp
-
- @IBAction func menuItemAction_stamp(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_stamp(sender)
- }
- }
-
- @IBAction func notesLink(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.notesLink(sender)
- }
- }
-
- @IBAction func notesStamp(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.notesStamp(sender)
- }
- }
-
- @IBAction func menuItemAction_signure(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_signure(sender)
- }
- }
-
- @IBAction func image(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.image(sender)
- }
- }
-
- @IBAction func table(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.table(sender)
- }
- }
-
- @IBAction func addForm(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.addForm(sender)
- }
- }
-
- @IBAction func editNote(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.editNote(sender)
- }
- }
-
- @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_hiddenAllAnnotation(sender)
- }
- }
-
- @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_clearAllAnnotation(sender)
- }
- }
- }
- // MARK: - KMSystemPDFMenuProtocol
- extension KMBrowserWindowController: KMSystemPDFMenuProtocol {
- @IBAction func changeDisplayMode(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.changeDisplayMode(sender)
- }
- }
-
- @IBAction func toggleDisplayAsBook(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleDisplayAsBook(sender)
- }
- }
-
- @IBAction func toggleDisplayPageBreaks(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleDisplayPageBreaks(sender)
- }
- }
-
- @IBAction func changeDisplayBox(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.changeDisplayBox(sender)
- }
- }
-
- @IBAction func toggleAutoScale(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.toggleAutoScale(sender)
- }
- }
-
- @IBAction func doZoomToActualSize(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.doZoomToActualSize(sender)
- }
- }
-
- @IBAction func doZoomToFit(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.doZoomToFit(sender)
- }
- }
-
- @IBAction func doZoomIn(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.doZoomIn(sender)
- }
- }
- @IBAction func doZoomOut(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.doZoomOut(sender)
- }
- }
-
- @IBAction func doMarqueeZoomTool(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.doMarqueeZoomTool(sender)
- }
- }
-
- @IBAction func highlightFormFiled(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.highlightFormFiled(sender)
- }
- }
- @IBAction func highlightLinks(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.highlightLinks(sender)
- }
- }
-
- @IBAction func resetForm(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.resetForm(sender)
- }
- }
-
- @IBAction func removeAllAnnotation(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.removeAllAnnotation(sender)
- }
- }
-
- @IBAction func savePDFSettingToDefaults(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.savePDFSettingToDefaults(sender)
- }
- }
- }
- // MARK: - KMSystemGotoMenuProtocol
- extension KMBrowserWindowController: KMSystemGotoMenuProtocol {
- func menuItemAction_nextPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_nextPage(sender)
- }
- }
-
- func menuItemAction_forwardPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_forwardPage(sender)
- }
- }
-
- func menuItemAction_firstPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_firstPage(sender)
- }
- }
-
- func menuItemAction_lastPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_lastPage(sender)
- }
- }
-
- func menuItemAction_forward(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_forward(sender)
- }
- }
-
- func menuItemAction_goback(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_goback(sender)
- }
- }
-
- func menuItemAction_gotoPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_gotoPage(sender)
- }
- }
-
- @IBAction func goToMarkedPage(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.goToMarkedPage(sender)
- }
- }
- @IBAction func markPage(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.markPage(sender)
- }
- }
- }
- // MARK: - KMSystemToolMenuProtocol
- extension KMBrowserWindowController: KMSystemToolMenuProtocol {
- @IBAction func getInfo(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.getInfo(sender)
- }
- }
-
- func orderFrontNotesPanel(_ sender: Any?) {
- let windowC = KMNotesPanelController.shared
- if let win = windowC.window {
- if win.isVisible {
- win.orderOut(sender)
- } else {
- win.orderFront(sender)
- }
- }
- }
-
- func menuItemAction_scrolTool(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_scrolTool(sender)
- }
- }
-
- func menuItemAction_zoomOutTool(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_zoomOutTool(sender)
- }
- }
-
- func menuItemAction_selectTool(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_selectTool(sender)
- }
- }
-
- @IBAction func changeToolMode(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.changeToolMode(sender)
- }
- }
- }
-
- @IBAction func compression(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.compression(sender)
- }
- }
- }
-
- @IBAction func merge(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.merge(sender)
- }
- }
- }
-
- @IBAction func convert(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.convert(sender)
- }
- }
- }
-
- @IBAction func imageToPDF(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.imageToPDF(sender)
- }
- }
- }
-
- @IBAction func ocr(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.ocr(sender)
- }
- }
- }
-
- @IBAction func extractImage(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.extractImage(sender)
- }
- }
- }
-
- @IBAction func pageEdit(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.pageEdit(sender)
- }
- }
- }
-
- @IBAction func textEditAction(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.textEditAction(sender)
- }
- }
- }
-
- @IBAction func security(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.security(sender)
- }
- }
- }
-
- @IBAction func decryption(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.decryption(sender)
- }
- }
- }
-
- @IBAction func cropAll(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.cropAll(sender)
- }
- }
- }
-
- @IBAction func crop(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.crop(sender)
- }
- }
- }
- @IBAction func autoCropAll(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.autoCropAll(sender)
- }
- }
- }
- @IBAction func smartAutoCropAll(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.smartAutoCropAll(sender)
- }
- }
- }
- @IBAction func cropOptionsModel(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- // document.mainViewController?.cropOptionsModel(sender)
- }
- }
- }
-
- @IBAction func selectToolModel(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.selectToolModel(sender)
- }
- }
- }
-
- @IBAction func takeSnapshot(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.takeSnapshot(sender)
- }
- }
- }
-
- @IBAction func takeSnapshotSelectContent(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.takeSnapshotSelectContent(sender)
- }
- }
- }
-
- @IBAction func changeAnnotationMode(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.changeAnnotationMode(sender)
- }
- }
- }
-
- @IBAction func addBackground(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.addBackground(sender)
- }
- }
- }
- @IBAction func removeBackground(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.removeBackground(sender)
- }
- }
- }
-
- @IBAction func addWatermark(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.addWatermark(sender)
- }
- }
- }
- @IBAction func editWatermark(_ sender: Any?) {
- KMPrint("editWatermark ...")
- }
- @IBAction func batchAddWatermark(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchAddWatermark(sender)
- }
- }
- }
- @IBAction func batchRemoveWatermark(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchRemoveWatermark(sender)
- }
- }
- }
- @IBAction func removeWatermark(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.removeWatermark(sender)
- }
- }
- }
- @IBAction func templateWatermark(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.templateWatermark(sender)
- }
- }
- }
- @IBAction func batchAddBackground(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchAddBackground(sender)
- }
- }
- }
- @IBAction func batchRemoveBackground(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchRemoveBackground(sender)
- }
- }
- }
- @IBAction func templateBackground(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.templateBackground(sender)
- }
- }
- }
-
- @IBAction func addHeaderFooter(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.addHeaderFooter(sender)
- }
- }
- }
- @IBAction func removeHeaderFooter(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.removeHeaderFooter(sender)
- }
- }
- }
- @IBAction func batchAddHeaderFooter(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchAddHeaderFooter(sender)
- }
- }
- }
- @IBAction func batchRemoveHeaderFooter(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchRemoveHeaderFooter(sender)
- }
- }
- }
- @IBAction func templateHeaderFooter(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.templateHeaderFooter(sender)
- }
- }
- }
- @IBAction func addHeaderFooterBates(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.addHeaderFooterBates(sender)
- }
- }
- }
- @IBAction func removeHeaderFooterBates(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.removeHeaderFooterBates(sender)
- }
- }
- }
- @IBAction func batchAddBates(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchAddBates(sender)
- }
- }
- }
- @IBAction func batchRemoveBates(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.batchRemoveBates(sender)
- }
- }
- }
- @IBAction func templateBates(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.templateBates(sender)
- }
- }
- }
-
- @IBAction func togglePoster(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.togglePoster(sender)
- }
- }
- }
- @IBAction func toggleMultiple(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.toggleMultiple(sender)
- }
- }
- }
- @IBAction func toggleBooklet(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.toggleBooklet(sender)
- }
- }
- }
-
- @IBAction func rotateRight(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.rotateRight(sender)
- }
- }
- }
- @IBAction func rotateLeft(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.rotateLeft(sender)
- }
- }
- }
- @IBAction func rotateAllRight(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.rotateAllRight(sender)
- }
- }
- }
- @IBAction func rotateAllLeft(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.rotateAllLeft(sender)
- }
- }
- }
-
- @IBAction func autoSelectContent(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.autoSelectContent(sender)
- }
- }
- }
- }
- // MARK: - KMSystemWindowMenuRrotocol
- extension KMBrowserWindowController: KMSystemWindowMenuRrotocol {
- func menuItemAction_showForwardTagPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_showForwardTagPage(sender)
- } else {
- document.mainViewController?.menuItemAction_showForwardTagPage(sender)
- }
- }
- }
-
- func menuItemAction_showNextTagPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_showNextTagPage(sender)
- } else {
- document.mainViewController?.menuItemAction_showNextTagPage(sender)
- }
- }
- }
-
- func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_newTagPageToNewWindow(sender)
- } else {
- document.mainViewController?.menuItemAction_newTagPageToNewWindow(sender)
- }
- }
- }
-
- func menuItemAction_mergeAllWindow(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_mergeAllWindow(sender)
- } else {
- document.mainViewController?.menuItemAction_mergeAllWindow(sender)
- }
- }
- }
-
- @IBAction func performFit(_ sender: Any?) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.performFit(sender)
- }
- }
- }
- }
- // MARK: - Analytics (埋点)
- extension KMBrowserWindowController {
- func trackEvent_upgrade() -> Void {
- KMAnalytics.trackEvent(eventName: "Btn_Tbr_Upgrade", parameters: [
- KMAnalytics.Parameter.categoryKey : KMAnalytics.Category.tbr,
- KMAnalytics.Parameter.labelKey : KMAnalytics.Label.tbr_Btn], platform: .AppCenter, appTarget: .all)
- }
- }
|