AppDelegate+MenuAction.swift 51 KB

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