AppDelegate+MenuAction.swift 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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. mainVC.listView.viewSplitMode = .vertical
  737. } else if sender.tag == 1 {
  738. mainVC.listView.viewSplitMode = .horizontal
  739. } else if sender.tag == 2 {
  740. mainVC.listView.viewSplitMode = .disable
  741. }
  742. mainVC.reloadPDFSplitInfo()
  743. }
  744. }
  745. @IBAction func menuItemAction_BOTAMode(_ sender: NSMenuItem) {
  746. if let mainVC = self.mainViewController() {
  747. if sender.tag == 0 {
  748. if mainVC.viewManager.pdfSideBarType == .thumbnail {
  749. mainVC.viewManager.pdfSideBarType = .none
  750. } else {
  751. mainVC.viewManager.pdfSideBarType = .thumbnail
  752. }
  753. } else if sender.tag == 1 {
  754. if mainVC.viewManager.pdfSideBarType == .outline {
  755. mainVC.viewManager.pdfSideBarType = .none
  756. } else {
  757. mainVC.viewManager.pdfSideBarType = .outline
  758. }
  759. } else if sender.tag == 2 {
  760. if mainVC.viewManager.pdfSideBarType == .bookmark {
  761. mainVC.viewManager.pdfSideBarType = .none
  762. } else {
  763. mainVC.viewManager.pdfSideBarType = .bookmark
  764. }
  765. } else if sender.tag == 3 {
  766. if mainVC.viewManager.pdfSideBarType == .annotation {
  767. mainVC.viewManager.pdfSideBarType = .none
  768. } else {
  769. mainVC.viewManager.pdfSideBarType = .annotation
  770. }
  771. } else if sender.tag == 4 {
  772. if mainVC.viewManager.pdfSideBarType == .search {
  773. mainVC.viewManager.pdfSideBarType = .none
  774. } else {
  775. mainVC.viewManager.pdfSideBarType = .search
  776. }
  777. }
  778. if mainVC.viewManager.pdfSideBarType == .none {
  779. mainVC.toggleCloseLeftSide()
  780. } else {
  781. mainVC.toggleOpenLeftSide(pdfSideBarType: mainVC.viewManager.pdfSideBarType)
  782. }
  783. mainVC.reloadSideBar()
  784. }
  785. }
  786. @IBAction func menuItemAction_Themes(_ sender: NSMenuItem) {
  787. if let mainVC = self.mainViewController() {
  788. var model: KMPDFViewMode = .normal
  789. var color = NSColor.clear
  790. if sender.tag == 0 {
  791. model = .normal
  792. } else if sender.tag == 1 {
  793. model = .soft
  794. } else if sender.tag == 2 {
  795. model = .green
  796. } else if sender.tag == 3 {
  797. model = .night
  798. } else {
  799. model = .other
  800. }
  801. if KMMemberInfo.shared.isLogin == false, model != .normal {
  802. KMLoginWindowsController.shared.showWindow(nil)
  803. return
  804. }
  805. mainVC.listView.setPageBackgroundColorWith(color, viewMode: model)
  806. mainVC.updatePDFDisplaySettingView()
  807. }
  808. }
  809. @IBAction func menuItemAction_Zoom(_ sender: NSMenuItem) {
  810. if let mainVC = self.mainViewController() {
  811. var type: KMPDFZoomType = .width
  812. if sender.tag == 0 {
  813. type = .width
  814. } else if sender.tag == 1 {
  815. type = .fit
  816. } else if sender.tag == 2 {
  817. type = .actualSize
  818. } else if sender.tag == 3 {
  819. type = .zoom_In
  820. } else if sender.tag == 4 {
  821. type = .zoom_Out
  822. }
  823. mainVC.selectZoom(type)
  824. }
  825. }
  826. @IBAction func menuItemAction_Rotate(_ sender: NSMenuItem) {
  827. if let mainVC = self.mainViewController() {
  828. if sender.tag == 0 {
  829. mainVC.rotateLeft(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  830. } else if sender.tag == 1 {
  831. mainVC.rotateRight(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  832. }
  833. }
  834. }
  835. @IBAction func menuItemAction_HighlightFormsField(_ sender: NSMenuItem) {
  836. if let mainVC = self.mainViewController() {
  837. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  838. CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled)
  839. mainVC.listView.setNeedsDisplayForVisiblePages()
  840. mainVC.alertTipViewController.reloadFormAlertUI()
  841. }
  842. }
  843. @IBAction func menuItemAction_HighlightLinks(_ sender: NSMenuItem) {
  844. if let mainVC = self.mainViewController() {
  845. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  846. CPDFAnnotation.updateLinkFieldHighlight(mainVC.listView, linkFieldHighlight: !enabled)
  847. }
  848. }
  849. @IBAction func menuItemAction_ResetForm(_ sender: NSMenuItem) {
  850. if let mainVC = self.mainViewController() {
  851. mainVC.listView.resetFormAnnotation()
  852. }
  853. }
  854. @IBAction func menuItemAction_AutoScroll(_ sender: NSMenuItem) {
  855. if let mainVC = self.mainViewController() {
  856. mainVC.toggleAutoFlow(nil)
  857. }
  858. }
  859. }
  860. // MARK: - Go Menu
  861. extension AppDelegate {
  862. func isGoMenuActions(sel: Selector?) -> Bool {
  863. guard let selector = sel else {
  864. return false
  865. }
  866. let selectors = [NSSelectorFromString("menuItemAction_Next:"),
  867. NSSelectorFromString("menuItemAction_Previous:"),
  868. NSSelectorFromString("menuItemAction_First:"),
  869. NSSelectorFromString("menuItemAction_Last:"),
  870. NSSelectorFromString("menuItemAction_GotoPage:"),
  871. NSSelectorFromString("menuItemAction_Back:"),
  872. NSSelectorFromString("menuItemAction_Forward:")]
  873. if selectors.contains(selector) {
  874. return true
  875. }
  876. return false
  877. }
  878. func validateGoMenuItem(_ menuItem: NSMenuItem) -> Bool {
  879. let action = menuItem.action
  880. if let mainVC = self.mainViewController() {
  881. if action == NSSelectorFromString("menuItemAction_Next:") {
  882. if mainVC.listView.isEditing() {
  883. let editingAreas = mainVC.listView.km_EditingAreas()
  884. if(editingAreas.count > 0) {
  885. var isEditSelect = false
  886. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  887. isEditSelect = true
  888. } else {
  889. let editState = mainVC.listView.editStatus()
  890. if (editState == .editSelectText) {// 选择文本
  891. isEditSelect = true
  892. }
  893. }
  894. if isEditSelect {
  895. return true
  896. }
  897. }
  898. }
  899. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToNextPage())
  900. } else if action == NSSelectorFromString("menuItemAction_Previous:") {
  901. if mainVC.listView.isEditing(){
  902. let editingAreas = mainVC.listView.km_EditingAreas()
  903. if(editingAreas.count > 0) {
  904. var isEditSelect = false
  905. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  906. isEditSelect = true
  907. } else {
  908. let editState = mainVC.listView.editStatus()
  909. if (editState == .editSelectText) {// 选择文本
  910. isEditSelect = true
  911. }
  912. }
  913. if isEditSelect {
  914. return true
  915. }
  916. }
  917. }
  918. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToPreviousPage())
  919. } else if action == NSSelectorFromString("menuItemAction_First:") {
  920. if(mainVC.listView.isEditing()) {
  921. let editingAreas = mainVC.listView.km_EditingAreas()
  922. if(editingAreas.count > 0) {
  923. var isEditSelect = false
  924. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  925. isEditSelect = true
  926. } else {
  927. let editState = mainVC.listView.editStatus()
  928. if (editState == .editSelectText) {// 选择文本
  929. isEditSelect = true
  930. }
  931. }
  932. if isEditSelect {
  933. return true
  934. }
  935. }
  936. }
  937. return mainVC.listView.canGoToFirstPage()
  938. } else if action == NSSelectorFromString("menuItemAction_Last:") {
  939. if(mainVC.listView.isEditing()) {
  940. let editingAreas = mainVC.listView.km_EditingAreas()
  941. if(editingAreas.count > 0) {
  942. var isEditSelect = false
  943. if !mainVC.listView.isSelecteditAreaNotEdit() { //光标输入状态
  944. isEditSelect = true
  945. } else {
  946. let editState = mainVC.listView.editStatus()
  947. if (editState == .editSelectText) {// 选择文本
  948. isEditSelect = true
  949. }
  950. }
  951. if isEditSelect {
  952. return true
  953. }
  954. }
  955. }
  956. return mainVC.listView.canGoToLastPage()
  957. } else if action == NSSelectorFromString("menuItemAction_GotoPage:") {
  958. return true
  959. } else if action == NSSelectorFromString("menuItemAction_Back:") {
  960. return mainVC.listView.km_canGoBack()
  961. } else if action == NSSelectorFromString("menuItemAction_Forward:") {
  962. return mainVC.listView.km_canGoForward()
  963. }
  964. }
  965. return false
  966. }
  967. //MARK: -IBAction
  968. @IBAction func menuItemAction_Next(_ sender: NSMenuItem) {
  969. if let mainVC = self.mainViewController() {
  970. if(mainVC.listView.isEditing()) {
  971. mainVC.keyDownEditCmdRight()
  972. } else {
  973. if (mainVC.listView.canGoToNextPage()) {
  974. mainVC.listView.goToNextPage(nil)
  975. }
  976. }
  977. }
  978. }
  979. @IBAction func menuItemAction_Previous(_ sender: NSMenuItem) {
  980. if let mainVC = self.mainViewController() {
  981. if(mainVC.listView.isEditing()) {
  982. mainVC.keyDownEditCmdLeft()
  983. } else {
  984. if (mainVC.listView.canGoToPreviousPage()) {
  985. mainVC.listView.goToPreviousPage(nil)
  986. }
  987. }
  988. }
  989. }
  990. @IBAction func menuItemAction_First(_ sender: NSMenuItem) {
  991. if let mainVC = self.mainViewController() {
  992. if(mainVC.listView.isEditing()) {
  993. mainVC.keyDownEditCmdUp()
  994. } else {
  995. mainVC.listView.goToFirstPage(nil)
  996. }
  997. }
  998. }
  999. @IBAction func menuItemAction_Last(_ sender: NSMenuItem) {
  1000. if let mainVC = self.mainViewController() {
  1001. if(mainVC.listView.isEditing()) {
  1002. mainVC.keyDownEditCmdDown()
  1003. } else {
  1004. mainVC.listView.goToLastPage(nil)
  1005. }
  1006. }
  1007. }
  1008. @IBAction func menuItemAction_GotoPage(_ sender: NSMenuItem) {
  1009. if let mainVC = self.mainViewController() {
  1010. mainVC.gotoPage(nil)
  1011. }
  1012. }
  1013. @IBAction func menuItemAction_Back(_ sender: NSMenuItem) {
  1014. if let mainVC = self.mainViewController() {
  1015. if (mainVC.listView.km_canGoBack()) {
  1016. mainVC.listView.km_goBack(nil)
  1017. }
  1018. }
  1019. }
  1020. @IBAction func menuItemAction_Forward(_ sender: NSMenuItem) {
  1021. if let mainVC = self.mainViewController() {
  1022. if (mainVC.listView.km_canGoForward()) {
  1023. mainVC.listView.km_goForward(nil)
  1024. }
  1025. }
  1026. }
  1027. }
  1028. // MARK: - Window Menu
  1029. extension AppDelegate {
  1030. func isWindowMenuActions(sel: Selector?) -> Bool {
  1031. guard let selector = sel else {
  1032. return false
  1033. }
  1034. var selectors = [NSSelectorFromString("menuItemAction_showForwardTagPage:"),
  1035. NSSelectorFromString("menuItemAction_showNextTagPage:"),
  1036. NSSelectorFromString("menuItemAction_mergeAllWindow:")]
  1037. if selectors.contains(selector) {
  1038. return true
  1039. }
  1040. return false
  1041. }
  1042. func validateWindowMenuItem(_ menuItem: NSMenuItem) -> Bool {
  1043. let action = menuItem.action
  1044. if let browser = self.currentKMBrowser() {
  1045. if action == NSSelectorFromString("menuItemAction_showForwardTagPage:") {
  1046. menuItem.keyEquivalent = "\t"
  1047. menuItem.keyEquivalentModifierMask = [.shift, .control]
  1048. return browser.canSelectPreviousTab()
  1049. } else if action == NSSelectorFromString("menuItemAction_showNextTagPage:") {
  1050. return browser.canSelectNextTab()
  1051. }
  1052. }
  1053. if let browserWC = self.currentBrowserWindowController() {
  1054. if action == NSSelectorFromString("menuItemAction_mergeAllWindow:") {
  1055. return browserWC.canMergeAllWindow()
  1056. }
  1057. }
  1058. return true
  1059. }
  1060. //MARK: -IBAction
  1061. @IBAction func menuItemAction_showForwardTagPage(_ sender: NSMenuItem) -> Void {
  1062. if let browser = self.currentKMBrowser() {
  1063. browser.selectPreviousTab()
  1064. }
  1065. }
  1066. @IBAction func menuItemAction_showNextTagPage(_ sender: NSMenuItem) -> Void {
  1067. if let browser = self.currentKMBrowser() {
  1068. browser.selectNextTab()
  1069. }
  1070. }
  1071. @IBAction func menuItemAction_mergeAllWindow(_ sender: NSMenuItem) -> Void {
  1072. if let browserWC = self.currentBrowserWindowController() {
  1073. browserWC.mergeAllWindow(sender)
  1074. }
  1075. }
  1076. }
  1077. // MARK: - help Menu
  1078. extension AppDelegate {
  1079. func isHelpMenuActions(sel: Selector?) -> Bool {
  1080. guard let selector = sel else {
  1081. return false
  1082. }
  1083. var selectors = [NSSelectorFromString("menuItemAction_APPWebSite:"),
  1084. NSSelectorFromString("menuItemAction_quickStudy:"),
  1085. NSSelectorFromString("menuItemAction_OnlineHelp:"),
  1086. NSSelectorFromString("menuItemAction_Feedback:"),
  1087. NSSelectorFromString("menuItemAction_FiveStar:"),
  1088. NSSelectorFromString("menuItemAction_SubscribeUs:"),
  1089. NSSelectorFromString("menuItemAction_CheckForUpdate:"),
  1090. NSSelectorFromString("menuItemAction_VPP:"),
  1091. NSSelectorFromString("menuItemAction_FreeTemplate:"),
  1092. NSSelectorFromString("menuItemAction_MoreProducts:"),
  1093. NSSelectorFromString("menuItemAction_PowerBy:"),
  1094. NSSelectorFromString("menuItemAction_privacyPolicy:"),
  1095. NSSelectorFromString("menuItemAction_TermsofService:")]
  1096. if selectors.contains(selector) {
  1097. return true
  1098. }
  1099. return false
  1100. }
  1101. func validateHelpMenuItem(_ menuItem: NSMenuItem) -> Bool {
  1102. return true
  1103. }
  1104. //MARK: -IBAction
  1105. @IBAction func menuItemAction_APPWebSite(_ sender: NSMenuItem) -> Void {
  1106. KMTools.openURL(urlString: APPMain_Link)
  1107. }
  1108. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  1109. KMTools.openQuickStartStudy()
  1110. }
  1111. @IBAction func menuItemAction_OnlineHelp(_ sender: NSMenuItem) -> Void {
  1112. KMTools.openFAQWebsite()
  1113. }
  1114. @IBAction func menuItemAction_Feedback(_ sender: NSMenuItem) -> Void {
  1115. let help = KMUserFeekbackHanddler()
  1116. help.showFeekbackWindow(with: KMLocalizedString("Feedback", comment: ""))
  1117. }
  1118. @IBAction func menuItemAction_FiveStar(_ sender: NSMenuItem) -> Void {
  1119. KMTools.rateUs()
  1120. }
  1121. @IBAction func menuItemAction_SubscribeUs(_ sender: NSMenuItem) -> Void {
  1122. KMEmailSubWindowController().showWindow(nil)
  1123. }
  1124. @IBAction func menuItemAction_CheckForUpdate(_ sender: NSMenuItem) -> Void {
  1125. #if VERSION_DMG
  1126. SUUpdater.shared().checkForUpdates(sender)
  1127. #endif
  1128. }
  1129. @IBAction func menuItemAction_VPP(_ sender: NSMenuItem) -> Void {
  1130. KMTools.openVPPWebSite()
  1131. }
  1132. @IBAction func menuItemAction_FreeTemplate(_ sender: NSMenuItem) -> Void {
  1133. KMTools.openFreePDFTemplatesWebsite()
  1134. }
  1135. @IBAction func menuItemAction_MoreProducts(_ sender: NSMenuItem) -> Void {
  1136. KMTools.openMoreProductWebsite()
  1137. }
  1138. @IBAction func menuItemAction_PowerBy(_ sender: NSMenuItem) -> Void {
  1139. KMTools.openComPDFKitPowerWebsite()
  1140. }
  1141. @IBAction func menuItemAction_privacyPolicy(_ sender: NSMenuItem) -> Void {
  1142. KMTools.openPrivacyPolicyWebSite()
  1143. }
  1144. @IBAction func menuItemAction_TermsofService(_ sender: NSMenuItem) -> Void {
  1145. KMTools.openTermOfServiceWebSite()
  1146. }
  1147. }