1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324 |
- //
- // KMBrowserWindowController.swift
- // PDF Master
- //
- // 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
-
- private var homeVC: KMHomeViewController?
- override func windowDidLoad() {
- super.windowDidLoad()
-
- window?.backgroundColor = NSColor.km_init(hex: "#DFE1E5")
-
- // window?.setFrameAutosaveName("")
- rightTabStripView_.delete = self
- homeRightTabStripView_.delete = self
- rightTabStripView_.updateView()
- fileUploadPanel.delete = self
- homeRightTabStripView_.homeRightSearchField.delegate = self
-
- isMultiTabMode = true
- 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)
-
- 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)
- }
- }
- }
- }
- }
-
- @objc func closeAction() {
- self.window?.performClose(nil)
- }
-
- override func windowShouldClose(_ sender: NSWindow) -> Bool {
- if self.browser.tabStripModel.count() > 1 {
- self.browser.windowDidBeginToClose()
- return false
- }
- return true
- }
-
- override func 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" {
- updateViewColor()
- }
- }
-
- 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
- }
- }
-
- 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.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 {
- return rightTabStripView_
- }
- }
-
- override var homeRightStripView: NSView! {
- get {
- return homeRightTabStripView_
- }
- }
-
- // MARK: Button Action
-
- func commandDispatch(_ sender: Any) -> Void {
- openDocumentWindow()
- }
- func closeAllTabs(_ sender: Any) -> Void {
- 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
- }
- }
- 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?.password = password
- }
- }
- }
- }
- } else {
- var selectDocument: KMMainDocument? = nil
- if ((document?.isKind(of: KMMainDocument.self)) != nil) {
- selectDocument = (document as! KMMainDocument)
- }
- if selectDocument != nil {
- let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
- selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
- if (selectDocument?.browser.window.isVisible)! as Bool {
- selectDocument?.browser.window.orderFront(nil)
- } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
- selectDocument?.browser.window.orderFront(nil)
- }
- } else {
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: (activeTab?.fileURL)!, display: true) { _, _, _ in
-
- }
- }
- }
- }
- }
-
- func canMergeAllWindow() -> Bool {
- return self.fetchBrowserWindowControllers().count > 0
- }
-
- fileprivate func fetchBrowserWindowControllers() -> [KMBrowserWindowController] {
- var windowArray: [KMBrowserWindowController] = []
- for window in NSApp.windows {
- guard let windowController = window.windowController, windowController is KMBrowserWindowController else {
- continue
- }
- if let _tabScripC = (windowController as? KMBrowserWindowController)?.tabStripController, _tabScripC.viewsCount() <= 1 {
- continue
- }
- if (window.isVisible && (windowController.isEqual(to: self) == false)) {
- windowArray.append(windowController as! KMBrowserWindowController)
- }
- }
- return windowArray
- }
-
- func mergeAllWindow(_ sender: Any) {
- let windowArray = self.fetchBrowserWindowControllers()
- if (windowArray.count <= 0) {
- return
- }
- for windowC in windowArray {
- // 拼接窗口 [拼接窗口里的标签,除了home标签]
- self.append(windowC, toTabView: NSView())
- if let browser = windowC.browser {
- if (browser.tabCount() <= 1 && browser.activeTabContents().isHome) {
- windowC.close()
- }
- }
- }
- }
-
- override func tabDidSelect(_ notification: Notification!) {
- super.tabDidSelect(notification)
-
- if let _userInfo = notification.userInfo, let _newContents = _userInfo[CTTabNewContentsUserInfoKey] as? KMMainDocument {
- _newContents.addWindowController(self)
- }
- }
-
- override func layoutTabContentArea(_ frame: NSRect) {
- super.layoutTabContentArea(frame)
-
- self.rightStripView.autoresizingMask = [.minXMargin, .minYMargin]
- }
-
- override func openDocument(_ sender: Any!) {
- guard let _window = self.window else {
- return
- }
-
- NSOpenPanel.km_open_pdf_multi_success(_window, panel: nil) { urls in
- for url in urls {
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
-
- }
- }
- }
- }
- }
- // MARK: - KMToolbarRightViewDelegate
- extension KMBrowserWindowController: KMToolbarRightViewDelegate {
- func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) {
- self.trackEvent_upgrade()
- KMComparativeTableViewController.show(window: self.window!, .upgrade)
- }
-
- 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 (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)) {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- if (KMSystemMenu.isAnnotationSelector(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)) {
- return document.isHome ? false : document.mainViewController!.validateMenuItem(menuItem)
- }
- if (KMSystemMenu.isWindowSelector(sel: action)) {
- return document.isHome ? document.homeViewController!.validateMenuItem(menuItem) : document.mainViewController!.validateMenuItem(menuItem)
- }
-
- return true
- }
- }
- extension KMBrowserWindowController {
- @IBAction func menuItemAction_openFile(_ sender: Any) {
- super.openDocument(sender)
- }
-
- @IBAction func importFromFile(_ sender: Any) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.importFromFile(sender)
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.importFromFile(sender)
- }
- }
-
- @IBAction func openBlankPage(_ sender: Any) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.openBlankPage(sender)
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.openBlankPage(sender)
- }
- }
-
- @IBAction func importFromScanner(_ sender: Any) {
- let document: KMMainDocument = self.browser.activeTabContents() as! KMMainDocument
- if (document.isHome) {
- document.homeViewController?.importFromScanner(sender)
- } else {
- self.homeVC = KMHomeViewController()
- self.homeVC?.importFromScanner(sender)
- }
- }
-
- @IBAction func menuItemAction_newTab(_ sender: Any) {
- self.openDocumentWindow()
- }
- }
- // 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) {
- // document.homeViewController?.menuItemClick_mergePDF(sender)
- } else {
- document.mainViewController?.menuItemClick_saveAsFlattenedPDF(sender)
- }
- }
- }
-
- func menuItemClick_mergePDF(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemClick_mergePDF(sender)
- } else {
- document.mainViewController?.menuItemClick_mergePDF(sender)
- }
- }
- }
-
- func menuItemClick_Compress(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemClick_Compress(sender)
- } else {
- document.mainViewController?.menuItemClick_Compress(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToWord(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToWord(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToWord(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToExcel(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToExcel(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToExcel(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToPPT(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToPPT(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToPPT(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToRTF(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToRTF(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToRTF(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToHTML(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToHTML(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToHTML(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToText(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToText(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToText(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToCSV(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToCSV(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToCSV(sender)
- }
- }
- }
-
- func menuItemAction_ConvertToImage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_ConvertToImage(sender)
- } else {
- document.mainViewController?.menuItemAction_ConvertToImage(sender)
- }
- }
- }
-
- func menuItemClick_SettingPassword(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemClick_SettingPassword(sender)
- } else {
- document.mainViewController?.menuItemClick_SettingPassword(sender)
- }
- }
- }
-
- func menuItemClick_RemovePassword(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemClick_RemovePassword(sender)
- }
- }
-
- func menuItemAction_closeWindow(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_closeWindow(sender)
- } else {
- document.mainViewController?.menuItemAction_closeWindow(sender)
- }
- }
- }
-
- func menuItemAction_closeAllWindows(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument {
- if (document.isHome) {
- document.homeViewController?.menuItemAction_closeAllWindows(sender)
- } else {
- document.mainViewController?.menuItemAction_closeAllWindows(sender)
- }
- }
- }
-
- func menuItemAction_closeTagPage(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_closeTagPage(sender)
- }
- }
-
- func menuItemAction_showInFinder(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_showInFinder(sender)
- }
- }
-
- func menuItemAction_property(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_property(sender)
- }
- }
-
- func menuItemAction_print(_ sender: Any) {
- if (self.canResponseDocumentAction() == false) {
- return
- }
- if let document = self.browser.activeTabContents() as? KMMainDocument, document.isHome == false {
- document.mainViewController?.menuItemAction_print(sender)
- }
- }
- }
- // MARK: - KMSystemViewMenuProtocol
- extension KMBrowserWindowController: KMSystemViewMenuProtocol {
- 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)
- }
- }
- }
- // 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)
- }
- }
- }
- // 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 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 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: - 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)
- }
- }
- }
- // MARK: - KMSystemToolMenuProtocol
- extension KMBrowserWindowController: KMSystemToolMenuProtocol {
- 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)
- }
- }
- }
- // 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)
- }
- }
- }
- }
- // 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)
- }
- }
|