AppDelegate+MenuAction.swift 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. return false
  28. }
  29. func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool {
  30. return true
  31. }
  32. // MARK: - update Menu
  33. func initMainMenu() {
  34. // 处理菜单栏多语
  35. let mainMenu = NSApp.mainMenu
  36. if (mainMenu == nil) {
  37. return
  38. }
  39. for menu in mainMenu!.items {
  40. let subMenu = menu.submenu
  41. for item in subMenu!.items {
  42. item.title = KMLocalizedString(item.title, comment: "")
  43. let itemSubMenu = item.submenu
  44. if (itemSubMenu == nil) {
  45. continue
  46. }
  47. for item in itemSubMenu!.items {
  48. item.title = KMLocalizedString(item.title, comment: "")
  49. let itemSubMenu = item.submenu
  50. if (itemSubMenu == nil) {
  51. continue
  52. }
  53. for item in itemSubMenu!.items {
  54. item.title = KMLocalizedString(item.title, comment: "")
  55. }
  56. }
  57. }
  58. }
  59. //appMenu
  60. let appMenu = mainMenu?.item(at: 0)?.submenu
  61. if let item = appMenu?.item(at: 0) {
  62. item.title = KMLocalizedString("About") + " " + KMNAppName
  63. }
  64. //Share Item
  65. let fileMenu = mainMenu?.item(at: 1)?.submenu
  66. for item in fileMenu?.items ?? [] {
  67. if item.action == NSSelectorFromString("menuItemAction_showInFinder:") {
  68. let shareItem: NSMenuItem? = NSMenuItem(title: KMLocalizedString("Share"), action: nil, target: nil)
  69. fileMenu?.insertItem(shareItem!, at: item.index)
  70. shareItem?.submenu = NSSharingServicePicker.menu(forSharingItems: [""], subjectContext: "", withTarget: self, selector: #selector(sharePageItemAction), serviceDelegate: nil)
  71. }
  72. }
  73. self.updateAppMenu()
  74. }
  75. @objc func sharePageItemAction(sender: NSMenuItem) {
  76. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  77. return
  78. }
  79. let windowControler = NSApp.mainWindow?.windowController as! KMBrowserWindowController
  80. let model = windowControler.browser?.tabStripModel
  81. if let cnt = model?.count(), cnt <= 0 {
  82. return
  83. }
  84. if let data = model?.activeTabContents()?.isHome, data {
  85. return
  86. }
  87. let document: KMMainDocument = model?.activeTabContents() as! KMMainDocument
  88. if let data = document.mainViewController?.saveWatermarkFlag, !data {
  89. let represent : NSSharingService = sender.representedObject as! NSSharingService
  90. represent.perform(withItems: [document.fileURL as Any])
  91. return
  92. }
  93. let represent : NSSharingService = sender.representedObject as! NSSharingService
  94. represent.perform(withItems: [document.fileURL as Any])
  95. }
  96. @objc func accountRefreshAction() {
  97. }
  98. }
  99. // MARK: - PDF Reader Pro Menu
  100. extension AppDelegate {
  101. func isPDFReaderProMenuActions(sel: Selector?) -> Bool {
  102. guard let selector = sel else {
  103. return false
  104. }
  105. let selectors = [NSSelectorFromString("menuItemAction_openPreferenceWindow:"),
  106. NSSelectorFromString("menuItemAction_loginMenuItemAction:"),
  107. NSSelectorFromString("menuItemAction_logoutMenuItemAction:"),
  108. NSSelectorFromString("menuItemAction_buyNowItemAction:"),
  109. NSSelectorFromString("menuItemAction_restoreMenuItemAction:"),
  110. NSSelectorFromString("menuItemAction_EducationDiscountAction:"),
  111. NSSelectorFromString("menuItemAction_volumeDiscount:")]
  112. if selectors.contains(selector) {
  113. return true
  114. }
  115. return false
  116. }
  117. func validatePDFReaderProMenuItem(_ menuItem: NSMenuItem) -> Bool {
  118. updateAppMenu()
  119. return true
  120. }
  121. //MARK: -IBAction
  122. @IBAction func menuItemAction_openPreferenceWindow(_ sender: Any) {
  123. SettingsWindowController.shared.showWindow(self)
  124. }
  125. @IBAction func menuItemAction_loginMenuItemAction(_ sender: Any) {
  126. if KMMemberInfo.shared.isLogin {
  127. KMUserInfoVCModel().skipAccountCenter()
  128. } else {
  129. KMLoginWindowsController.shared.showWindow(nil)
  130. }
  131. }
  132. @IBAction func menuItemAction_logoutMenuItemAction(_ sender: Any) {
  133. KMUserInfoVCModel().signOutAction()
  134. }
  135. @IBAction func menuItemAction_buyNowItemAction(_ sender: Any) {
  136. }
  137. @IBAction func menuItemAction_restoreMenuItemAction(_ sender: Any) {
  138. }
  139. @IBAction func menuItemAction_EducationDiscountAction(_ sender: NSMenuItem) {
  140. KMTools.openEducateWebSite()
  141. }
  142. @IBAction func menuItemAction_volumeDiscount(_ sender: NSMenuItem) {
  143. KMTools.openVPPWebSite()
  144. }
  145. func updateAppMenu() {
  146. guard let mainMenu = NSApp.mainMenu else {
  147. return
  148. }
  149. for item in mainMenu.items {
  150. for subItem in item.submenu?.items ?? [] {
  151. if subItem.action == NSSelectorFromString("menuItemAction_loginMenuItemAction:") {
  152. if KMMemberInfo.shared.isLogin {
  153. subItem.title = KMMemberInfo.shared.userEmail
  154. } else {
  155. subItem.title = KMLocalizedString("Login")
  156. }
  157. } else if subItem.action == NSSelectorFromString("menuItemAction_logoutMenuItemAction:") {
  158. subItem.isHidden = KMMemberInfo.shared.isLogin ? false : true
  159. }
  160. #if VERSION_BETA
  161. if subItem.action == NSSelectorFromString("menuItemAction_buyNowItemAction:") {
  162. subItem.isHidden = true
  163. } else if subItem.action == NSSelectorFromString("menuItemAction_restoreMenuItemAction:") {
  164. subItem.isHidden = true
  165. } else if subItem.action == NSSelectorFromString("menuItemAction_EducationDiscountAction:") {
  166. subItem.isHidden = true
  167. } else if subItem.action == NSSelectorFromString("menuItemAction_volumeDiscount:") {
  168. subItem.isHidden = true
  169. } else if subItem.action == NSSelectorFromString("menuItemAction_FiveStar:") {
  170. subItem.isHidden = true
  171. } else if subItem.action == NSSelectorFromString("menuItemAction_CheckForUpdate:") {
  172. subItem.isHidden = true
  173. } else if subItem.action == NSSelectorFromString("menuItemAction_VPP:") {
  174. subItem.isHidden = true
  175. }
  176. #endif
  177. }
  178. }
  179. }
  180. }
  181. //MARK: - File Menu
  182. extension AppDelegate {
  183. func isFileMenuActions(sel: Selector?) -> Bool {
  184. guard let selector = sel else {
  185. return false
  186. }
  187. let selectors = [NSSelectorFromString("menuItemAction_NewFromFile:"),
  188. NSSelectorFromString("menuItemAction_Open:"),
  189. NSSelectorFromString("menuItemAction_NewTab:"),
  190. NSSelectorFromString("menuItemAction_NewWindow:"),
  191. NSSelectorFromString("menuItemAction_NewFromWeb:"),
  192. NSSelectorFromString("menuItemAction_NewFromClipboard:"),
  193. NSSelectorFromString("menuItemAction_NewFromScanner:"),
  194. NSSelectorFromString("menuItemAction_NewFromBlankPage:"),
  195. NSSelectorFromString("menuItemAction_NewFromWindow:"),
  196. NSSelectorFromString("menuItemAction_MergePDFFiles:"),
  197. NSSelectorFromString("menuItemAction_closeDocument:"),
  198. NSSelectorFromString("menuItemAction_closeWindow:"),
  199. NSSelectorFromString("menuItemAction_closeAllWindows:"),
  200. NSSelectorFromString("menuItemClick_saveAsFlattenedPDF:"),
  201. NSSelectorFromString("menuItemClick_Compress:"),
  202. NSSelectorFromString("menuItemAction_ConvertTo:"),
  203. NSSelectorFromString("menuItemAction_addPassword:"),
  204. NSSelectorFromString("menuItemAction_removePassword:"),
  205. NSSelectorFromString("menuItemAction_unlockFunction:"),
  206. NSSelectorFromString("menuItemAction_searchPDF:"),
  207. NSSelectorFromString("menuItemAction_performFindPanelAction:"),
  208. NSSelectorFromString("menuItemAction_showInFinder:"),
  209. NSSelectorFromString("menuItemAction_property:"),
  210. NSSelectorFromString("menuItemAction_print:"),
  211. NSSelectorFromString("menuItemAction_customPrint:"),
  212. NSSelectorFromString("sharePageItemActionWithSender:")]
  213. if selectors.contains(selector) {
  214. return true
  215. }
  216. return false
  217. }
  218. func validateFileMenuItem(_ menuItem: NSMenuItem) -> Bool {
  219. let action = menuItem.action
  220. if action == NSSelectorFromString("menuItemAction_NewFromFile:") {
  221. return true
  222. } else if action == NSSelectorFromString("menuItemAction_NewFromWeb:") {
  223. return true
  224. } else if action == NSSelectorFromString("menuItemAction_NewFromClipboard:") {
  225. return true
  226. } else if action == NSSelectorFromString("menuItemAction_NewFromScanner:") {
  227. return true
  228. } else if action == NSSelectorFromString("menuItemAction_NewFromBlankPage:") {
  229. return true
  230. } else if action == NSSelectorFromString("menuItemAction_NewFromWindow:") {
  231. return true
  232. } else if action == NSSelectorFromString("menuItemAction_MergePDFFiles:") {
  233. return true
  234. } else if action == NSSelectorFromString("menuItemAction_closeDocument:") {
  235. return true
  236. } else if action == NSSelectorFromString("menuItemAction_closeWindow:") {
  237. return true
  238. } else if action == NSSelectorFromString("menuItemAction_closeAllWindows:") {
  239. return true
  240. } else if action == NSSelectorFromString("menuItemAction_Open:") {
  241. return true
  242. } else if action == NSSelectorFromString("menuItemAction_NewTab:") {
  243. return true
  244. } else if action == NSSelectorFromString("menuItemAction_NewWindow:") {
  245. return true
  246. }
  247. if let mainVC = self.mainViewController() {
  248. if action == NSSelectorFromString("menuItemClick_saveAsFlattenedPDF:") {
  249. } else if action == NSSelectorFromString("menuItemClick_Compress:") {
  250. } else if action == NSSelectorFromString("menuItemAction_ConvertTo:") {
  251. } else if action == NSSelectorFromString("menuItemAction_addPassword:") {
  252. } else if action == NSSelectorFromString("menuItemAction_removePassword:") {
  253. if mainVC.listView.document.isLocked == true {
  254. return true
  255. } else {
  256. if let pw = mainVC.listView.document.password {
  257. return true
  258. }
  259. return false
  260. }
  261. } else if action == NSSelectorFromString("menuItemAction_unlockFunction:") {
  262. return mainVC.listView.document.isEncrypted
  263. } else if action == NSSelectorFromString("menuItemAction_searchPDF:") {
  264. } else if action == NSSelectorFromString("menuItemAction_performFindPanelAction:") {
  265. } else if action == NSSelectorFromString("menuItemAction_showInFinder:") {
  266. } else if action == NSSelectorFromString("menuItemAction_property:") {
  267. } else if action == NSSelectorFromString("menuItemAction_print:") {
  268. return mainVC.validPrint()
  269. } else if action == NSSelectorFromString("menuItemAction_customPrint:") {
  270. } else if action == NSSelectorFromString("sharePageItemActionWithSender:") {
  271. return true
  272. }
  273. return true
  274. }
  275. return false
  276. }
  277. //MARK: -IBAction
  278. @IBAction func menuItemAction_Open(_ sender: NSMenuItem) -> Void {
  279. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  280. _windowC.newFromPDFFile()
  281. }
  282. }
  283. @IBAction func menuItemAction_NewTab(_ sender: NSMenuItem) -> Void {
  284. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  285. _windowC.openDocumentWindow()
  286. }
  287. }
  288. @IBAction func menuItemAction_NewWindow(_ sender: NSMenuItem) -> Void {
  289. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  290. let browser: KMBrowser = KMBrowser.init()
  291. browser.windowController = KMBrowserWindowController.init(browser: browser)
  292. browser.addHomeTabContents()
  293. browser.windowController.window?.center()
  294. browser.windowController.showWindow(self)
  295. }
  296. }
  297. @IBAction func menuItemAction_NewFromFile(_ sender: NSMenuItem) -> Void {
  298. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  299. _windowC.newFromFile()
  300. }
  301. }
  302. @IBAction func menuItemAction_NewFromWeb(_ sender: NSMenuItem) -> Void {
  303. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  304. _windowC.newFromWebPage()
  305. }
  306. }
  307. @IBAction func menuItemAction_NewFromClipboard(_ sender: NSMenuItem) -> Void {
  308. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  309. _windowC.newFromClipboard()
  310. }
  311. }
  312. @IBAction func menuItemAction_NewFromScanner(_ sender: NSMenuItem) -> Void {
  313. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  314. _windowC.importFromScanner()
  315. }
  316. }
  317. @IBAction func menuItemAction_NewFromBlankPage(_ sender: NSMenuItem) -> Void {
  318. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  319. _windowC.newBlankPage()
  320. }
  321. }
  322. @IBAction func menuItemAction_NewFromWindow(_ sender: NSMenuItem) -> Void {
  323. if sender.tag == 0 {
  324. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  325. _windowC.screenShot_SelectArea(nil)
  326. }
  327. } else if sender.tag == 1 {
  328. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  329. _windowC.screenShot_Window(nil)
  330. }
  331. } else if sender.tag == 2 {
  332. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  333. _windowC.screenShot_FullScreen(nil)
  334. }
  335. }
  336. }
  337. @IBAction func menuItemAction_MergePDFFiles(_ sender: NSMenuItem) -> Void {
  338. if let homeVC = self.homeViewController() {
  339. homeVC.fastTool_MergePDF()
  340. } else if let mainVC = self.mainViewController() {
  341. mainVC.showMergeWindow()
  342. }
  343. }
  344. @IBAction func menuItemAction_closeDocument(_ sender: Any) {
  345. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  346. guard let windowControler = NSApp.mainWindow?.windowController else {
  347. return
  348. }
  349. windowControler.window?.performClose(nil)
  350. return
  351. }
  352. let windowControler = NSApp.mainWindow?.windowController as? KMBrowserWindowController
  353. if let data = windowControler?.browser, data.tabCount() >= 2 { // 有两个以上的标签
  354. if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应
  355. return
  356. }
  357. }
  358. if let browser = windowControler?.browser {
  359. if browser.tabCount() == 1 {
  360. windowControler?.window?.close()
  361. } else {
  362. if let _ = windowControler?.window?.attachedSheet {
  363. NSSound.beep()
  364. return
  365. }
  366. browser.closeTab()
  367. }
  368. } else {
  369. windowControler?.window?.close()
  370. }
  371. }
  372. @IBAction func menuItemAction_closeWindow(_ sender: Any) {
  373. if let windowVC = self.currentBrowserWindowController() {
  374. if windowVC.browser != nil {
  375. windowVC.browser.closeAllTabs()
  376. }
  377. }
  378. }
  379. @IBAction func menuItemAction_closeAllWindows(_ sender: Any) {
  380. for window in NSApp.windows {
  381. if let windowVC = window.windowController as? KMBrowserWindowController {
  382. if windowVC.browser != nil {
  383. windowVC.browser.closeAllTabs()
  384. }
  385. }
  386. }
  387. }
  388. @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  389. if let mainVC = self.mainViewController() {
  390. mainVC.saveAsFlattenedPDFAction()
  391. }
  392. }
  393. @IBAction func menuItemClick_Compress(_ sender: Any) {
  394. if let mainVC = self.mainViewController() {
  395. let model = KMBatchProcessingTableViewModel.initWithFilePath(url: mainVC.listView.document.documentURL)
  396. model.password = mainVC.listView.document.password ?? ""
  397. mainVC.showCompressController(model: model)
  398. }
  399. }
  400. @IBAction func menuItemAction_ConvertTo(_ sender: NSMenuItem) {
  401. if let mainVC = self.mainViewController() {
  402. var convertType: KMPDFConvertType = .word
  403. if sender.tag == 0 {
  404. } else if sender.tag == 1 {
  405. convertType = .excel
  406. } else if sender.tag == 2 {
  407. convertType = .ppt
  408. } else if sender.tag == 30 {
  409. convertType = .jpeg
  410. } else if sender.tag == 31 {
  411. convertType = .jpg
  412. } else if sender.tag == 32 {
  413. convertType = .png
  414. } else if sender.tag == 33 {
  415. convertType = .gif
  416. } else if sender.tag == 34 {
  417. convertType = .tiff
  418. } else if sender.tag == 35 {
  419. convertType = .tga
  420. } else if sender.tag == 36 {
  421. convertType = .bmp
  422. } else if sender.tag == 37 {
  423. convertType = .jp2
  424. } else if sender.tag == 4 {
  425. convertType = .rtf
  426. } else if sender.tag == 5 {
  427. convertType = .csv
  428. } else if sender.tag == 6 {
  429. convertType = .html
  430. } else if sender.tag == 7 {
  431. convertType = .text
  432. } else if sender.tag == 8 {
  433. convertType = .json
  434. }
  435. mainVC.showConvertWindow(convertType)
  436. }
  437. }
  438. @IBAction func menuItemAction_addPassword(_ sender: Any) {
  439. if let mainVC = self.mainViewController() {
  440. mainVC.showSecureWindow()
  441. }
  442. }
  443. @IBAction func menuItemAction_removePassword(_ sender: Any) {
  444. if let mainVC = self.mainViewController() {
  445. mainVC.showRemoveSecureWindow()
  446. }
  447. }
  448. @IBAction func menuItemAction_unlockFunction(_ sender: Any) {
  449. if let mainVC = self.mainViewController() {
  450. mainVC.unlockPDFDocument()
  451. }
  452. }
  453. @IBAction func menuItemAction_searchPDF(_ sender: Any?) {
  454. if let mainVC = self.mainViewController() {
  455. mainVC.searchPDF()
  456. }
  457. }
  458. @IBAction func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) {
  459. if let mainVC = self.mainViewController() {
  460. if sender.tag == 0 {
  461. mainVC.find_ReplacePDF()
  462. } else if sender.tag == 1 {
  463. mainVC.fineNext()
  464. } else if sender.tag == 2 {
  465. mainVC.findPrevious()
  466. } else if sender.tag == 3 {
  467. mainVC.useSelectionForFind()
  468. }
  469. }
  470. }
  471. @IBAction func menuItemAction_showInFinder(_ sender: Any) {
  472. if let mainVC = self.mainViewController() {
  473. mainVC.showInFinder()
  474. }
  475. }
  476. @IBAction func menuItemAction_property(_ sender: Any) {
  477. if let mainVC = self.mainViewController() {
  478. KMInfoWindowController.shared.showWindow(sender)
  479. }
  480. }
  481. @IBAction func menuItemAction_print(_ sender: Any) {
  482. if let mainVC = self.mainViewController() {
  483. mainVC.showPrintWindow()
  484. }
  485. }
  486. @IBAction func menuItemAction_customPrint(_ sender: NSMenuItem) {
  487. if let mainVC = self.mainViewController() {
  488. if sender.tag == 0 {
  489. mainVC.showPosterPrintWindow()
  490. } else if sender.tag == 1 {
  491. mainVC.showMultiplePrintWindow()
  492. } else if sender.tag == 2 {
  493. mainVC.showBookletPrintWindow()
  494. }
  495. }
  496. }
  497. }
  498. // MARK: - Edit Menu
  499. extension AppDelegate {
  500. func isEditMenuActions(sel: Selector?) -> Bool {
  501. guard let selector = sel else {
  502. return false
  503. }
  504. let selectors = [ NSSelectorFromString("menuItemAction_PasteAndMatch:"),
  505. NSSelectorFromString("menuItemAction_ShowFont:"),
  506. NSSelectorFromString("menuItemAction_FontAction:"),
  507. NSSelectorFromString("menuItemAction_CustomFont:"),
  508. NSSelectorFromString("menuItemAction_FontAlign:")]
  509. if selectors.contains(selector) {
  510. return true
  511. }
  512. return false
  513. }
  514. func validateEditMenuItem(_ menuItem: NSMenuItem) -> Bool {
  515. let action = menuItem.action
  516. if let mainVC = self.mainViewController() {
  517. if action == NSSelectorFromString("menuItemAction_PasteAndMatch:") {
  518. if mainVC.listView.isEditing() {
  519. if mainVC.listView.isSupportPast() {
  520. return true
  521. }
  522. }
  523. return false
  524. } else if action == NSSelectorFromString("menuItemAction_ShowFont:") {
  525. if mainVC.viewManager.toolMode == .Edit {
  526. if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
  527. if mainVC.listView.km_editingTextAreas().count > 0 {
  528. return true
  529. }
  530. }
  531. }
  532. return false
  533. } else if action == NSSelectorFromString("menuItemAction_FontAction:") {
  534. if mainVC.viewManager.toolMode == .Edit {
  535. if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
  536. if mainVC.listView.km_editingTextAreas().count > 0 {
  537. return true
  538. }
  539. }
  540. }
  541. return false
  542. } else if action == NSSelectorFromString("menuItemAction_CustomFont:") {
  543. if mainVC.viewManager.toolMode == .Edit {
  544. if mainVC.viewManager.subToolMode == .None || mainVC.viewManager.subToolMode == .Edit_text {
  545. if mainVC.listView.km_editingTextAreas().count > 0 {
  546. return true
  547. }
  548. }
  549. }
  550. return false
  551. } else if action == NSSelectorFromString("menuItemAction_FontAlign:") {
  552. if mainVC.listView.isEditing() == true {
  553. if mainVC.listView.km_editingTextAreas().count > 0 {
  554. return true
  555. }
  556. } else {
  557. if let freeTextAnnotation = mainVC.listView.activeAnnotation as? CPDFFreeTextAnnotation {
  558. return true
  559. }
  560. }
  561. return false
  562. }
  563. return true
  564. }
  565. return false
  566. }
  567. //MARK: -IBAction
  568. @IBAction func menuItemAction_PasteAndMatch(_ menuItem: NSMenuItem) {
  569. if let mainVC = self.mainViewController() {
  570. if mainVC.listView.isEditing() == true {
  571. if mainVC.listView.isSupportPast() {
  572. mainVC.listView.pasteEditAreaAction()
  573. }
  574. }
  575. }
  576. }
  577. @IBAction func menuItemAction_ShowFont(_ menuItem: NSMenuItem) {
  578. if let mainVC = self.mainViewController() {
  579. mainVC.menuItemAction_FontPanel()
  580. }
  581. }
  582. @IBAction func menuItemAction_FontAction(_ menuItem: NSMenuItem) {
  583. if let mainVC = self.mainViewController() {
  584. mainVC.menuItemAction_FontAction(menuItem.tag)
  585. }
  586. }
  587. @IBAction func menuItemAction_CustomFont(_ menuItem: NSMenuItem) {
  588. if let mainVC = self.mainViewController() {
  589. mainVC.menuItemAction_CustomFont(menuItem.tag)
  590. }
  591. }
  592. @IBAction func menuItemAction_FontAlign(_ menuItem: NSMenuItem) {
  593. if let mainVC = self.mainViewController() {
  594. mainVC.menuItemAction_FontAlign(menuItem.tag)
  595. }
  596. }
  597. }
  598. // MARK: - View Menu
  599. extension AppDelegate {
  600. func isViewMenuActions(sel: Selector?) -> Bool {
  601. guard let selector = sel else {
  602. return false
  603. }
  604. let selectors = [NSSelectorFromString("menuItemAction_ChangeDisplayMode:"),
  605. NSSelectorFromString("menuItemAction_ReadMode:"),
  606. NSSelectorFromString("menuItemAction_FullScreen:"),
  607. NSSelectorFromString("menuItemAction_Presentation:"),
  608. NSSelectorFromString("menuItemAction_SplitView:"),
  609. NSSelectorFromString("menuItemAction_BOTAMode:"),
  610. NSSelectorFromString("menuItemAction_Outline:"),
  611. NSSelectorFromString("menuItemAction_Notes:"),
  612. NSSelectorFromString("menuItemAction_Annotate:"),
  613. NSSelectorFromString("menuItemAction_Themes:"),
  614. NSSelectorFromString("menuItemAction_Zoom:"),
  615. NSSelectorFromString("menuItemAction_Rotate:"),
  616. NSSelectorFromString("menuItemAction_HighlightFormsField:"),
  617. NSSelectorFromString("menuItemAction_HighlightLinks:"),
  618. NSSelectorFromString("menuItemAction_ResetForm:"),
  619. NSSelectorFromString("menuItemAction_AutoScroll:")]
  620. if selectors.contains(selector) {
  621. return true
  622. }
  623. return false
  624. }
  625. func validateViewMenuItem(_ menuItem: NSMenuItem) -> Bool {
  626. let action = menuItem.action
  627. if action == NSSelectorFromString("menuItemAction_FullScreen:") {
  628. return true
  629. }
  630. if let mainVC = self.mainViewController() {
  631. if action == NSSelectorFromString("menuItemAction_ChangeDisplayMode:") {
  632. menuItem.state = .off
  633. if menuItem.tag == 1 && mainVC.getPDFViewPageLayoutType() == .singlePage {
  634. menuItem.state = .on
  635. } else if menuItem.tag == 2 && mainVC.getPDFViewPageLayoutType() == .singlePageContinue {
  636. menuItem.state = .on
  637. } else if menuItem.tag == 3 && mainVC.getPDFViewPageLayoutType() == .twoPage {
  638. menuItem.state = .on
  639. } else if menuItem.tag == 4 && mainVC.getPDFViewPageLayoutType() == .twoPageContinue {
  640. menuItem.state = .on
  641. } else if menuItem.tag == 5 && mainVC.getPDFViewPageLayoutType() == .bookMode {
  642. menuItem.state = .on
  643. }
  644. } else if action == NSSelectorFromString("menuItemAction_ReadMode:") {
  645. menuItem.state = .off
  646. if mainVC.viewManager.isPDFReadMode == true {
  647. menuItem.state = .on
  648. }
  649. } else if action == NSSelectorFromString("menuItemAction_Presentation:") {
  650. } else if action == NSSelectorFromString("menuItemAction_SplitView:") {
  651. menuItem.state = .off
  652. if menuItem.tag == 0 && mainVC.listView.viewSplitMode == .vertical {
  653. menuItem.state = .on
  654. } else if menuItem.tag == 1 && mainVC.listView.viewSplitMode == .horizontal {
  655. menuItem.state = .on
  656. } else if menuItem.tag == 2 && mainVC.listView.viewSplitMode == .disable {
  657. menuItem.state = .on
  658. }
  659. } else if action == NSSelectorFromString("menuItemAction_BOTAMode:") {
  660. menuItem.state = .off
  661. if menuItem.tag == 0 && mainVC.viewManager.pdfSideBarType == .thumbnail {
  662. menuItem.state = .on
  663. } else if menuItem.tag == 1 && mainVC.viewManager.pdfSideBarType == .outline {
  664. menuItem.state = .on
  665. } else if menuItem.tag == 2 && mainVC.viewManager.pdfSideBarType == .bookmark {
  666. menuItem.state = .on
  667. } else if menuItem.tag == 3 && mainVC.viewManager.pdfSideBarType == .annotation {
  668. menuItem.state = .on
  669. } else if menuItem.tag == 4 && mainVC.viewManager.pdfSideBarType == .search {
  670. menuItem.state = .on
  671. }
  672. } else if action == NSSelectorFromString("menuItemAction_Themes:") {
  673. menuItem.state = .off
  674. if menuItem.tag == 0 && mainVC.listView.displayMode == .normal {
  675. menuItem.state = .on
  676. } else if menuItem.tag == 1 && mainVC.listView.displayMode == .soft {
  677. menuItem.state = .on
  678. } else if menuItem.tag == 2 && mainVC.listView.displayMode == .green {
  679. menuItem.state = .on
  680. } else if menuItem.tag == 3 && mainVC.listView.displayMode == .night {
  681. menuItem.state = .on
  682. }
  683. } else if action == NSSelectorFromString("menuItemAction_Zoom:") {
  684. } else if action == NSSelectorFromString("menuItemAction_Rotate:") {
  685. } else if action == NSSelectorFromString("menuItemAction_HighlightFormsField:") {
  686. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  687. menuItem.state = enabled ? .on : .off
  688. } else if action == NSSelectorFromString("menuItemAction_HighlightLinks:") {
  689. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  690. menuItem.state = enabled ? .on : .off
  691. } else if action == NSSelectorFromString("menuItemAction_ResetForm:") {
  692. } else if action == NSSelectorFromString("menuItemAction_AutoScroll:") {
  693. menuItem.state = mainVC.isAutoFlowOn() ? .on : .off
  694. }
  695. return true
  696. }
  697. return false
  698. }
  699. //MARK: -IBAction
  700. @IBAction func menuItemAction_ChangeDisplayMode(_ sender: NSMenuItem) {
  701. if let mainVC = self.mainViewController() {
  702. if sender.tag == 1 {
  703. mainVC.updatePDFViewDisplayMode(viewMode: .singlePage)
  704. } else if sender.tag == 2 {
  705. mainVC.updatePDFViewDisplayMode(viewMode: .singlePageContinuous)
  706. } else if sender.tag == 3 {
  707. mainVC.updatePDFViewDisplayMode(viewMode: .twoUp)
  708. } else if sender.tag == 4 {
  709. mainVC.updatePDFViewDisplayMode(viewMode: .twoUpContinuous)
  710. } else if sender.tag == 5 {
  711. mainVC.updatePDFViewDisplayMode(isbookMode: true)
  712. }
  713. }
  714. }
  715. @IBAction func menuItemAction_ReadMode(_ sender: NSMenuItem) {
  716. if let mainVC = self.mainViewController() {
  717. mainVC.viewManager.isPDFReadMode = !mainVC.viewManager.isPDFReadMode
  718. if mainVC.viewManager.isPDFReadMode {
  719. mainVC.openPDFReadMode()
  720. } else {
  721. mainVC.exitPDFReadMode()
  722. }
  723. }
  724. }
  725. @IBAction func menuItemAction_FullScreen(_ sender: NSMenuItem) {
  726. NSApp.mainWindow?.toggleFullScreen(nil)
  727. }
  728. @IBAction func menuItemAction_Presentation(_ sender: NSMenuItem) {
  729. if let mainVC = self.mainViewController() {
  730. mainVC.togglePresentation(nil)
  731. }
  732. }
  733. @IBAction func menuItemAction_SplitView(_ sender: NSMenuItem) {
  734. if let mainVC = self.mainViewController() {
  735. if sender.tag == 0 {
  736. if KMMemberInfo.shared.isLogin == false {
  737. KMLoginWindowsController.shared.showWindow(nil)
  738. return
  739. }
  740. mainVC.listView.viewSplitMode = .vertical
  741. } else if sender.tag == 1 {
  742. if KMMemberInfo.shared.isLogin == false {
  743. KMLoginWindowsController.shared.showWindow(nil)
  744. return
  745. }
  746. mainVC.listView.viewSplitMode = .horizontal
  747. } else if sender.tag == 2 {
  748. mainVC.listView.viewSplitMode = .disable
  749. }
  750. mainVC.reloadPDFSplitInfo()
  751. }
  752. }
  753. @IBAction func menuItemAction_BOTAMode(_ sender: NSMenuItem) {
  754. if let mainVC = self.mainViewController() {
  755. if sender.tag == 0 {
  756. if mainVC.viewManager.pdfSideBarType == .thumbnail {
  757. mainVC.viewManager.pdfSideBarType = .none
  758. } else {
  759. mainVC.viewManager.pdfSideBarType = .thumbnail
  760. }
  761. } else if sender.tag == 1 {
  762. if mainVC.viewManager.pdfSideBarType == .outline {
  763. mainVC.viewManager.pdfSideBarType = .none
  764. } else {
  765. mainVC.viewManager.pdfSideBarType = .outline
  766. }
  767. } else if sender.tag == 2 {
  768. if mainVC.viewManager.pdfSideBarType == .bookmark {
  769. mainVC.viewManager.pdfSideBarType = .none
  770. } else {
  771. mainVC.viewManager.pdfSideBarType = .bookmark
  772. }
  773. } else if sender.tag == 3 {
  774. if mainVC.viewManager.pdfSideBarType == .annotation {
  775. mainVC.viewManager.pdfSideBarType = .none
  776. } else {
  777. mainVC.viewManager.pdfSideBarType = .annotation
  778. }
  779. } else if sender.tag == 4 {
  780. if mainVC.viewManager.pdfSideBarType == .search {
  781. mainVC.viewManager.pdfSideBarType = .none
  782. } else {
  783. mainVC.viewManager.pdfSideBarType = .search
  784. }
  785. }
  786. if mainVC.viewManager.pdfSideBarType == .none {
  787. mainVC.toggleCloseLeftSide()
  788. } else {
  789. mainVC.toggleOpenLeftSide(pdfSideBarType: mainVC.viewManager.pdfSideBarType)
  790. }
  791. mainVC.reloadSideBar()
  792. }
  793. }
  794. @IBAction func menuItemAction_Themes(_ sender: NSMenuItem) {
  795. if let mainVC = self.mainViewController() {
  796. var model: KMPDFViewMode = .normal
  797. var color = NSColor.clear
  798. if sender.tag == 0 {
  799. model = .normal
  800. } else if sender.tag == 1 {
  801. model = .soft
  802. } else if sender.tag == 2 {
  803. model = .green
  804. } else if sender.tag == 3 {
  805. model = .night
  806. } else {
  807. model = .other
  808. }
  809. if KMMemberInfo.shared.isLogin == false, model != .normal {
  810. KMLoginWindowsController.shared.showWindow(nil)
  811. return
  812. }
  813. mainVC.listView.setPageBackgroundColorWith(color, viewMode: model)
  814. mainVC.updatePDFDisplaySettingView()
  815. }
  816. }
  817. @IBAction func menuItemAction_Zoom(_ sender: NSMenuItem) {
  818. if let mainVC = self.mainViewController() {
  819. var type: KMPDFZoomType = .width
  820. if sender.tag == 0 {
  821. type = .width
  822. } else if sender.tag == 1 {
  823. type = .fit
  824. } else if sender.tag == 2 {
  825. type = .actualSize
  826. } else if sender.tag == 3 {
  827. type = .zoom_In
  828. } else if sender.tag == 4 {
  829. type = .zoom_Out
  830. }
  831. mainVC.selectZoom(type)
  832. }
  833. }
  834. @IBAction func menuItemAction_Rotate(_ sender: NSMenuItem) {
  835. if let mainVC = self.mainViewController() {
  836. if sender.tag == 0 {
  837. mainVC.rotateLeft(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  838. } else if sender.tag == 1 {
  839. mainVC.rotateRight(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  840. }
  841. }
  842. }
  843. @IBAction func menuItemAction_HighlightFormsField(_ sender: NSMenuItem) {
  844. if let mainVC = self.mainViewController() {
  845. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  846. CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled)
  847. mainVC.listView.setNeedsDisplayForVisiblePages()
  848. mainVC.alertTipViewController.reloadFormAlertUI()
  849. }
  850. }
  851. @IBAction func menuItemAction_HighlightLinks(_ sender: NSMenuItem) {
  852. if let mainVC = self.mainViewController() {
  853. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  854. CPDFAnnotation.updateLinkFieldHighlight(mainVC.listView, linkFieldHighlight: !enabled)
  855. }
  856. }
  857. @IBAction func menuItemAction_ResetForm(_ sender: NSMenuItem) {
  858. if let mainVC = self.mainViewController() {
  859. mainVC.listView.resetFormAnnotation()
  860. }
  861. }
  862. @IBAction func menuItemAction_AutoScroll(_ sender: NSMenuItem) {
  863. if let mainVC = self.mainViewController() {
  864. mainVC.toggleAutoFlow(nil)
  865. }
  866. }
  867. }
  868. // MARK: - Go Menu
  869. extension AppDelegate {
  870. func isGoMenuActions(sel: Selector?) -> Bool {
  871. guard let selector = sel else {
  872. return false
  873. }
  874. let selectors = [NSSelectorFromString("menuItemAction_Next:"),
  875. NSSelectorFromString("menuItemAction_Previous:"),
  876. NSSelectorFromString("menuItemAction_First:"),
  877. NSSelectorFromString("menuItemAction_Last:"),
  878. NSSelectorFromString("menuItemAction_GotoPage:"),
  879. NSSelectorFromString("menuItemAction_Back:"),
  880. NSSelectorFromString("menuItemAction_Forward:")]
  881. if selectors.contains(selector) {
  882. return true
  883. }
  884. return false
  885. }
  886. func validateGoMenuItem(_ menuItem: NSMenuItem) -> Bool {
  887. let action = menuItem.action
  888. if let mainVC = self.mainViewController() {
  889. if action == NSSelectorFromString("menuItemAction_Next:") {
  890. if mainVC.listView.isEditing() {
  891. let editingAreas = mainVC.listView.km_EditingAreas()
  892. if(editingAreas.count > 0) {
  893. var isEditSelect = false
  894. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  895. isEditSelect = true
  896. } else {
  897. let editState = mainVC.listView.editStatus()
  898. if (editState == .editSelectText) {// 选择文本
  899. isEditSelect = true
  900. }
  901. }
  902. if isEditSelect {
  903. return true
  904. }
  905. }
  906. }
  907. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToNextPage())
  908. } else if action == NSSelectorFromString("menuItemAction_Previous:") {
  909. if mainVC.listView.isEditing(){
  910. let editingAreas = mainVC.listView.km_EditingAreas()
  911. if(editingAreas.count > 0) {
  912. var isEditSelect = false
  913. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  914. isEditSelect = true
  915. } else {
  916. let editState = mainVC.listView.editStatus()
  917. if (editState == .editSelectText) {// 选择文本
  918. isEditSelect = true
  919. }
  920. }
  921. if isEditSelect {
  922. return true
  923. }
  924. }
  925. }
  926. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToPreviousPage())
  927. } else if action == NSSelectorFromString("menuItemAction_First:") {
  928. if(mainVC.listView.isEditing()) {
  929. let editingAreas = mainVC.listView.km_EditingAreas()
  930. if(editingAreas.count > 0) {
  931. var isEditSelect = false
  932. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  933. isEditSelect = true
  934. } else {
  935. let editState = mainVC.listView.editStatus()
  936. if (editState == .editSelectText) {// 选择文本
  937. isEditSelect = true
  938. }
  939. }
  940. if isEditSelect {
  941. return true
  942. }
  943. }
  944. }
  945. return mainVC.listView.canGoToFirstPage()
  946. } else if action == NSSelectorFromString("menuItemAction_Last:") {
  947. if(mainVC.listView.isEditing()) {
  948. let editingAreas = mainVC.listView.km_EditingAreas()
  949. if(editingAreas.count > 0) {
  950. var isEditSelect = false
  951. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  952. isEditSelect = true
  953. } else {
  954. let editState = mainVC.listView.editStatus()
  955. if (editState == .editSelectText) {// 选择文本
  956. isEditSelect = true
  957. }
  958. }
  959. if isEditSelect {
  960. return true
  961. }
  962. }
  963. }
  964. return mainVC.listView.canGoToLastPage()
  965. } else if action == NSSelectorFromString("menuItemAction_GotoPage:") {
  966. return true
  967. } else if action == NSSelectorFromString("menuItemAction_Back:") {
  968. return mainVC.listView.km_canGoBack()
  969. } else if action == NSSelectorFromString("menuItemAction_Forward:") {
  970. return mainVC.listView.km_canGoForward()
  971. }
  972. }
  973. return false
  974. }
  975. //MARK: -IBAction
  976. @IBAction func menuItemAction_Next(_ sender: NSMenuItem) {
  977. if let mainVC = self.mainViewController() {
  978. if(mainVC.listView.isEditing()) {
  979. mainVC.keyDownEditCmdRight()
  980. } else {
  981. if (mainVC.listView.canGoToNextPage()) {
  982. mainVC.listView.goToNextPage(nil)
  983. }
  984. }
  985. }
  986. }
  987. @IBAction func menuItemAction_Previous(_ sender: NSMenuItem) {
  988. if let mainVC = self.mainViewController() {
  989. if(mainVC.listView.isEditing()) {
  990. mainVC.keyDownEditCmdLeft()
  991. } else {
  992. if (mainVC.listView.canGoToPreviousPage()) {
  993. mainVC.listView.goToPreviousPage(nil)
  994. }
  995. }
  996. }
  997. }
  998. @IBAction func menuItemAction_First(_ sender: NSMenuItem) {
  999. if let mainVC = self.mainViewController() {
  1000. if(mainVC.listView.isEditing()) {
  1001. mainVC.keyDownEditCmdUp()
  1002. } else {
  1003. mainVC.listView.goToFirstPage(nil)
  1004. }
  1005. }
  1006. }
  1007. @IBAction func menuItemAction_Last(_ sender: NSMenuItem) {
  1008. if let mainVC = self.mainViewController() {
  1009. if(mainVC.listView.isEditing()) {
  1010. mainVC.keyDownEditCmdDown()
  1011. } else {
  1012. mainVC.listView.goToLastPage(nil)
  1013. }
  1014. }
  1015. }
  1016. @IBAction func menuItemAction_GotoPage(_ sender: NSMenuItem) {
  1017. if let mainVC = self.mainViewController() {
  1018. mainVC.gotoPage(nil)
  1019. }
  1020. }
  1021. @IBAction func menuItemAction_Back(_ sender: NSMenuItem) {
  1022. if let mainVC = self.mainViewController() {
  1023. if (mainVC.listView.km_canGoBack()) {
  1024. mainVC.listView.km_goBack(nil)
  1025. }
  1026. }
  1027. }
  1028. @IBAction func menuItemAction_Forward(_ sender: NSMenuItem) {
  1029. if let mainVC = self.mainViewController() {
  1030. if (mainVC.listView.km_canGoForward()) {
  1031. mainVC.listView.km_goForward(nil)
  1032. }
  1033. }
  1034. }
  1035. }
  1036. // MARK: - Window Menu
  1037. extension AppDelegate {
  1038. func isWindowMenuActions(sel: Selector?) -> Bool {
  1039. guard let selector = sel else {
  1040. return false
  1041. }
  1042. var selectors = [NSSelectorFromString("menuItemAction_showForwardTagPage:"),
  1043. NSSelectorFromString("menuItemAction_showNextTagPage:"),
  1044. NSSelectorFromString("menuItemAction_mergeAllWindow:")]
  1045. if selectors.contains(selector) {
  1046. return true
  1047. }
  1048. return false
  1049. }
  1050. func validateWindowMenuItem(_ menuItem: NSMenuItem) -> Bool {
  1051. let action = menuItem.action
  1052. if let browser = self.currentKMBrowser() {
  1053. if action == NSSelectorFromString("menuItemAction_showForwardTagPage:") {
  1054. menuItem.keyEquivalent = "\t"
  1055. menuItem.keyEquivalentModifierMask = [.shift, .control]
  1056. return browser.canSelectPreviousTab()
  1057. } else if action == NSSelectorFromString("menuItemAction_showNextTagPage:") {
  1058. return browser.canSelectNextTab()
  1059. }
  1060. }
  1061. if let browserWC = self.currentBrowserWindowController() {
  1062. if action == NSSelectorFromString("menuItemAction_mergeAllWindow:") {
  1063. return browserWC.canMergeAllWindow()
  1064. }
  1065. }
  1066. return true
  1067. }
  1068. //MARK: -IBAction
  1069. @IBAction func menuItemAction_showForwardTagPage(_ sender: NSMenuItem) -> Void {
  1070. if let browser = self.currentKMBrowser() {
  1071. browser.selectPreviousTab()
  1072. }
  1073. }
  1074. @IBAction func menuItemAction_showNextTagPage(_ sender: NSMenuItem) -> Void {
  1075. if let browser = self.currentKMBrowser() {
  1076. browser.selectNextTab()
  1077. }
  1078. }
  1079. @IBAction func menuItemAction_mergeAllWindow(_ sender: NSMenuItem) -> Void {
  1080. if let browserWC = self.currentBrowserWindowController() {
  1081. browserWC.mergeAllWindow(sender)
  1082. }
  1083. }
  1084. }
  1085. // MARK: - help Menu
  1086. extension AppDelegate {
  1087. func isHelpMenuActions(sel: Selector?) -> Bool {
  1088. guard let selector = sel else {
  1089. return false
  1090. }
  1091. var selectors = [NSSelectorFromString("menuItemAction_APPWebSite:"),
  1092. NSSelectorFromString("menuItemAction_quickStudy:"),
  1093. NSSelectorFromString("menuItemAction_OnlineHelp:"),
  1094. NSSelectorFromString("menuItemAction_Feedback:"),
  1095. NSSelectorFromString("menuItemAction_FiveStar:"),
  1096. NSSelectorFromString("menuItemAction_SubscribeUs:"),
  1097. NSSelectorFromString("menuItemAction_CheckForUpdate:"),
  1098. NSSelectorFromString("menuItemAction_VPP:"),
  1099. NSSelectorFromString("menuItemAction_FreeTemplate:"),
  1100. NSSelectorFromString("menuItemAction_MoreProducts:"),
  1101. NSSelectorFromString("menuItemAction_PowerBy:"),
  1102. NSSelectorFromString("menuItemAction_privacyPolicy:"),
  1103. NSSelectorFromString("menuItemAction_TermsofService:")]
  1104. if selectors.contains(selector) {
  1105. return true
  1106. }
  1107. return false
  1108. }
  1109. func validateHelpMenuItem(_ menuItem: NSMenuItem) -> Bool {
  1110. return true
  1111. }
  1112. //MARK: -IBAction
  1113. @IBAction func menuItemAction_APPWebSite(_ sender: NSMenuItem) -> Void {
  1114. KMTools.openURL(urlString: APPMain_Link)
  1115. }
  1116. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  1117. KMTools.openQuickStartStudy()
  1118. }
  1119. @IBAction func menuItemAction_OnlineHelp(_ sender: NSMenuItem) -> Void {
  1120. KMTools.openFAQWebsite()
  1121. }
  1122. @IBAction func menuItemAction_Feedback(_ sender: NSMenuItem) -> Void {
  1123. let help = KMUserFeekbackHanddler()
  1124. help.showFeekbackWindow(with: KMLocalizedString("Feedback", comment: ""))
  1125. }
  1126. @IBAction func menuItemAction_FiveStar(_ sender: NSMenuItem) -> Void {
  1127. KMTools.rateUs()
  1128. }
  1129. @IBAction func menuItemAction_SubscribeUs(_ sender: NSMenuItem) -> Void {
  1130. KMEmailSubWindowController().showWindow(nil)
  1131. }
  1132. @IBAction func menuItemAction_CheckForUpdate(_ sender: NSMenuItem) -> Void {
  1133. #if VERSION_DMG
  1134. SUUpdater.shared().checkForUpdates(sender)
  1135. #endif
  1136. }
  1137. @IBAction func menuItemAction_VPP(_ sender: NSMenuItem) -> Void {
  1138. KMTools.openVPPWebSite()
  1139. }
  1140. @IBAction func menuItemAction_FreeTemplate(_ sender: NSMenuItem) -> Void {
  1141. KMTools.openFreePDFTemplatesWebsite()
  1142. }
  1143. @IBAction func menuItemAction_MoreProducts(_ sender: NSMenuItem) -> Void {
  1144. KMTools.openMoreProductWebsite()
  1145. }
  1146. @IBAction func menuItemAction_PowerBy(_ sender: NSMenuItem) -> Void {
  1147. KMTools.openComPDFKitPowerWebsite()
  1148. }
  1149. @IBAction func menuItemAction_privacyPolicy(_ sender: NSMenuItem) -> Void {
  1150. KMTools.openPrivacyPolicyWebSite()
  1151. }
  1152. @IBAction func menuItemAction_TermsofService(_ sender: NSMenuItem) -> Void {
  1153. KMTools.openTermOfServiceWebSite()
  1154. }
  1155. }