1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259 |
- //
- // 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: NSMakeRect(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 = NSWidth(self.rightToolbarItemView.frame) - rect.size.width - 8
- rect.origin.y = (NSHeight(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
- let winC = self?.kmCurrentWindowC as? KMTabbingHintWindowController
- let newTab = winC?.newTabInWindowButton.state == .on
- if continueOrNot {
- if IAPProductsManager.default().isAvailableAllFunction() && newTab {
- self?.openDocumentWindow()
- } else {
- 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)
-
- _newContents.mainViewController?.showMeasureFloatingWindowsIfNeed()
- }
- if let _userInfo = notification.userInfo, let _oldContents = _userInfo[CTTabContentsUserInfoKey] as? KMMainDocument {
- _oldContents.mainViewController?.hideMeasureFloatingWindows()
- }
- }
-
- 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
- }
-
- let childWins = self.window?.childWindows ?? []
- for childWin in childWins {
- if let winC = childWin.windowController {
- if winC.responds(to: selector) {
- winC.perform(selector, with: appearance)
- }
- } else {
- if childWin.responds(to: selector) {
- childWin.perform(selector, with: appearance)
- }
- }
- }
- }
- }
- }
- // 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 menuItemClick_ExportNote(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser?.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- } else {
- document.mainViewController?.menuItemClick_ExportNote(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?) {
- 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 {
- if image.size.equalTo(.zero) == true {
-
- } else {
- 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 = KMTools.imageExtensions
- 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: NSWindow.currentWindow()) { 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)
- }
- }
|