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