123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170 |
- //
- // 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)
-
- }
- return false
- }
-
- 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 = KMLocalizedString(item.title, comment: "")
- let itemSubMenu = item.submenu
- if (itemSubMenu == nil) {
- continue
- }
-
- for item in itemSubMenu!.items {
- item.title = KMLocalizedString(item.title, comment: "")
-
- let itemSubMenu = item.submenu
- if (itemSubMenu == nil) {
- continue
- }
-
- for item in itemSubMenu!.items {
- item.title = KMLocalizedString(item.title, comment: "")
- }
- }
- }
- }
-
- //appMenu
- let appMenu = mainMenu?.item(at: 0)?.submenu
- if let item = appMenu?.item(at: 0) {
- item.title = KMLocalizedString("About") + " " + KMNAppName
- }
-
- //Share Item
- 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)
- }
- }
-
- self.updateAppMenu()
-
- }
-
- @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 {
- updateAppMenu()
-
- return true
- }
-
- //MARK: -IBAction
- @IBAction func menuItemAction_openPreferenceWindow(_ sender: Any) {
- SettingsWindowController.shared.showWindow(self)
- }
-
- @IBAction func menuItemAction_loginMenuItemAction(_ sender: Any) {
- if KMMemberInfo.shared.isLogin {
- KMUserInfoVCModel().skipAccountCenter()
- } else {
- KMLoginWindowsController.shared.showWindow(nil)
- }
- }
-
- @IBAction func menuItemAction_logoutMenuItemAction(_ sender: Any) {
- KMUserInfoVCModel().signOutAction()
- }
-
- @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()
- }
-
- func updateAppMenu() {
- guard let mainMenu = NSApp.mainMenu else {
- return
- }
-
- let appMenu = mainMenu.item(at: 0)?.submenu
- for item in appMenu?.items ?? [] {
- if item.action == NSSelectorFromString("menuItemAction_loginMenuItemAction:") {
- if KMMemberInfo.shared.isLogin {
- item.title = KMMemberInfo.shared.userEmail
- } else {
- item.title = KMLocalizedString("Login")
- }
- } else if item.action == NSSelectorFromString("menuItemAction_logoutMenuItemAction:") {
- item.isHidden = KMMemberInfo.shared.isLogin ? false : true
- }
- #if VERSION_BETA
- if item.action == NSSelectorFromString("menuItemAction_buyNowItemAction:") {
- item.isHidden = true
- } else if item.action == NSSelectorFromString("menuItemAction_restoreMenuItemAction:") {
- item.isHidden = true
- } else if item.action == NSSelectorFromString("menuItemAction_EducationDiscountAction:") {
- item.isHidden = true
- } else if item.action == NSSelectorFromString("menuItemAction_volumeDiscount:") {
- item.isHidden = true
- }
- #endif
-
- }
-
-
- }
- }
- //MARK: - File Menu
- extension AppDelegate {
- func isFileMenuActions(sel: Selector?) -> Bool {
- guard let selector = sel else {
- return false
- }
- let selectors = [NSSelectorFromString("menuItemAction_NewFromFile:"),
- NSSelectorFromString("menuItemAction_Open:"),
- 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:"),
- NSSelectorFromString("sharePageItemActionWithSender:")]
- 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
- } else if action == NSSelectorFromString("menuItemAction_Open:") {
- 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 {
- return true
- } else {
- if let pw = mainVC.listView.document.password {
- return true
- }
- 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:") {
-
- } else if action == NSSelectorFromString("sharePageItemActionWithSender:") {
- return true
- }
- return true
- }
- return false
- }
-
- //MARK: -IBAction
- @IBAction func menuItemAction_Open(_ sender: NSMenuItem) -> Void {
- if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
- _windowC.newFromPDFFile()
- }
- }
-
- @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()
- }
- }
-
- @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() {
-
- let model = KMBatchProcessingTableViewModel.initWithFilePath(url: mainVC.listView.document.documentURL)
- model.password = mainVC.listView.document.password ?? ""
-
- mainVC.showCompressController(model: model)
- }
- }
-
- @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?) {
- if let mainVC = self.mainViewController() {
- mainVC.searchPDF()
- }
- }
-
- @IBAction func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) {
- if let mainVC = self.mainViewController() {
- if sender.tag == 0 {
- mainVC.find_ReplacePDF()
- } else if sender.tag == 1 {
- mainVC.fineNext()
- } else if sender.tag == 2 {
- mainVC.findPrevious()
- } else if sender.tag == 3 {
- mainVC.useSelectionForFind()
- }
- }
- }
-
- @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:") {
- if mainVC.viewManager.toolMode == .Edit {
- if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
- if mainVC.listView.km_editingTextAreas().count > 0 {
- return true
- }
- }
- }
- return false
- } else if action == NSSelectorFromString("menuItemAction_FontAction:") {
- if mainVC.viewManager.toolMode == .Edit {
- if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
- if mainVC.listView.km_editingTextAreas().count > 0 {
- return true
- }
- }
- }
- return false
- } else if action == NSSelectorFromString("menuItemAction_CustomFont:") {
- if mainVC.viewManager.toolMode == .Edit {
- if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
- if mainVC.listView.km_editingTextAreas().count > 0 {
- return true
- }
- }
- }
- return false
- } else if action == NSSelectorFromString("menuItemAction_FontAlign:") {
- if mainVC.viewManager.toolMode == .Edit {
- if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
- if mainVC.listView.km_editingTextAreas().count > 0 {
- return true
- }
- }
- }
- return false
- }
- return true
- }
- return false
- }
-
- //MARK: -IBAction
-
-
- @IBAction func menuItemAction_PasteAndMatch(_ menuItem: NSMenuItem) {
-
- }
-
- @IBAction func menuItemAction_ShowFont(_ menuItem: NSMenuItem) {
- if let mainVC = self.mainViewController() {
- mainVC.menuItemAction_FontPanel()
- }
- }
-
- @IBAction func menuItemAction_FontAction(_ menuItem: NSMenuItem) {
- if let mainVC = self.mainViewController() {
- mainVC.menuItemAction_FontAction(menuItem.tag)
- }
- }
-
- @IBAction func menuItemAction_CustomFont(_ menuItem: NSMenuItem) {
- if let mainVC = self.mainViewController() {
- mainVC.menuItemAction_CustomFont(menuItem.tag)
- }
- }
-
- @IBAction func menuItemAction_FontAlign(_ menuItem: NSMenuItem) {
- if let mainVC = self.mainViewController() {
- mainVC.menuItemAction_FontAlign(menuItem.tag)
- }
- }
-
-
- }
- // 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:") {
- menuItem.state = .off
- if mainVC.viewManager.isPDFReadMode == true {
- menuItem.state = .on
- }
- } else if action == NSSelectorFromString("menuItemAction_FullScreen:") {
- menuItem.state = .off
- if mainVC.view.window?.isFullScreen() == true {
- menuItem.state = .on
- }
- } else if action == NSSelectorFromString("menuItemAction_Presentation:") {
-
- } else if action == NSSelectorFromString("menuItemAction_SplitView:") {
- menuItem.state = .off
- if menuItem.tag == 0 && mainVC.listView.viewSplitMode == .vertical {
- menuItem.state = .on
- } else if menuItem.tag == 1 && mainVC.listView.viewSplitMode == .horizontal {
- menuItem.state = .on
- } else if menuItem.tag == 2 && mainVC.listView.viewSplitMode == .disable {
- menuItem.state = .on
- }
- } 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()
- mainVC.alertTipViewController.reloadFormAlertUI()
- }
- }
-
- @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("menuItemAction_showForwardTagPage:"),
- NSSelectorFromString("menuItemAction_showNextTagPage:"),
- NSSelectorFromString("menuItemAction_mergeAllWindow:")]
- if selectors.contains(selector) {
- return true
- }
- return false
- }
-
- func validateWindowMenuItem(_ menuItem: NSMenuItem) -> Bool {
- let action = menuItem.action
- if let browser = self.currentKMBrowser() {
- if action == NSSelectorFromString("menuItemAction_showForwardTagPage:") {
- menuItem.keyEquivalent = "\t"
- menuItem.keyEquivalentModifierMask = [.shift, .control]
- return browser.canSelectPreviousTab()
- } else if action == NSSelectorFromString("menuItemAction_showNextTagPage:") {
- return browser.canSelectNextTab()
- }
- }
- if let browserWC = self.currentBrowserWindowController() {
- if action == NSSelectorFromString("menuItemAction_mergeAllWindow:") {
- return browserWC.canMergeAllWindow()
- }
- }
- return true
- }
-
- //MARK: -IBAction
- @IBAction func menuItemAction_showForwardTagPage(_ sender: NSMenuItem) -> Void {
- if let browser = self.currentKMBrowser() {
- browser.selectPreviousTab()
- }
- }
-
- @IBAction func menuItemAction_showNextTagPage(_ sender: NSMenuItem) -> Void {
- if let browser = self.currentKMBrowser() {
- browser.selectNextTab()
- }
- }
-
- @IBAction func menuItemAction_mergeAllWindow(_ sender: NSMenuItem) -> Void {
- if let browserWC = self.currentBrowserWindowController() {
- browserWC.mergeAllWindow(sender)
- }
- }
- }
- // 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 {
- let help = KMUserFeekbackHanddler()
- help.showFeekbackWindow(with: KMLocalizedString("Feedback", comment: ""))
- }
-
- @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()
- }
-
-
- }
|