12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325 |
- //
- // 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 (WelcomeWindowController.welcomeHasShow() == false) {
- //AI 版本禁掉首次开启帮助文档
- // KMTools.openQuickStartStudy()
-
- DispatchQueue.main.async {
- let welcome = WelcomeWindowController()
- self.window?.beginSheet(welcome.window!)
-
- welcome.itemClick = { [weak self] idx, param in
- if (idx == 1) { // 关闭
- self?.window?.endSheet((param as! NSWindowController).window!)
- } else if (idx == 2) { // 以后提醒
- self?.window?.endSheet((param as! NSWindowController).window!)
- } else if (idx == 3) { // 注册
- self?.window?.endSheet((param as! NSWindowController).window!)
-
- guard let window_ = self?.window else {
- return
- }
- let _ = 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)
- }
- }
|