AppDelegate+MenuAction.swift 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. //
  2. // AppDelegate+MenuAction.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2025/1/2.
  6. //
  7. import Foundation
  8. //MARK: - NSMenuDelegate
  9. extension AppDelegate: NSMenuDelegate, NSMenuItemValidation {
  10. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  11. let action = menuItem.action
  12. if self.isPDFReaderProMenuActions(sel: action) {
  13. return self.validatePDFReaderProMenuItem(menuItem)
  14. } else if self.isFileMenuActions(sel: action) {
  15. return self.validateFileMenuItem(menuItem)
  16. } else if self.isEditMenuActions(sel: action) {
  17. return self.validateEditMenuItem(menuItem)
  18. } else if self.isViewMenuActions(sel: action) {
  19. return self.validateViewMenuItem(menuItem)
  20. } else if self.isGoMenuActions(sel: action) {
  21. return self.validateGoMenuItem(menuItem)
  22. } else if self.isWindowMenuActions(sel: action) {
  23. return self.validateWindowMenuItem(menuItem)
  24. } else if self.isHelpMenuActions(sel: action) {
  25. return self.validateHelpMenuItem(menuItem)
  26. }
  27. // if (action == #selector(sharePageItemAction)) {
  28. // guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  29. // return false
  30. // }
  31. //
  32. // let isHome = _windowC.browser?.activeTabContents()?.isHome ?? false
  33. // return !isHome
  34. // }
  35. // if action == #selector(menuItemAction_closeDocument) {
  36. // guard let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController else {
  37. // if NSApp.mainWindow?.windowController != nil {
  38. // return true
  39. // }
  40. // return false
  41. // }
  42. // let isNewTab = _windowC.browser?.activeTabContents()?.isNewTab ?? false
  43. // if isNewTab {
  44. // return true
  45. // }
  46. // }
  47. return false
  48. }
  49. func updateLoginMenuItem() {
  50. let firstItem = NSApp.mainMenu?.item(at: 0)?.submenu
  51. if firstItem != nil {
  52. let item1 = firstItem?.item(withTag: 11)
  53. let item2 = firstItem?.item(withTag: 12)
  54. let item3 = firstItem?.item(withTag: 13)
  55. let item4 = firstItem?.item(withTag: 14)
  56. let item6 = firstItem?.item(withTag: kKMMainMenuAccountRefreshItemTag)
  57. item1?.isHidden = true
  58. item2?.isHidden = true
  59. item3?.isHidden = true
  60. item4?.isHidden = true
  61. item6?.isHidden = true
  62. }
  63. }
  64. @objc func clickOutline(menuItem: NSMenuItem) {
  65. KMPrint("更新菜单栏")
  66. }
  67. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  68. return true
  69. }
  70. // MARK: - update Menu
  71. func initMainMenu() {
  72. // 处理菜单栏多语
  73. let mainMenu = NSApp.mainMenu
  74. if (mainMenu == nil) {
  75. return
  76. }
  77. for menu in mainMenu!.items {
  78. let subMenu = menu.submenu
  79. for item in subMenu!.items {
  80. item.title = NSLocalizedString(item.title, comment: "")
  81. let itemSubMenu = item.submenu
  82. if (itemSubMenu == nil) {
  83. continue
  84. }
  85. for item in itemSubMenu!.items {
  86. item.title = NSLocalizedString(item.title, comment: "")
  87. let itemSubMenu = item.submenu
  88. if (itemSubMenu == nil) {
  89. continue
  90. }
  91. for item in itemSubMenu!.items {
  92. item.title = NSLocalizedString(item.title, comment: "")
  93. }
  94. }
  95. }
  96. }
  97. // let PDFOfficeMenu = mainMenu?.item(at: 0)?.submenu
  98. //#if VERSION_DMG
  99. // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Check for Updates", comment: ""), action: #selector(checkForUpdates), target: self, at: 3)
  100. // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Enter License", comment: ""), action: #selector(enterLicense), target: self, at: 4)
  101. // if VerificationManager.default().needUpgradeLicense {
  102. // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("PDF to Office Pack", comment: ""), action: #selector(pdftoOfficeMenuItemAction), target: self, at: 5)
  103. // }
  104. //
  105. // let accountRefreshItem = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Account Refresh", comment: ""), action: #selector(accountRefreshAction), target: self, at: 8)
  106. // accountRefreshItem?.tag = kKMMainMenuAccountRefreshItemTag
  107. //#endif
  108. //#if !VERSION_DMG
  109. // _ = PDFOfficeMenu?.insertItem(withTitle: NSLocalizedString("Restore Previous Purchase", comment: ""), action: #selector(restoreSubscriptions), target: self, at: 1)
  110. //#endif
  111. // if let items = PDFOfficeMenu?.items {
  112. // for menu in items {
  113. //
  114. // }
  115. // }
  116. // if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Volume Discount", comment: "")) {
  117. // item.isHidden = true
  118. // }
  119. // if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("One License for Mac and Windows", comment: "")) {
  120. // item.isHidden = true
  121. // }
  122. // if let item = PDFOfficeMenu?.item(withTitle: NSLocalizedString("Education Discount", comment: "")) {
  123. // item.isHidden = true
  124. // }
  125. //
  126. let fileMenu = mainMenu?.item(at: 1)?.submenu
  127. for item in fileMenu?.items ?? [] {
  128. if item.action == NSSelectorFromString("menuItemAction_showInFinder:") {
  129. let shareItem: NSMenuItem? = NSMenuItem(title: KMLocalizedString("Share"), action: nil, target: nil)
  130. fileMenu?.insertItem(shareItem!, at: item.index)
  131. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  132. }
  133. }
  134. }
  135. @objc func sharePageItemAction(sender: NSMenuItem) {
  136. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  137. return
  138. }
  139. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  140. let model = windowControler.browser?.tabStripModel
  141. if let cnt = model?.count(), cnt <= 0 {
  142. return
  143. }
  144. if let data = model?.activeTabContents()?.isHome, data {
  145. return
  146. }
  147. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  148. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  149. let represent : NSSharingService = sender.representedObject as! NSSharingService
  150. represent.perform(withItems: [document.fileURL as Any])
  151. return
  152. }
  153. let represent : NSSharingService = sender.representedObject as! NSSharingService
  154. represent.perform(withItems: [document.fileURL as Any])
  155. }
  156. @objc func accountRefreshAction() {
  157. }
  158. }
  159. // MARK: - PDF Reader Pro Menu
  160. extension AppDelegate {
  161. func isPDFReaderProMenuActions(sel: Selector?) -> Bool {
  162. guard let selector = sel else {
  163. return false
  164. }
  165. let selectors = [NSSelectorFromString("menuItemAction_openPreferenceWindow:"),
  166. NSSelectorFromString("menuItemAction_loginMenuItemAction:"),
  167. NSSelectorFromString("menuItemAction_logoutMenuItemAction:"),
  168. NSSelectorFromString("menuItemAction_buyNowItemAction:"),
  169. NSSelectorFromString("menuItemAction_restoreMenuItemAction:"),
  170. NSSelectorFromString("menuItemAction_EducationDiscountAction:"),
  171. NSSelectorFromString("menuItemAction_volumeDiscount:")]
  172. if selectors.contains(selector) {
  173. return true
  174. }
  175. return false
  176. }
  177. func validatePDFReaderProMenuItem(_ menuItem: NSMenuItem) -> Bool {
  178. return true
  179. }
  180. //MARK: -IBAction
  181. @IBAction func menuItemAction_openPreferenceWindow(_ sender: Any) {
  182. SettingsWindowController.shared.showWindow(self)
  183. }
  184. @IBAction func menuItemAction_loginMenuItemAction(_ sender: Any) {
  185. }
  186. @IBAction func menuItemAction_logoutMenuItemAction(_ sender: Any) {
  187. }
  188. @IBAction func menuItemAction_buyNowItemAction(_ sender: Any) {
  189. }
  190. @IBAction func menuItemAction_restoreMenuItemAction(_ sender: Any) {
  191. }
  192. @IBAction func menuItemAction_EducationDiscountAction(_ sender: NSMenuItem) {
  193. KMTools.openEducateWebSite()
  194. }
  195. @IBAction func menuItemAction_volumeDiscount(_ sender: NSMenuItem) {
  196. KMTools.openVPPWebSite()
  197. }
  198. }
  199. //MARK: - File Menu
  200. extension AppDelegate {
  201. func isFileMenuActions(sel: Selector?) -> Bool {
  202. guard let selector = sel else {
  203. return false
  204. }
  205. let selectors = [NSSelectorFromString("menuItemAction_NewFromFile:"),
  206. NSSelectorFromString("menuItemAction_NewFromWeb:"),
  207. NSSelectorFromString("menuItemAction_NewFromClipboard:"),
  208. NSSelectorFromString("menuItemAction_NewFromScanner:"),
  209. NSSelectorFromString("menuItemAction_NewFromBlankPage:"),
  210. NSSelectorFromString("menuItemAction_NewFromWindow:"),
  211. NSSelectorFromString("menuItemAction_MergePDFFiles:"),
  212. NSSelectorFromString("menuItemAction_closeDocument:"),
  213. NSSelectorFromString("menuItemAction_closeWindow:"),
  214. NSSelectorFromString("menuItemAction_closeAllWindows:"),
  215. NSSelectorFromString("menuItemClick_saveAsFlattenedPDF:"),
  216. NSSelectorFromString("menuItemClick_Compress:"),
  217. NSSelectorFromString("menuItemAction_ConvertTo:"),
  218. NSSelectorFromString("menuItemAction_addPassword:"),
  219. NSSelectorFromString("menuItemAction_removePassword:"),
  220. NSSelectorFromString("menuItemAction_unlockFunction:"),
  221. NSSelectorFromString("menuItemAction_searchPDF:"),
  222. NSSelectorFromString("menuItemAction_performFindPanelAction:"),
  223. NSSelectorFromString("menuItemAction_showInFinder:"),
  224. NSSelectorFromString("menuItemAction_property:"),
  225. NSSelectorFromString("menuItemAction_print:"),
  226. NSSelectorFromString("menuItemAction_customPrint:")]
  227. if selectors.contains(selector) {
  228. return true
  229. }
  230. return false
  231. }
  232. func validateFileMenuItem(_ menuItem: NSMenuItem) -> Bool {
  233. let action = menuItem.action
  234. if action == NSSelectorFromString("menuItemAction_NewFromFile:") {
  235. return true
  236. } else if action == NSSelectorFromString("menuItemAction_NewFromWeb:") {
  237. return true
  238. } else if action == NSSelectorFromString("menuItemAction_NewFromClipboard:") {
  239. return true
  240. } else if action == NSSelectorFromString("menuItemAction_NewFromScanner:") {
  241. return true
  242. } else if action == NSSelectorFromString("menuItemAction_NewFromBlankPage:") {
  243. return true
  244. } else if action == NSSelectorFromString("menuItemAction_NewFromWindow:") {
  245. return true
  246. } else if action == NSSelectorFromString("menuItemAction_MergePDFFiles:") {
  247. return true
  248. } else if action == NSSelectorFromString("menuItemAction_closeDocument:") {
  249. return true
  250. } else if action == NSSelectorFromString("menuItemAction_closeWindow:") {
  251. return true
  252. } else if action == NSSelectorFromString("menuItemAction_closeAllWindows:") {
  253. return true
  254. }
  255. if let mainVC = self.mainViewController() {
  256. if action == NSSelectorFromString("menuItemClick_saveAsFlattenedPDF:") {
  257. } else if action == NSSelectorFromString("menuItemClick_Compress:") {
  258. } else if action == NSSelectorFromString("menuItemAction_ConvertTo:") {
  259. } else if action == NSSelectorFromString("menuItemAction_addPassword:") {
  260. } else if action == NSSelectorFromString("menuItemAction_removePassword:") {
  261. } else if action == NSSelectorFromString("menuItemAction_unlockFunction:") {
  262. } else if action == NSSelectorFromString("menuItemAction_searchPDF:") {
  263. } else if action == NSSelectorFromString("menuItemAction_performFindPanelAction:") {
  264. } else if action == NSSelectorFromString("menuItemAction_showInFinder:") {
  265. } else if action == NSSelectorFromString("menuItemAction_property:") {
  266. } else if action == NSSelectorFromString("menuItemAction_print:") {
  267. } else if action == NSSelectorFromString("menuItemAction_customPrint:") {
  268. }
  269. return true
  270. }
  271. return false
  272. }
  273. //MARK: -IBAction
  274. @IBAction func menuItemAction_NewFromFile(_ sender: NSMenuItem) -> Void {
  275. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  276. _windowC.newFromFile()
  277. }
  278. }
  279. @IBAction func menuItemAction_NewFromWeb(_ sender: NSMenuItem) -> Void {
  280. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  281. _windowC.newFromWebPage()
  282. }
  283. }
  284. @IBAction func menuItemAction_NewFromClipboard(_ sender: NSMenuItem) -> Void {
  285. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  286. _windowC.newFromClipboard()
  287. }
  288. }
  289. @IBAction func menuItemAction_NewFromScanner(_ sender: NSMenuItem) -> Void {
  290. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  291. _windowC.importFromScanner()
  292. }
  293. }
  294. @IBAction func menuItemAction_NewFromBlankPage(_ sender: NSMenuItem) -> Void {
  295. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  296. _windowC.newBlankPage()
  297. }
  298. }
  299. @IBAction func menuItemAction_NewFromWindow(_ sender: NSMenuItem) -> Void {
  300. if sender.tag == 0 {
  301. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  302. _windowC.screenShot_SelectArea(nil)
  303. }
  304. } else if sender.tag == 1 {
  305. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  306. _windowC.screenShot_Window(nil)
  307. }
  308. } else if sender.tag == 2 {
  309. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  310. _windowC.screenShot_FullScreen(nil)
  311. }
  312. }
  313. }
  314. @IBAction func menuItemAction_MergePDFFiles(_ sender: NSMenuItem) -> Void {
  315. }
  316. @IBAction func menuItemAction_closeDocument(_ sender: Any) {
  317. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  318. guard let windowControler = NSApp.mainWindow?.windowController else {
  319. return
  320. }
  321. windowControler.window?.performClose(nil)
  322. return
  323. }
  324. let windowControler = NSApp.mainWindow?.windowController as? KMBrowserWindowController
  325. if let data = windowControler?.browser, data.tabCount() >= 2 { // 有两个以上的标签
  326. if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应
  327. return
  328. }
  329. }
  330. if let browser = windowControler?.browser {
  331. if browser.tabCount() == 1 {
  332. windowControler?.window?.close()
  333. } else {
  334. if let _ = windowControler?.window?.attachedSheet {
  335. NSSound.beep()
  336. return
  337. }
  338. browser.closeTab()
  339. }
  340. } else {
  341. windowControler?.window?.close()
  342. }
  343. }
  344. @IBAction func menuItemAction_closeWindow(_ sender: Any) {
  345. NSApp.mainWindow?.close()
  346. }
  347. @IBAction func menuItemAction_closeAllWindows(_ sender: Any) {
  348. for window in NSApp.windows {
  349. window.close()
  350. }
  351. }
  352. @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  353. if let mainVC = self.mainViewController() {
  354. mainVC.saveAsFlattenedPDFAction()
  355. }
  356. }
  357. @IBAction func menuItemClick_Compress(_ sender: Any) {
  358. if let mainVC = self.mainViewController() {
  359. mainVC.showCompressController(mainVC.listView.document.documentURL)
  360. }
  361. }
  362. @IBAction func menuItemAction_ConvertTo(_ sender: NSMenuItem) {
  363. if let mainVC = self.mainViewController() {
  364. var convertType: KMPDFConvertType = .word
  365. if sender.tag == 0 {
  366. } else if sender.tag == 1 {
  367. convertType = .excel
  368. } else if sender.tag == 2 {
  369. convertType = .ppt
  370. } else if sender.tag == 3 {
  371. if sender.tag == 30 {
  372. convertType = .jpeg
  373. } else if sender.tag == 31 {
  374. convertType = .jpg
  375. } else if sender.tag == 32 {
  376. convertType = .png
  377. } else if sender.tag == 33 {
  378. convertType = .gif
  379. } else if sender.tag == 34 {
  380. convertType = .tiff
  381. } else if sender.tag == 35 {
  382. convertType = .tga
  383. } else if sender.tag == 36 {
  384. convertType = .bmp
  385. } else if sender.tag == 37 {
  386. convertType = .jp2
  387. }
  388. } else if sender.tag == 4 {
  389. convertType = .rtf
  390. } else if sender.tag == 5 {
  391. convertType = .csv
  392. } else if sender.tag == 6 {
  393. convertType = .html
  394. } else if sender.tag == 7 {
  395. convertType = .text
  396. } else if sender.tag == 8 {
  397. convertType = .json
  398. }
  399. mainVC.showConvertWindow(convertType)
  400. }
  401. }
  402. @IBAction func menuItemAction_addPassword(_ sender: Any) {
  403. if let mainVC = self.mainViewController() {
  404. mainVC.showSecureWindow()
  405. }
  406. }
  407. @IBAction func menuItemAction_removePassword(_ sender: Any) {
  408. if let mainVC = self.mainViewController() {
  409. mainVC.showRemoveSecureWindow()
  410. }
  411. }
  412. @IBAction func menuItemAction_unlockFunction(_ sender: Any) {
  413. if let mainVC = self.mainViewController() {
  414. mainVC.unlockPDFDocument()
  415. }
  416. }
  417. @IBAction func menuItemAction_searchPDF(_ sender: Any?) {
  418. }
  419. @IBAction func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) {
  420. var forward = true
  421. var findString: String?
  422. }
  423. @IBAction func menuItemAction_showInFinder(_ sender: Any) {
  424. if let mainVC = self.mainViewController() {
  425. mainVC.showInFinder()
  426. }
  427. }
  428. @IBAction func menuItemAction_property(_ sender: Any) {
  429. if let mainVC = self.mainViewController() {
  430. KMInfoWindowController.shared.showWindow(sender)
  431. }
  432. }
  433. @IBAction func menuItemAction_print(_ sender: Any) {
  434. if let mainVC = self.mainViewController() {
  435. mainVC.showPrintWindow()
  436. }
  437. }
  438. @IBAction func menuItemAction_customPrint(_ sender: NSMenuItem) {
  439. if let mainVC = self.mainViewController() {
  440. if sender.tag == 0 {
  441. mainVC.showPosterPrintWindow()
  442. } else if sender.tag == 1 {
  443. mainVC.showMultiplePrintWindow()
  444. } else if sender.tag == 2 {
  445. mainVC.showBookletPrintWindow()
  446. }
  447. }
  448. }
  449. }
  450. // MARK: - Edit Menu
  451. extension AppDelegate {
  452. func isEditMenuActions(sel: Selector?) -> Bool {
  453. guard let selector = sel else {
  454. return false
  455. }
  456. let selectors = [NSSelectorFromString("menuItemAction_undo:"),
  457. NSSelectorFromString("menuItemAction_redo:"),
  458. NSSelectorFromString("menuItemAction_Copy:"),
  459. NSSelectorFromString("menuItemAction_Cut:"),
  460. NSSelectorFromString("menuItemAction_Paste:"),
  461. NSSelectorFromString("menuItemAction_PasteAndMatch:"),
  462. NSSelectorFromString("menuItemAction_Delete:"),
  463. NSSelectorFromString("menuItemAction_SelectAll:"),
  464. NSSelectorFromString("menuItemAction_ShowFont:"),
  465. NSSelectorFromString("menuItemAction_FontAction:"),
  466. NSSelectorFromString("menuItemAction_CustomFont:"),
  467. NSSelectorFromString("menuItemAction_FontAlign:")]
  468. if selectors.contains(selector) {
  469. return true
  470. }
  471. return false
  472. }
  473. func validateEditMenuItem(_ menuItem: NSMenuItem) -> Bool {
  474. let action = menuItem.action
  475. if let mainVC = self.mainViewController() {
  476. if action == NSSelectorFromString("menuItemAction_undo:") {
  477. } else if action == NSSelectorFromString("menuItemAction_redo:") {
  478. } else if action == NSSelectorFromString("menuItemAction_Copy:") {
  479. } else if action == NSSelectorFromString("menuItemAction_Cut:") {
  480. } else if action == NSSelectorFromString("menuItemAction_Paste:") {
  481. } else if action == NSSelectorFromString("menuItemAction_PasteAndMatch:") {
  482. } else if action == NSSelectorFromString("menuItemAction_Delete:") {
  483. } else if action == NSSelectorFromString("menuItemAction_SelectAll:") {
  484. } else if action == NSSelectorFromString("menuItemAction_ShowFont:") {
  485. } else if action == NSSelectorFromString("menuItemAction_FontAction:") {
  486. } else if action == NSSelectorFromString("menuItemAction_CustomFont:") {
  487. } else if action == NSSelectorFromString("menuItemAction_FontAlign:") {
  488. }
  489. return true
  490. }
  491. return false
  492. }
  493. //MARK: -IBAction
  494. @IBAction func menuItemAction_undo(_ sender: NSMenuItem) {
  495. }
  496. @IBAction func menuItemAction_redo(_ sender: NSMenuItem) {
  497. }
  498. @IBAction func menuItemAction_Copy(_ sender: NSMenuItem) {
  499. }
  500. @IBAction func menuItemAction_Cut(_ sender: NSMenuItem) {
  501. }
  502. @IBAction func menuItemAction_Paste(_ sender: NSMenuItem) {
  503. }
  504. @IBAction func menuItemAction_PasteAndMatch(_ sender: NSMenuItem) {
  505. }
  506. @IBAction func menuItemAction_Delete(_ sender: NSMenuItem) {
  507. }
  508. @IBAction func menuItemAction_SelectAll(_ sender: NSMenuItem) {
  509. }
  510. @IBAction func menuItemAction_ShowFont(_ sender: NSMenuItem) {
  511. NSFontManager.shared.orderFrontFontPanel(nil)
  512. }
  513. @IBAction func menuItemAction_FontAction(_ sender: Any) {
  514. }
  515. @IBAction func menuItemAction_CustomFont(_ sender: NSMenuItem) {
  516. }
  517. @IBAction func menuItemAction_FontAlign(_ sender: NSMenuItem) {
  518. }
  519. }
  520. // MARK: - View Menu
  521. extension AppDelegate {
  522. func isViewMenuActions(sel: Selector?) -> Bool {
  523. guard let selector = sel else {
  524. return false
  525. }
  526. let selectors = [NSSelectorFromString("menuItemAction_ChangeDisplayMode:"),
  527. NSSelectorFromString("menuItemAction_ReadMode:"),
  528. NSSelectorFromString("menuItemAction_FullScreen:"),
  529. NSSelectorFromString("menuItemAction_Presentation:"),
  530. NSSelectorFromString("menuItemAction_SplitView:"),
  531. NSSelectorFromString("menuItemAction_BOTAMode:"),
  532. NSSelectorFromString("menuItemAction_Outline:"),
  533. NSSelectorFromString("menuItemAction_Notes:"),
  534. NSSelectorFromString("menuItemAction_Annotate:"),
  535. NSSelectorFromString("menuItemAction_Themes:"),
  536. NSSelectorFromString("menuItemAction_Zoom:"),
  537. NSSelectorFromString("menuItemAction_Rotate:"),
  538. NSSelectorFromString("menuItemAction_HighlightFormsField:"),
  539. NSSelectorFromString("menuItemAction_HighlightLinks:"),
  540. NSSelectorFromString("menuItemAction_ResetForm:"),
  541. NSSelectorFromString("menuItemAction_AutoScroll:")]
  542. if selectors.contains(selector) {
  543. return true
  544. }
  545. return false
  546. }
  547. func validateViewMenuItem(_ menuItem: NSMenuItem) -> Bool {
  548. let action = menuItem.action
  549. if let mainVC = self.mainViewController() {
  550. if action == NSSelectorFromString("menuItemAction_ChangeDisplayMode:") {
  551. } else if action == NSSelectorFromString("menuItemAction_ReadMode:") {
  552. } else if action == NSSelectorFromString("menuItemAction_FullScreen:") {
  553. } else if action == NSSelectorFromString("menuItemAction_Presentation:") {
  554. } else if action == NSSelectorFromString("menuItemAction_SplitView:") {
  555. } else if action == NSSelectorFromString("menuItemAction_BOTAMode:") {
  556. } else if action == NSSelectorFromString("menuItemAction_Themes:") {
  557. } else if action == NSSelectorFromString("menuItemAction_Zoom:") {
  558. } else if action == NSSelectorFromString("menuItemAction_Rotate:") {
  559. } else if action == NSSelectorFromString("menuItemAction_HighlightFormsField:") {
  560. } else if action == NSSelectorFromString("menuItemAction_HighlightLinks:") {
  561. } else if action == NSSelectorFromString("menuItemAction_ResetForm:") {
  562. } else if action == NSSelectorFromString("menuItemAction_AutoScroll:") {
  563. }
  564. return true
  565. }
  566. return false
  567. }
  568. //MARK: -IBAction
  569. @IBAction func menuItemAction_ChangeDisplayMode(_ sender: NSMenuItem) {
  570. if let mainVC = self.mainViewController() {
  571. if sender.tag == 1 {
  572. mainVC.updatePDFViewDisplayMode(viewMode: .singlePage)
  573. } else if sender.tag == 2 {
  574. mainVC.updatePDFViewDisplayMode(viewMode: .singlePageContinuous)
  575. } else if sender.tag == 3 {
  576. mainVC.updatePDFViewDisplayMode(viewMode: .twoUp)
  577. } else if sender.tag == 4 {
  578. mainVC.updatePDFViewDisplayMode(viewMode: .twoUpContinuous)
  579. } else if sender.tag == 5 {
  580. mainVC.updatePDFViewDisplayMode(isbookMode: true)
  581. }
  582. }
  583. }
  584. @IBAction func menuItemAction_ReadMode(_ sender: NSMenuItem) {
  585. if let mainVC = self.mainViewController() {
  586. mainVC.viewManager.isPDFReadMode = !mainVC.viewManager.isPDFReadMode
  587. if mainVC.viewManager.isPDFReadMode {
  588. mainVC.openPDFReadMode()
  589. } else {
  590. mainVC.exitPDFReadMode()
  591. }
  592. }
  593. }
  594. @IBAction func menuItemAction_FullScreen(_ sender: NSMenuItem) {
  595. if let mainVC = self.mainViewController() {
  596. mainVC.view.window?.toggleFullScreen(nil)
  597. }
  598. }
  599. @IBAction func menuItemAction_Presentation(_ sender: NSMenuItem) {
  600. if let mainVC = self.mainViewController() {
  601. mainVC.togglePresentation(nil)
  602. }
  603. }
  604. @IBAction func menuItemAction_SplitView(_ sender: NSMenuItem) {
  605. if let mainVC = self.mainViewController() {
  606. if sender.tag == 0 {
  607. mainVC.listView.viewSplitMode = .vertical
  608. } else if sender.tag == 1 {
  609. mainVC.listView.viewSplitMode = .horizontal
  610. } else if sender.tag == 2 {
  611. mainVC.listView.viewSplitMode = .disable
  612. }
  613. mainVC.reloadPDFSplitInfo()
  614. }
  615. }
  616. @IBAction func menuItemAction_BOTAMode(_ sender: NSMenuItem) {
  617. if let mainVC = self.mainViewController() {
  618. if sender.tag == 0 {
  619. if mainVC.viewManager.pdfSideBarType == .thumbnail {
  620. mainVC.viewManager.pdfSideBarType = .none
  621. } else {
  622. mainVC.viewManager.pdfSideBarType = .thumbnail
  623. }
  624. } else if sender.tag == 1 {
  625. if mainVC.viewManager.pdfSideBarType == .outline {
  626. mainVC.viewManager.pdfSideBarType = .none
  627. } else {
  628. mainVC.viewManager.pdfSideBarType = .outline
  629. }
  630. } else if sender.tag == 2 {
  631. if mainVC.viewManager.pdfSideBarType == .bookmark {
  632. mainVC.viewManager.pdfSideBarType = .none
  633. } else {
  634. mainVC.viewManager.pdfSideBarType = .bookmark
  635. }
  636. } else if sender.tag == 3 {
  637. if mainVC.viewManager.pdfSideBarType == .annotation {
  638. mainVC.viewManager.pdfSideBarType = .none
  639. } else {
  640. mainVC.viewManager.pdfSideBarType = .annotation
  641. }
  642. }
  643. if mainVC.viewManager.pdfSideBarType == .none {
  644. mainVC.toggleCloseLeftSide()
  645. } else {
  646. mainVC.toggleOpenLeftSide(pdfSideBarType: mainVC.viewManager.pdfSideBarType)
  647. }
  648. mainVC.reloadSideBar()
  649. }
  650. }
  651. @IBAction func menuItemAction_Themes(_ sender: NSMenuItem) {
  652. if let mainVC = self.mainViewController() {
  653. var model: KMPDFViewMode = .normal
  654. var color = NSColor.clear
  655. if sender.tag == 0 {
  656. model = .normal
  657. } else if sender.tag == 1 {
  658. model = .soft
  659. } else if sender.tag == 2 {
  660. model = .green
  661. } else if sender.tag == 3 {
  662. model = .night
  663. } else {
  664. model = .other
  665. }
  666. mainVC.listView.setPageBackgroundColorWith(color, viewMode: model)
  667. }
  668. }
  669. @IBAction func menuItemAction_Zoom(_ sender: NSMenuItem) {
  670. if let mainVC = self.mainViewController() {
  671. var type: KMPDFZoomType = .width
  672. if sender.tag == 0 {
  673. type = .width
  674. } else if sender.tag == 1 {
  675. type = .fit
  676. } else if sender.tag == 2 {
  677. type = .actualSize
  678. } else if sender.tag == 3 {
  679. type = .zoom_In
  680. } else if sender.tag == 4 {
  681. type = .zoom_Out
  682. }
  683. mainVC.selectZoom(type)
  684. }
  685. }
  686. @IBAction func menuItemAction_Rotate(_ sender: NSMenuItem) {
  687. if let mainVC = self.mainViewController() {
  688. if sender.tag == 0 {
  689. mainVC.rotateLeft(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  690. } else if sender.tag == 1 {
  691. mainVC.rotateRight(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  692. }
  693. }
  694. }
  695. @IBAction func menuItemAction_HighlightFormsField(_ sender: NSMenuItem) {
  696. if let mainVC = self.mainViewController() {
  697. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  698. CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled)
  699. mainVC.listView.setNeedsDisplayForVisiblePages()
  700. }
  701. }
  702. @IBAction func menuItemAction_HighlightLinks(_ sender: NSMenuItem) {
  703. if let mainVC = self.mainViewController() {
  704. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  705. CPDFAnnotation.updateLinkFieldHighlight(mainVC.listView, linkFieldHighlight: !enabled)
  706. }
  707. }
  708. @IBAction func menuItemAction_ResetForm(_ sender: NSMenuItem) {
  709. if let mainVC = self.mainViewController() {
  710. mainVC.listView.resetFormAnnotation()
  711. }
  712. }
  713. @IBAction func menuItemAction_AutoScroll(_ sender: NSMenuItem) {
  714. if let mainVC = self.mainViewController() {
  715. mainVC.toggleAutoFlow(nil)
  716. }
  717. }
  718. }
  719. // MARK: - Go Menu
  720. extension AppDelegate {
  721. func isGoMenuActions(sel: Selector?) -> Bool {
  722. guard let selector = sel else {
  723. return false
  724. }
  725. let selectors = [NSSelectorFromString("menuItemAction_Next:"),
  726. NSSelectorFromString("menuItemAction_Previous:"),
  727. NSSelectorFromString("menuItemAction_First:"),
  728. NSSelectorFromString("menuItemAction_Last:"),
  729. NSSelectorFromString("menuItemAction_GotoPage:"),
  730. NSSelectorFromString("menuItemAction_Back:"),
  731. NSSelectorFromString("menuItemAction_Forward:")]
  732. if selectors.contains(selector) {
  733. return true
  734. }
  735. return false
  736. }
  737. func validateGoMenuItem(_ menuItem: NSMenuItem) -> Bool {
  738. let action = menuItem.action
  739. if let mainVC = self.mainViewController() {
  740. if action == NSSelectorFromString("menuItemAction_Next:") {
  741. if mainVC.listView.isEditing() && mainVC.listView.isEditable() {
  742. return false
  743. }
  744. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToNextPage())
  745. } else if action == NSSelectorFromString("menuItemAction_Previous:") {
  746. if mainVC.listView.isEditing() && mainVC.listView.isEditable() {
  747. return false
  748. }
  749. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToPreviousPage())
  750. } else if action == NSSelectorFromString("menuItemAction_First:") {
  751. return mainVC.listView.canGoToFirstPage()
  752. } else if action == NSSelectorFromString("menuItemAction_Last:") {
  753. return mainVC.listView.canGoToLastPage()
  754. } else if action == NSSelectorFromString("menuItemAction_GotoPage:") {
  755. return true
  756. } else if action == NSSelectorFromString("menuItemAction_Back:") {
  757. return mainVC.listView.km_canGoBack()
  758. } else if action == NSSelectorFromString("menuItemAction_Forward:") {
  759. return mainVC.listView.km_canGoForward()
  760. }
  761. }
  762. return false
  763. }
  764. //MARK: -IBAction
  765. @IBAction func menuItemAction_Next(_ sender: NSMenuItem) {
  766. if let mainVC = self.mainViewController() {
  767. if (mainVC.listView.canGoToNextPage()) {
  768. mainVC.listView.goToNextPage(nil)
  769. }
  770. }
  771. }
  772. @IBAction func menuItemAction_Previous(_ sender: NSMenuItem) {
  773. if let mainVC = self.mainViewController() {
  774. if (mainVC.listView.canGoToPreviousPage()) {
  775. mainVC.listView.goToPreviousPage(nil)
  776. }
  777. }
  778. }
  779. @IBAction func menuItemAction_First(_ sender: NSMenuItem) {
  780. if let mainVC = self.mainViewController() {
  781. mainVC.listView.goToFirstPage(nil)
  782. }
  783. }
  784. @IBAction func menuItemAction_Last(_ sender: NSMenuItem) {
  785. if let mainVC = self.mainViewController() {
  786. mainVC.listView.goToLastPage(nil)
  787. }
  788. }
  789. @IBAction func menuItemAction_GotoPage(_ sender: NSMenuItem) {
  790. if let mainVC = self.mainViewController() {
  791. mainVC.gotoPage(nil)
  792. }
  793. }
  794. @IBAction func menuItemAction_Back(_ sender: NSMenuItem) {
  795. if let mainVC = self.mainViewController() {
  796. if (mainVC.listView.km_canGoBack()) {
  797. mainVC.listView.km_goBack(nil)
  798. }
  799. }
  800. }
  801. @IBAction func menuItemAction_Forward(_ sender: NSMenuItem) {
  802. if let mainVC = self.mainViewController() {
  803. if (mainVC.listView.km_canGoForward()) {
  804. mainVC.listView.km_goForward(nil)
  805. }
  806. }
  807. }
  808. }
  809. // MARK: - Window Menu
  810. extension AppDelegate {
  811. func isWindowMenuActions(sel: Selector?) -> Bool {
  812. guard let selector = sel else {
  813. return false
  814. }
  815. var selectors = [NSSelectorFromString("11:"),
  816. NSSelectorFromString("11:")]
  817. if selectors.contains(selector) {
  818. return true
  819. }
  820. return false
  821. }
  822. func validateWindowMenuItem(_ menuItem: NSMenuItem) -> Bool {
  823. return true
  824. }
  825. //MARK: -IBAction
  826. }
  827. // MARK: - help Menu
  828. extension AppDelegate {
  829. func isHelpMenuActions(sel: Selector?) -> Bool {
  830. guard let selector = sel else {
  831. return false
  832. }
  833. var selectors = [NSSelectorFromString("menuItemAction_APPWebSite:"),
  834. NSSelectorFromString("menuItemAction_quickStudy:"),
  835. NSSelectorFromString("menuItemAction_OnlineHelp:"),
  836. NSSelectorFromString("menuItemAction_Feedback:"),
  837. NSSelectorFromString("menuItemAction_FiveStar:"),
  838. NSSelectorFromString("menuItemAction_SubscribeUs:"),
  839. NSSelectorFromString("menuItemAction_CheckForUpdate:"),
  840. NSSelectorFromString("menuItemAction_VPP:"),
  841. NSSelectorFromString("menuItemAction_FreeTemplate:"),
  842. NSSelectorFromString("menuItemAction_MoreProducts:"),
  843. NSSelectorFromString("menuItemAction_PowerBy:"),
  844. NSSelectorFromString("menuItemAction_privacyPolicy:"),
  845. NSSelectorFromString("menuItemAction_TermsofService:")]
  846. if selectors.contains(selector) {
  847. return true
  848. }
  849. return false
  850. }
  851. func validateHelpMenuItem(_ menuItem: NSMenuItem) -> Bool {
  852. return true
  853. }
  854. //MARK: -IBAction
  855. @IBAction func menuItemAction_APPWebSite(_ sender: NSMenuItem) -> Void {
  856. KMTools.openURL(urlString: APPMain_Link)
  857. }
  858. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  859. KMTools.openQuickStartStudy()
  860. }
  861. @IBAction func menuItemAction_OnlineHelp(_ sender: NSMenuItem) -> Void {
  862. KMTools.openFAQWebsite()
  863. }
  864. @IBAction func menuItemAction_Feedback(_ sender: NSMenuItem) -> Void {
  865. KMTools.feekback()
  866. }
  867. @IBAction func menuItemAction_FiveStar(_ sender: NSMenuItem) -> Void {
  868. KMTools.rateUs()
  869. }
  870. @IBAction func menuItemAction_SubscribeUs(_ sender: NSMenuItem) -> Void {
  871. KMEmailSubWindowController().showWindow(nil)
  872. }
  873. @IBAction func menuItemAction_CheckForUpdate(_ sender: NSMenuItem) -> Void {
  874. #if VERSION_DMG
  875. SUUpdater.shared().checkForUpdates(sender)
  876. #endif
  877. }
  878. @IBAction func menuItemAction_VPP(_ sender: NSMenuItem) -> Void {
  879. KMTools.openVPPWebSite()
  880. }
  881. @IBAction func menuItemAction_FreeTemplate(_ sender: NSMenuItem) -> Void {
  882. KMTools.openFreePDFTemplatesWebsite()
  883. }
  884. @IBAction func menuItemAction_MoreProducts(_ sender: NSMenuItem) -> Void {
  885. KMTools.openMoreProductWebsite()
  886. }
  887. @IBAction func menuItemAction_PowerBy(_ sender: NSMenuItem) -> Void {
  888. KMTools.openComPDFKitPowerWebsite()
  889. }
  890. @IBAction func menuItemAction_privacyPolicy(_ sender: NSMenuItem) -> Void {
  891. KMTools.openPrivacyPolicyWebSite()
  892. }
  893. @IBAction func menuItemAction_TermsofService(_ sender: NSMenuItem) -> Void {
  894. KMTools.openTermOfServiceWebSite()
  895. }
  896. }