12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221 |
- //
- // 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 DEBUG
- // if self.browser.tabStripModel.count() > 1 {
- // self.browser.windowDidBeginToClose()
- // return false
- // }
- //#else
- // if let cnt = self.browser?.tabStripModel?.count(), cnt > 1 {
- // if self.browser?.window != nil {
- // self.browser?.windowDidBeginToClose()
- // }
- // return false
- // }
- //#endif
- if let cnt = self.browser?.tabStripModel?.count(), cnt > 1 {
- if self.browser?.window != nil {
- 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 let cnt = self.browser?.tabCount(), cnt > 1{
- if !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
- }
- if KMPreference.shared.openDocumentType == .newWindow {
- self.reopenDocument(forPaths: nil)
- 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 = self.browser?.activeTabContents() as? KMMainDocument
- if let data = document?.isHome, data {
- document?.homeViewController?.importFromFile(sender)
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.importFromFile(sender)
- }
- }
-
- @IBAction func openBlankPage(_ sender: Any) {
- let document = self.browser?.activeTabContents() as? KMMainDocument
- if let data = document?.isHome, data {
- document?.homeViewController?.openBlankPage()
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.openBlankPage()
- }
- }
-
- @IBAction func importFromScanner(_ sender: Any) {
- let document = self.browser?.activeTabContents() as? KMMainDocument
- if let data = document?.isHome, data {
- 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!.closePDF()
-
- 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 = self.browser?.activeTabContents() as? KMMainDocument
- if let data = document?.isHome, data {
- 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 {
- let tabCount = self.km_browser?.tabCount() ?? 0
- if tabCount > 1{
- if !IAPProductsManager.default().isAvailableAllFunction() {
- 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
- }else {
- if KMPreference.shared.openDocumentType == .newWindow {
- self.reopenDocumentForNewWindow(savePath: path)
- 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(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 {
- if self.checkOpenNewDocument(path: savePath) {
- self.savePdf(savePath)
- }
- // try? FileManager.default.removeItem(atPath: savePath)
- } else {
-
- }
- }
- }
- }
- }
- @IBAction func screenShot_FullScreen(_ sender: Any?) {//延迟3秒
- KMPrint("screenShot_FullScreen")
- 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 {
- 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)
- }
- }
|