1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093 |
- //
- // 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:") {
-
- } else if action == NSSelectorFromString("menuItemAction_unlockFunction:") {
-
- } 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 {
-
- }
-
- @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 == 3 {
- 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_undo:"),
- NSSelectorFromString("menuItemAction_redo:"),
- NSSelectorFromString("menuItemAction_Copy:"),
- NSSelectorFromString("menuItemAction_Cut:"),
- NSSelectorFromString("menuItemAction_Paste:"),
- NSSelectorFromString("menuItemAction_PasteAndMatch:"),
- NSSelectorFromString("menuItemAction_Delete:"),
- NSSelectorFromString("menuItemAction_SelectAll:"),
- 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_undo:") {
-
- } else if action == NSSelectorFromString("menuItemAction_redo:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Copy:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Cut:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Paste:") {
-
- } else if action == NSSelectorFromString("menuItemAction_PasteAndMatch:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Delete:") {
-
- } else if action == NSSelectorFromString("menuItemAction_SelectAll:") {
-
- } 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_undo(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_redo(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_Copy(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_Cut(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_Paste(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_PasteAndMatch(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_Delete(_ sender: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_SelectAll(_ 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:") {
-
- } 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:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Themes:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Zoom:") {
-
- } else if action == NSSelectorFromString("menuItemAction_Rotate:") {
-
- } else if action == NSSelectorFromString("menuItemAction_HighlightFormsField:") {
-
- } else if action == NSSelectorFromString("menuItemAction_HighlightLinks:") {
-
- } else if action == NSSelectorFromString("menuItemAction_ResetForm:") {
-
- } else if action == NSSelectorFromString("menuItemAction_AutoScroll:") {
-
- }
- 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)
-
- }
- }
-
- @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()
- }
-
-
- }
|