AppDelegate+MenuAction.swift 42 KB

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