// // 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) } }