// // AppDelegate+MenuAction.swift // PDF Reader Pro // // Created by Niehaoyu on 2025/1/2. // import Foundation //MARK: - NSMenuDelegate extension AppDelegate: NSMenuDelegate, NSMenuItemValidation { func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { let action = menuItem.action if self.isPDFReaderProMenuActions(sel: action) { return self.validatePDFReaderProMenuItem(menuItem) } else if self.isFileMenuActions(sel: action) { return self.validateFileMenuItem(menuItem) } else if self.isEditMenuActions(sel: action) { return self.validateEditMenuItem(menuItem) } else if self.isViewMenuActions(sel: action) { return self.validateViewMenuItem(menuItem) } else if self.isGoMenuActions(sel: action) { return self.validateGoMenuItem(menuItem) } else if self.isWindowMenuActions(sel: action) { return self.validateWindowMenuItem(menuItem) } else if self.isHelpMenuActions(sel: action) { return self.validateHelpMenuItem(menuItem) } // if (action == #selector(sharePageItemAction)) { // guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else { // return false // } // // let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false // return !isHome // } // if action == #selector(menuItemAction_closeDocument) { // guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else { // if NSApp.mainWindow?.windowController != nil { // return true // } // return false // } // let isNewTab = _windowC.browser?.activeTabContents()?.isNewTab ?? false // if isNewTab { // return true // } // } return false } func updateLoginMenuItem() { let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu if firstItem != nil { let item1 = firstItem?.item(withTag: 11) let item2 = firstItem?.item(withTag: 12) let item3 = firstItem?.item(withTag: 13) let item4 = firstItem?.item(withTag: 14) let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag) item1?.isHidden = true item2?.isHidden = true item3?.isHidden = true item4?.isHidden = true item6?.isHidden = true } } @objc func clickOutline(menuItem: NSMenuItem) { KMPrint("更新菜单栏") } func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool { return true } // MARK: - update Menu func initMainMenu() { // 处理菜单栏多语 let mainMenu = NSApp.mainMenu if (mainMenu == nil) { return } for menu in mainMenu!.items { let subMenu = menu.submenu for item in subMenu!.items { item.title = NSLocalizedString(item.title, comment: "") let itemSubMenu = item.submenu if (itemSubMenu == nil) { continue } for item in itemSubMenu!.items { item.title = NSLocalizedString(item.title, comment: "") let itemSubMenu = item.submenu if (itemSubMenu == nil) { continue } for item in itemSubMenu!.items { item.title = NSLocalizedString(item.title, comment: "") } } } } // let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu //#if VERSION_DMG // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 3) // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Enter License", comment: ""), action: #selector(enterLicense), target: self, at: 4) // if VerificationManager.default().needUpgradeLicense { // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("PDF to Office Pack", comment: ""), action: #selector(pdftoOfficeMenuItemAction), target: self, at: 5) // } // // let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8) // accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag //#endif //#if !VERSION_DMG // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Restore Previous Purchase", comment: ""), action: #selector(restoreSubscriptions), target: self, at: 1) //#endif // if let items = PDFOfficeMenu?.items { // for menu in items { // // } // } // if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Volume Discount", comment: "")) { // item.isHidden = true // } // if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("One License for Mac and Windows", comment: "")) { // item.isHidden = true // } // if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Education Discount", comment: "")) { // item.isHidden = true // } // let fileMenu = mainMenu?.item(at: 1)?.submenu for item in fileMenu?.items ?? [] { if item.action == NSSelectorFromString("menuItemAction_showInFinder:") { let shareItem: NSMenuItem? = NSMenuItem(title: KMLocalizedString("Share"), action: nil, target: nil) fileMenu?.insertItem(shareItem!, at: item.index) shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil) } } } @objc func sharePageItemAction(sender: NSMenuItem) { if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) { return } let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController let model = windowControler.browser?.tabStripModel if let cnt = model?.count(), cnt <= 0 { return } if let data = model?.activeTabContents()?.isHome, data { return } let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument if let data = document.mainViewController?.saveWatermarkFlag, !data { let represent : NSSharingService = sender.representedObject as! NSSharingService represent.perform(withItems: [document.fileURL as Any]) return } let represent : NSSharingService = sender.representedObject as! NSSharingService represent.perform(withItems: [document.fileURL as Any]) } @objc func accountRefreshAction() { } } // MARK: - PDF Reader Pro Menu extension AppDelegate { func isPDFReaderProMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } let selectors = [NSSelectorFromString("menuItemAction_openPreferenceWindow:"), NSSelectorFromString("menuItemAction_loginMenuItemAction:"), NSSelectorFromString("menuItemAction_logoutMenuItemAction:"), NSSelectorFromString("menuItemAction_buyNowItemAction:"), NSSelectorFromString("menuItemAction_restoreMenuItemAction:"), NSSelectorFromString("menuItemAction_EducationDiscountAction:"), NSSelectorFromString("menuItemAction_volumeDiscount:")] if selectors.contains(selector) { return true } return false } func validatePDFReaderProMenuItem(_ menuItem: NSMenuItem) -> Bool { return true } //MARK: -IBAction @IBAction func menuItemAction_openPreferenceWindow(_ sender: Any) { SettingsWindowController.shared.showWindow(self) } @IBAction func menuItemAction_loginMenuItemAction(_ sender: Any) { } @IBAction func menuItemAction_logoutMenuItemAction(_ sender: Any) { } @IBAction func menuItemAction_buyNowItemAction(_ sender: Any) { } @IBAction func menuItemAction_restoreMenuItemAction(_ sender: Any) { } @IBAction func menuItemAction_EducationDiscountAction(_ sender: NSMenuItem) { KMTools.openEducateWebSite() } @IBAction func menuItemAction_volumeDiscount(_ sender: NSMenuItem) { KMTools.openVPPWebSite() } } //MARK: - File Menu extension AppDelegate { func isFileMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } let selectors = [NSSelectorFromString("menuItemAction_NewFromFile:"), NSSelectorFromString("menuItemAction_NewFromWeb:"), NSSelectorFromString("menuItemAction_NewFromClipboard:"), NSSelectorFromString("menuItemAction_NewFromScanner:"), NSSelectorFromString("menuItemAction_NewFromBlankPage:"), NSSelectorFromString("menuItemAction_NewFromWindow:"), NSSelectorFromString("menuItemAction_MergePDFFiles:"), NSSelectorFromString("menuItemAction_closeDocument:"), NSSelectorFromString("menuItemAction_closeWindow:"), NSSelectorFromString("menuItemAction_closeAllWindows:"), NSSelectorFromString("menuItemClick_saveAsFlattenedPDF:"), NSSelectorFromString("menuItemClick_Compress:"), NSSelectorFromString("menuItemAction_ConvertTo:"), NSSelectorFromString("menuItemAction_addPassword:"), NSSelectorFromString("menuItemAction_removePassword:"), NSSelectorFromString("menuItemAction_unlockFunction:"), NSSelectorFromString("menuItemAction_searchPDF:"), NSSelectorFromString("menuItemAction_performFindPanelAction:"), NSSelectorFromString("menuItemAction_showInFinder:"), NSSelectorFromString("menuItemAction_property:"), NSSelectorFromString("menuItemAction_print:"), NSSelectorFromString("menuItemAction_customPrint:")] if selectors.contains(selector) { return true } return false } func validateFileMenuItem(_ menuItem: NSMenuItem) -> Bool { let action = menuItem.action if action == NSSelectorFromString("menuItemAction_NewFromFile:") { return true } else if action == NSSelectorFromString("menuItemAction_NewFromWeb:") { return true } else if action == NSSelectorFromString("menuItemAction_NewFromClipboard:") { return true } else if action == NSSelectorFromString("menuItemAction_NewFromScanner:") { return true } else if action == NSSelectorFromString("menuItemAction_NewFromBlankPage:") { return true } else if action == NSSelectorFromString("menuItemAction_NewFromWindow:") { return true } else if action == NSSelectorFromString("menuItemAction_MergePDFFiles:") { return true } else if action == NSSelectorFromString("menuItemAction_closeDocument:") { return true } else if action == NSSelectorFromString("menuItemAction_closeWindow:") { return true } else if action == NSSelectorFromString("menuItemAction_closeAllWindows:") { return true } if let mainVC = self.mainViewController() { if action == NSSelectorFromString("menuItemClick_saveAsFlattenedPDF:") { } else if action == NSSelectorFromString("menuItemClick_Compress:") { } else if action == NSSelectorFromString("menuItemAction_ConvertTo:") { } else if action == NSSelectorFromString("menuItemAction_addPassword:") { } else if action == NSSelectorFromString("menuItemAction_removePassword:") { if mainVC.listView.document.isLocked == true || mainVC.listView.document.password.count > 0 { return true } else { return false } } else if action == NSSelectorFromString("menuItemAction_unlockFunction:") { return mainVC.listView.document.isEncrypted } else if action == NSSelectorFromString("menuItemAction_searchPDF:") { } else if action == NSSelectorFromString("menuItemAction_performFindPanelAction:") { } else if action == NSSelectorFromString("menuItemAction_showInFinder:") { } else if action == NSSelectorFromString("menuItemAction_property:") { } else if action == NSSelectorFromString("menuItemAction_print:") { } else if action == NSSelectorFromString("menuItemAction_customPrint:") { } return true } return false } //MARK: -IBAction @IBAction func menuItemAction_NewFromFile(_ sender: NSMenuItem) -> Void { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.newFromFile() } } @IBAction func menuItemAction_NewFromWeb(_ sender: NSMenuItem) -> Void { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.newFromWebPage() } } @IBAction func menuItemAction_NewFromClipboard(_ sender: NSMenuItem) -> Void { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.newFromClipboard() } } @IBAction func menuItemAction_NewFromScanner(_ sender: NSMenuItem) -> Void { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.importFromScanner() } } @IBAction func menuItemAction_NewFromBlankPage(_ sender: NSMenuItem) -> Void { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.newBlankPage() } } @IBAction func menuItemAction_NewFromWindow(_ sender: NSMenuItem) -> Void { if sender.tag == 0 { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.screenShot_SelectArea(nil) } } else if sender.tag == 1 { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.screenShot_Window(nil) } } else if sender.tag == 2 { if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController { _windowC.screenShot_FullScreen(nil) } } } @IBAction func menuItemAction_MergePDFFiles(_ sender: NSMenuItem) -> Void { if let homeVC = self.homeViewController() { homeVC.fastTool_MergePDF() } else if let mainVC = self.mainViewController() { mainVC.showMergeWindow(mainVC.listView.document.password) } } @IBAction func menuItemAction_closeDocument(_ sender: Any) { if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) { guard let windowControler = NSApp.mainWindow?.windowController else { return } windowControler.window?.performClose(nil) return } let windowControler = NSApp.mainWindow?.windowController as? KMBrowserWindowController if let data = windowControler?.browser, data.tabCount() >= 2 { // 有两个以上的标签 if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应 return } } if let browser = windowControler?.browser { if browser.tabCount() == 1 { windowControler?.window?.close() } else { if let _ = windowControler?.window?.attachedSheet { NSSound.beep() return } browser.closeTab() } } else { windowControler?.window?.close() } } @IBAction func menuItemAction_closeWindow(_ sender: Any) { NSApp.mainWindow?.close() } @IBAction func menuItemAction_closeAllWindows(_ sender: Any) { for window in NSApp.windows { window.close() } } @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.saveAsFlattenedPDFAction() } } @IBAction func menuItemClick_Compress(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.showCompressController(mainVC.listView.document.documentURL) } } @IBAction func menuItemAction_ConvertTo(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { var convertType: KMPDFConvertType = .word if sender.tag == 0 { } else if sender.tag == 1 { convertType = .excel } else if sender.tag == 2 { convertType = .ppt } else if sender.tag == 30 { convertType = .jpeg } else if sender.tag == 31 { convertType = .jpg } else if sender.tag == 32 { convertType = .png } else if sender.tag == 33 { convertType = .gif } else if sender.tag == 34 { convertType = .tiff } else if sender.tag == 35 { convertType = .tga } else if sender.tag == 36 { convertType = .bmp } else if sender.tag == 37 { convertType = .jp2 } else if sender.tag == 4 { convertType = .rtf } else if sender.tag == 5 { convertType = .csv } else if sender.tag == 6 { convertType = .html } else if sender.tag == 7 { convertType = .text } else if sender.tag == 8 { convertType = .json } mainVC.showConvertWindow(convertType) } } @IBAction func menuItemAction_addPassword(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.showSecureWindow() } } @IBAction func menuItemAction_removePassword(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.showRemoveSecureWindow() } } @IBAction func menuItemAction_unlockFunction(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.unlockPDFDocument() } } @IBAction func menuItemAction_searchPDF(_ sender: Any?) { } @IBAction func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) { var forward = true var findString: String? } @IBAction func menuItemAction_showInFinder(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.showInFinder() } } @IBAction func menuItemAction_property(_ sender: Any) { if let mainVC = self.mainViewController() { KMInfoWindowController.shared.showWindow(sender) } } @IBAction func menuItemAction_print(_ sender: Any) { if let mainVC = self.mainViewController() { mainVC.showPrintWindow() } } @IBAction func menuItemAction_customPrint(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if sender.tag == 0 { mainVC.showPosterPrintWindow() } else if sender.tag == 1 { mainVC.showMultiplePrintWindow() } else if sender.tag == 2 { mainVC.showBookletPrintWindow() } } } } // MARK: - Edit Menu extension AppDelegate { func isEditMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } let selectors = [ NSSelectorFromString("menuItemAction_PasteAndMatch:"), NSSelectorFromString("menuItemAction_ShowFont:"), NSSelectorFromString("menuItemAction_FontAction:"), NSSelectorFromString("menuItemAction_CustomFont:"), NSSelectorFromString("menuItemAction_FontAlign:")] if selectors.contains(selector) { return true } return false } func validateEditMenuItem(_ menuItem: NSMenuItem) -> Bool { let action = menuItem.action if let mainVC = self.mainViewController() { if action == NSSelectorFromString("menuItemAction_PasteAndMatch:") { } else if action == NSSelectorFromString("menuItemAction_ShowFont:") { } else if action == NSSelectorFromString("menuItemAction_FontAction:") { } else if action == NSSelectorFromString("menuItemAction_CustomFont:") { } else if action == NSSelectorFromString("menuItemAction_FontAlign:") { } return true } return false } //MARK: -IBAction @IBAction func menuItemAction_PasteAndMatch(_ sender: NSMenuItem) { } @IBAction func menuItemAction_ShowFont(_ sender: NSMenuItem) { NSFontManager.shared.orderFrontFontPanel(nil) } @IBAction func menuItemAction_FontAction(_ sender: Any) { } @IBAction func menuItemAction_CustomFont(_ sender: NSMenuItem) { } @IBAction func menuItemAction_FontAlign(_ sender: NSMenuItem) { } } // MARK: - View Menu extension AppDelegate { func isViewMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } let selectors = [NSSelectorFromString("menuItemAction_ChangeDisplayMode:"), NSSelectorFromString("menuItemAction_ReadMode:"), NSSelectorFromString("menuItemAction_FullScreen:"), NSSelectorFromString("menuItemAction_Presentation:"), NSSelectorFromString("menuItemAction_SplitView:"), NSSelectorFromString("menuItemAction_BOTAMode:"), NSSelectorFromString("menuItemAction_Outline:"), NSSelectorFromString("menuItemAction_Notes:"), NSSelectorFromString("menuItemAction_Annotate:"), NSSelectorFromString("menuItemAction_Themes:"), NSSelectorFromString("menuItemAction_Zoom:"), NSSelectorFromString("menuItemAction_Rotate:"), NSSelectorFromString("menuItemAction_HighlightFormsField:"), NSSelectorFromString("menuItemAction_HighlightLinks:"), NSSelectorFromString("menuItemAction_ResetForm:"), NSSelectorFromString("menuItemAction_AutoScroll:")] if selectors.contains(selector) { return true } return false } func validateViewMenuItem(_ menuItem: NSMenuItem) -> Bool { let action = menuItem.action if let mainVC = self.mainViewController() { if action == NSSelectorFromString("menuItemAction_ChangeDisplayMode:") { menuItem.state = .off if menuItem.tag == 1 && mainVC.getPDFViewPageLayoutType() == .singlePage { menuItem.state = .on } else if menuItem.tag == 2 && mainVC.getPDFViewPageLayoutType() == .singlePageContinue { menuItem.state = .on } else if menuItem.tag == 3 && mainVC.getPDFViewPageLayoutType() == .twoPage { menuItem.state = .on } else if menuItem.tag == 4 && mainVC.getPDFViewPageLayoutType() == .twoPageContinue { menuItem.state = .on } else if menuItem.tag == 5 && mainVC.getPDFViewPageLayoutType() == .bookMode { menuItem.state = .on } } else if action == NSSelectorFromString("menuItemAction_ReadMode:") { } else if action == NSSelectorFromString("menuItemAction_FullScreen:") { } else if action == NSSelectorFromString("menuItemAction_Presentation:") { } else if action == NSSelectorFromString("menuItemAction_SplitView:") { } else if action == NSSelectorFromString("menuItemAction_BOTAMode:") { menuItem.state = .off if menuItem.tag == 0 && mainVC.viewManager.pdfSideBarType == .thumbnail { menuItem.state = .on } else if menuItem.tag == 1 && mainVC.viewManager.pdfSideBarType == .outline { menuItem.state = .on } else if menuItem.tag == 2 && mainVC.viewManager.pdfSideBarType == .bookmark { menuItem.state = .on } else if menuItem.tag == 3 && mainVC.viewManager.pdfSideBarType == .annotation { menuItem.state = .on } } else if action == NSSelectorFromString("menuItemAction_Themes:") { menuItem.state = .off if menuItem.tag == 0 && mainVC.listView.displayMode == .normal { menuItem.state = .on } else if menuItem.tag == 1 && mainVC.listView.displayMode == .soft { menuItem.state = .on } else if menuItem.tag == 2 && mainVC.listView.displayMode == .green { menuItem.state = .on } else if menuItem.tag == 3 && mainVC.listView.displayMode == .night { menuItem.state = .on } } else if action == NSSelectorFromString("menuItemAction_Zoom:") { } else if action == NSSelectorFromString("menuItemAction_Rotate:") { } else if action == NSSelectorFromString("menuItemAction_HighlightFormsField:") { let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight() menuItem.state = enabled ? .on : .off } else if action == NSSelectorFromString("menuItemAction_HighlightLinks:") { let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight() menuItem.state = enabled ? .on : .off } else if action == NSSelectorFromString("menuItemAction_ResetForm:") { } else if action == NSSelectorFromString("menuItemAction_AutoScroll:") { menuItem.state = mainVC.isAutoFlowOn() ? .on : .off } return true } return false } //MARK: -IBAction @IBAction func menuItemAction_ChangeDisplayMode(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if sender.tag == 1 { mainVC.updatePDFViewDisplayMode(viewMode: .singlePage) } else if sender.tag == 2 { mainVC.updatePDFViewDisplayMode(viewMode: .singlePageContinuous) } else if sender.tag == 3 { mainVC.updatePDFViewDisplayMode(viewMode: .twoUp) } else if sender.tag == 4 { mainVC.updatePDFViewDisplayMode(viewMode: .twoUpContinuous) } else if sender.tag == 5 { mainVC.updatePDFViewDisplayMode(isbookMode: true) } } } @IBAction func menuItemAction_ReadMode(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.viewManager.isPDFReadMode = !mainVC.viewManager.isPDFReadMode if mainVC.viewManager.isPDFReadMode { mainVC.openPDFReadMode() } else { mainVC.exitPDFReadMode() } } } @IBAction func menuItemAction_FullScreen(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.view.window?.toggleFullScreen(nil) } } @IBAction func menuItemAction_Presentation(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.togglePresentation(nil) } } @IBAction func menuItemAction_SplitView(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if sender.tag == 0 { mainVC.listView.viewSplitMode = .vertical } else if sender.tag == 1 { mainVC.listView.viewSplitMode = .horizontal } else if sender.tag == 2 { mainVC.listView.viewSplitMode = .disable } mainVC.reloadPDFSplitInfo() } } @IBAction func menuItemAction_BOTAMode(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if sender.tag == 0 { if mainVC.viewManager.pdfSideBarType == .thumbnail { mainVC.viewManager.pdfSideBarType = .none } else { mainVC.viewManager.pdfSideBarType = .thumbnail } } else if sender.tag == 1 { if mainVC.viewManager.pdfSideBarType == .outline { mainVC.viewManager.pdfSideBarType = .none } else { mainVC.viewManager.pdfSideBarType = .outline } } else if sender.tag == 2 { if mainVC.viewManager.pdfSideBarType == .bookmark { mainVC.viewManager.pdfSideBarType = .none } else { mainVC.viewManager.pdfSideBarType = .bookmark } } else if sender.tag == 3 { if mainVC.viewManager.pdfSideBarType == .annotation { mainVC.viewManager.pdfSideBarType = .none } else { mainVC.viewManager.pdfSideBarType = .annotation } } if mainVC.viewManager.pdfSideBarType == .none { mainVC.toggleCloseLeftSide() } else { mainVC.toggleOpenLeftSide(pdfSideBarType: mainVC.viewManager.pdfSideBarType) } mainVC.reloadSideBar() } } @IBAction func menuItemAction_Themes(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { var model: KMPDFViewMode = .normal var color = NSColor.clear if sender.tag == 0 { model = .normal } else if sender.tag == 1 { model = .soft } else if sender.tag == 2 { model = .green } else if sender.tag == 3 { model = .night } else { model = .other } mainVC.listView.setPageBackgroundColorWith(color, viewMode: model) mainVC.updatePDFDisplaySettingView() } } @IBAction func menuItemAction_Zoom(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { var type: KMPDFZoomType = .width if sender.tag == 0 { type = .width } else if sender.tag == 1 { type = .fit } else if sender.tag == 2 { type = .actualSize } else if sender.tag == 3 { type = .zoom_In } else if sender.tag == 4 { type = .zoom_Out } mainVC.selectZoom(type) } } @IBAction func menuItemAction_Rotate(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if sender.tag == 0 { mainVC.rotateLeft(page: mainVC.listView.currentPage(), listView: mainVC.listView) } else if sender.tag == 1 { mainVC.rotateRight(page: mainVC.listView.currentPage(), listView: mainVC.listView) } } } @IBAction func menuItemAction_HighlightFormsField(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight() CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled) mainVC.listView.setNeedsDisplayForVisiblePages() } } @IBAction func menuItemAction_HighlightLinks(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight() CPDFAnnotation.updateLinkFieldHighlight(mainVC.listView, linkFieldHighlight: !enabled) } } @IBAction func menuItemAction_ResetForm(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.listView.resetFormAnnotation() } } @IBAction func menuItemAction_AutoScroll(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.toggleAutoFlow(nil) } } } // MARK: - Go Menu extension AppDelegate { func isGoMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } let selectors = [NSSelectorFromString("menuItemAction_Next:"), NSSelectorFromString("menuItemAction_Previous:"), NSSelectorFromString("menuItemAction_First:"), NSSelectorFromString("menuItemAction_Last:"), NSSelectorFromString("menuItemAction_GotoPage:"), NSSelectorFromString("menuItemAction_Back:"), NSSelectorFromString("menuItemAction_Forward:")] if selectors.contains(selector) { return true } return false } func validateGoMenuItem(_ menuItem: NSMenuItem) -> Bool { let action = menuItem.action if let mainVC = self.mainViewController() { if action == NSSelectorFromString("menuItemAction_Next:") { if mainVC.listView.isEditing() && mainVC.listView.isEditable() { return false } return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToNextPage()) } else if action == NSSelectorFromString("menuItemAction_Previous:") { if mainVC.listView.isEditing() && mainVC.listView.isEditable() { return false } return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToPreviousPage()) } else if action == NSSelectorFromString("menuItemAction_First:") { return mainVC.listView.canGoToFirstPage() } else if action == NSSelectorFromString("menuItemAction_Last:") { return mainVC.listView.canGoToLastPage() } else if action == NSSelectorFromString("menuItemAction_GotoPage:") { return true } else if action == NSSelectorFromString("menuItemAction_Back:") { return mainVC.listView.km_canGoBack() } else if action == NSSelectorFromString("menuItemAction_Forward:") { return mainVC.listView.km_canGoForward() } } return false } //MARK: -IBAction @IBAction func menuItemAction_Next(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if (mainVC.listView.canGoToNextPage()) { mainVC.listView.goToNextPage(nil) } } } @IBAction func menuItemAction_Previous(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if (mainVC.listView.canGoToPreviousPage()) { mainVC.listView.goToPreviousPage(nil) } } } @IBAction func menuItemAction_First(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.listView.goToFirstPage(nil) } } @IBAction func menuItemAction_Last(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.listView.goToLastPage(nil) } } @IBAction func menuItemAction_GotoPage(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { mainVC.gotoPage(nil) } } @IBAction func menuItemAction_Back(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if (mainVC.listView.km_canGoBack()) { mainVC.listView.km_goBack(nil) } } } @IBAction func menuItemAction_Forward(_ sender: NSMenuItem) { if let mainVC = self.mainViewController() { if (mainVC.listView.km_canGoForward()) { mainVC.listView.km_goForward(nil) } } } } // MARK: - Window Menu extension AppDelegate { func isWindowMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } var selectors = [NSSelectorFromString("11:"), NSSelectorFromString("11:")] if selectors.contains(selector) { return true } return false } func validateWindowMenuItem(_ menuItem: NSMenuItem) -> Bool { return true } //MARK: -IBAction } // MARK: - help Menu extension AppDelegate { func isHelpMenuActions(sel: Selector?) -> Bool { guard let selector = sel else { return false } var selectors = [NSSelectorFromString("menuItemAction_APPWebSite:"), NSSelectorFromString("menuItemAction_quickStudy:"), NSSelectorFromString("menuItemAction_OnlineHelp:"), NSSelectorFromString("menuItemAction_Feedback:"), NSSelectorFromString("menuItemAction_FiveStar:"), NSSelectorFromString("menuItemAction_SubscribeUs:"), NSSelectorFromString("menuItemAction_CheckForUpdate:"), NSSelectorFromString("menuItemAction_VPP:"), NSSelectorFromString("menuItemAction_FreeTemplate:"), NSSelectorFromString("menuItemAction_MoreProducts:"), NSSelectorFromString("menuItemAction_PowerBy:"), NSSelectorFromString("menuItemAction_privacyPolicy:"), NSSelectorFromString("menuItemAction_TermsofService:")] if selectors.contains(selector) { return true } return false } func validateHelpMenuItem(_ menuItem: NSMenuItem) -> Bool { return true } //MARK: -IBAction @IBAction func menuItemAction_APPWebSite(_ sender: NSMenuItem) -> Void { KMTools.openURL(urlString: APPMain_Link) } @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void { KMTools.openQuickStartStudy() } @IBAction func menuItemAction_OnlineHelp(_ sender: NSMenuItem) -> Void { KMTools.openFAQWebsite() } @IBAction func menuItemAction_Feedback(_ sender: NSMenuItem) -> Void { KMTools.feekback() } @IBAction func menuItemAction_FiveStar(_ sender: NSMenuItem) -> Void { KMTools.rateUs() } @IBAction func menuItemAction_SubscribeUs(_ sender: NSMenuItem) -> Void { KMEmailSubWindowController().showWindow(nil) } @IBAction func menuItemAction_CheckForUpdate(_ sender: NSMenuItem) -> Void { #if VERSION_DMG SUUpdater.shared().checkForUpdates(sender) #endif } @IBAction func menuItemAction_VPP(_ sender: NSMenuItem) -> Void { KMTools.openVPPWebSite() } @IBAction func menuItemAction_FreeTemplate(_ sender: NSMenuItem) -> Void { KMTools.openFreePDFTemplatesWebsite() } @IBAction func menuItemAction_MoreProducts(_ sender: NSMenuItem) -> Void { KMTools.openMoreProductWebsite() } @IBAction func menuItemAction_PowerBy(_ sender: NSMenuItem) -> Void { KMTools.openComPDFKitPowerWebsite() } @IBAction func menuItemAction_privacyPolicy(_ sender: NSMenuItem) -> Void { KMTools.openPrivacyPolicyWebSite() } @IBAction func menuItemAction_TermsofService(_ sender: NSMenuItem) -> Void { KMTools.openTermOfServiceWebSite() } }