AppDelegate+MenuAction.swift 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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 || mainVC.listView.document.password.count > 0 {
  262. return true
  263. } else {
  264. return false
  265. }
  266. } else if action == NSSelectorFromString("menuItemAction_unlockFunction:") {
  267. return mainVC.listView.document.isEncrypted
  268. } else if action == NSSelectorFromString("menuItemAction_searchPDF:") {
  269. } else if action == NSSelectorFromString("menuItemAction_performFindPanelAction:") {
  270. } else if action == NSSelectorFromString("menuItemAction_showInFinder:") {
  271. } else if action == NSSelectorFromString("menuItemAction_property:") {
  272. } else if action == NSSelectorFromString("menuItemAction_print:") {
  273. } else if action == NSSelectorFromString("menuItemAction_customPrint:") {
  274. }
  275. return true
  276. }
  277. return false
  278. }
  279. //MARK: -IBAction
  280. @IBAction func menuItemAction_NewFromFile(_ sender: NSMenuItem) -> Void {
  281. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  282. _windowC.newFromFile()
  283. }
  284. }
  285. @IBAction func menuItemAction_NewFromWeb(_ sender: NSMenuItem) -> Void {
  286. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  287. _windowC.newFromWebPage()
  288. }
  289. }
  290. @IBAction func menuItemAction_NewFromClipboard(_ sender: NSMenuItem) -> Void {
  291. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  292. _windowC.newFromClipboard()
  293. }
  294. }
  295. @IBAction func menuItemAction_NewFromScanner(_ sender: NSMenuItem) -> Void {
  296. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  297. _windowC.importFromScanner()
  298. }
  299. }
  300. @IBAction func menuItemAction_NewFromBlankPage(_ sender: NSMenuItem) -> Void {
  301. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  302. _windowC.newBlankPage()
  303. }
  304. }
  305. @IBAction func menuItemAction_NewFromWindow(_ sender: NSMenuItem) -> Void {
  306. if sender.tag == 0 {
  307. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  308. _windowC.screenShot_SelectArea(nil)
  309. }
  310. } else if sender.tag == 1 {
  311. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  312. _windowC.screenShot_Window(nil)
  313. }
  314. } else if sender.tag == 2 {
  315. if let _windowC = NSApp.mainWindow?.windowController as? KMBrowserWindowController {
  316. _windowC.screenShot_FullScreen(nil)
  317. }
  318. }
  319. }
  320. @IBAction func menuItemAction_MergePDFFiles(_ sender: NSMenuItem) -> Void {
  321. if let homeVC = self.homeViewController() {
  322. homeVC.fastTool_MergePDF()
  323. } else if let mainVC = self.mainViewController() {
  324. mainVC.showMergeWindow(mainVC.listView.document.password)
  325. }
  326. }
  327. @IBAction func menuItemAction_closeDocument(_ sender: Any) {
  328. if ((NSApp.mainWindow?.windowController is KMBrowserWindowController) == false) {
  329. guard let windowControler = NSApp.mainWindow?.windowController else {
  330. return
  331. }
  332. windowControler.window?.performClose(nil)
  333. return
  334. }
  335. let windowControler = NSApp.mainWindow?.windowController as? KMBrowserWindowController
  336. if let data = windowControler?.browser, data.tabCount() >= 2 { // 有两个以上的标签
  337. if data.activeTabIndex() == 0 { // 主页不允许关闭,暂时处理为无反应
  338. return
  339. }
  340. }
  341. if let browser = windowControler?.browser {
  342. if browser.tabCount() == 1 {
  343. windowControler?.window?.close()
  344. } else {
  345. if let _ = windowControler?.window?.attachedSheet {
  346. NSSound.beep()
  347. return
  348. }
  349. browser.closeTab()
  350. }
  351. } else {
  352. windowControler?.window?.close()
  353. }
  354. }
  355. @IBAction func menuItemAction_closeWindow(_ sender: Any) {
  356. NSApp.mainWindow?.close()
  357. }
  358. @IBAction func menuItemAction_closeAllWindows(_ sender: Any) {
  359. for window in NSApp.windows {
  360. window.close()
  361. }
  362. }
  363. @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  364. if let mainVC = self.mainViewController() {
  365. mainVC.saveAsFlattenedPDFAction()
  366. }
  367. }
  368. @IBAction func menuItemClick_Compress(_ sender: Any) {
  369. if let mainVC = self.mainViewController() {
  370. mainVC.showCompressController(mainVC.listView.document.documentURL)
  371. }
  372. }
  373. @IBAction func menuItemAction_ConvertTo(_ sender: NSMenuItem) {
  374. if let mainVC = self.mainViewController() {
  375. var convertType: KMPDFConvertType = .word
  376. if sender.tag == 0 {
  377. } else if sender.tag == 1 {
  378. convertType = .excel
  379. } else if sender.tag == 2 {
  380. convertType = .ppt
  381. } else if sender.tag == 30 {
  382. convertType = .jpeg
  383. } else if sender.tag == 31 {
  384. convertType = .jpg
  385. } else if sender.tag == 32 {
  386. convertType = .png
  387. } else if sender.tag == 33 {
  388. convertType = .gif
  389. } else if sender.tag == 34 {
  390. convertType = .tiff
  391. } else if sender.tag == 35 {
  392. convertType = .tga
  393. } else if sender.tag == 36 {
  394. convertType = .bmp
  395. } else if sender.tag == 37 {
  396. convertType = .jp2
  397. } else if sender.tag == 4 {
  398. convertType = .rtf
  399. } else if sender.tag == 5 {
  400. convertType = .csv
  401. } else if sender.tag == 6 {
  402. convertType = .html
  403. } else if sender.tag == 7 {
  404. convertType = .text
  405. } else if sender.tag == 8 {
  406. convertType = .json
  407. }
  408. mainVC.showConvertWindow(convertType)
  409. }
  410. }
  411. @IBAction func menuItemAction_addPassword(_ sender: Any) {
  412. if let mainVC = self.mainViewController() {
  413. mainVC.showSecureWindow()
  414. }
  415. }
  416. @IBAction func menuItemAction_removePassword(_ sender: Any) {
  417. if let mainVC = self.mainViewController() {
  418. mainVC.showRemoveSecureWindow()
  419. }
  420. }
  421. @IBAction func menuItemAction_unlockFunction(_ sender: Any) {
  422. if let mainVC = self.mainViewController() {
  423. mainVC.unlockPDFDocument()
  424. }
  425. }
  426. @IBAction func menuItemAction_searchPDF(_ sender: Any?) {
  427. }
  428. @IBAction func menuItemAction_performFindPanelAction(_ sender: NSMenuItem) {
  429. var forward = true
  430. var findString: String?
  431. }
  432. @IBAction func menuItemAction_showInFinder(_ sender: Any) {
  433. if let mainVC = self.mainViewController() {
  434. mainVC.showInFinder()
  435. }
  436. }
  437. @IBAction func menuItemAction_property(_ sender: Any) {
  438. if let mainVC = self.mainViewController() {
  439. KMInfoWindowController.shared.showWindow(sender)
  440. }
  441. }
  442. @IBAction func menuItemAction_print(_ sender: Any) {
  443. if let mainVC = self.mainViewController() {
  444. mainVC.showPrintWindow()
  445. }
  446. }
  447. @IBAction func menuItemAction_customPrint(_ sender: NSMenuItem) {
  448. if let mainVC = self.mainViewController() {
  449. if sender.tag == 0 {
  450. mainVC.showPosterPrintWindow()
  451. } else if sender.tag == 1 {
  452. mainVC.showMultiplePrintWindow()
  453. } else if sender.tag == 2 {
  454. mainVC.showBookletPrintWindow()
  455. }
  456. }
  457. }
  458. }
  459. // MARK: - Edit Menu
  460. extension AppDelegate {
  461. func isEditMenuActions(sel: Selector?) -> Bool {
  462. guard let selector = sel else {
  463. return false
  464. }
  465. let selectors = [ NSSelectorFromString("menuItemAction_PasteAndMatch:"),
  466. NSSelectorFromString("menuItemAction_ShowFont:"),
  467. NSSelectorFromString("menuItemAction_FontAction:"),
  468. NSSelectorFromString("menuItemAction_CustomFont:"),
  469. NSSelectorFromString("menuItemAction_FontAlign:")]
  470. if selectors.contains(selector) {
  471. return true
  472. }
  473. return false
  474. }
  475. func validateEditMenuItem(_ menuItem: NSMenuItem) -> Bool {
  476. let action = menuItem.action
  477. if let mainVC = self.mainViewController() {
  478. if action == NSSelectorFromString("menuItemAction_PasteAndMatch:") {
  479. } else if action == NSSelectorFromString("menuItemAction_ShowFont:") {
  480. } else if action == NSSelectorFromString("menuItemAction_FontAction:") {
  481. } else if action == NSSelectorFromString("menuItemAction_CustomFont:") {
  482. } else if action == NSSelectorFromString("menuItemAction_FontAlign:") {
  483. }
  484. return true
  485. }
  486. return false
  487. }
  488. //MARK: -IBAction
  489. @IBAction func menuItemAction_PasteAndMatch(_ sender: NSMenuItem) {
  490. }
  491. @IBAction func menuItemAction_ShowFont(_ sender: NSMenuItem) {
  492. NSFontManager.shared.orderFrontFontPanel(nil)
  493. }
  494. @IBAction func menuItemAction_FontAction(_ sender: Any) {
  495. }
  496. @IBAction func menuItemAction_CustomFont(_ sender: NSMenuItem) {
  497. }
  498. @IBAction func menuItemAction_FontAlign(_ sender: NSMenuItem) {
  499. }
  500. }
  501. // MARK: - View Menu
  502. extension AppDelegate {
  503. func isViewMenuActions(sel: Selector?) -> Bool {
  504. guard let selector = sel else {
  505. return false
  506. }
  507. let selectors = [NSSelectorFromString("menuItemAction_ChangeDisplayMode:"),
  508. NSSelectorFromString("menuItemAction_ReadMode:"),
  509. NSSelectorFromString("menuItemAction_FullScreen:"),
  510. NSSelectorFromString("menuItemAction_Presentation:"),
  511. NSSelectorFromString("menuItemAction_SplitView:"),
  512. NSSelectorFromString("menuItemAction_BOTAMode:"),
  513. NSSelectorFromString("menuItemAction_Outline:"),
  514. NSSelectorFromString("menuItemAction_Notes:"),
  515. NSSelectorFromString("menuItemAction_Annotate:"),
  516. NSSelectorFromString("menuItemAction_Themes:"),
  517. NSSelectorFromString("menuItemAction_Zoom:"),
  518. NSSelectorFromString("menuItemAction_Rotate:"),
  519. NSSelectorFromString("menuItemAction_HighlightFormsField:"),
  520. NSSelectorFromString("menuItemAction_HighlightLinks:"),
  521. NSSelectorFromString("menuItemAction_ResetForm:"),
  522. NSSelectorFromString("menuItemAction_AutoScroll:")]
  523. if selectors.contains(selector) {
  524. return true
  525. }
  526. return false
  527. }
  528. func validateViewMenuItem(_ menuItem: NSMenuItem) -> Bool {
  529. let action = menuItem.action
  530. if let mainVC = self.mainViewController() {
  531. if action == NSSelectorFromString("menuItemAction_ChangeDisplayMode:") {
  532. menuItem.state = .off
  533. if menuItem.tag == 1 && mainVC.getPDFViewPageLayoutType() == .singlePage {
  534. menuItem.state = .on
  535. } else if menuItem.tag == 2 && mainVC.getPDFViewPageLayoutType() == .singlePageContinue {
  536. menuItem.state = .on
  537. } else if menuItem.tag == 3 && mainVC.getPDFViewPageLayoutType() == .twoPage {
  538. menuItem.state = .on
  539. } else if menuItem.tag == 4 && mainVC.getPDFViewPageLayoutType() == .twoPageContinue {
  540. menuItem.state = .on
  541. } else if menuItem.tag == 5 && mainVC.getPDFViewPageLayoutType() == .bookMode {
  542. menuItem.state = .on
  543. }
  544. } else if action == NSSelectorFromString("menuItemAction_ReadMode:") {
  545. } else if action == NSSelectorFromString("menuItemAction_FullScreen:") {
  546. } else if action == NSSelectorFromString("menuItemAction_Presentation:") {
  547. } else if action == NSSelectorFromString("menuItemAction_SplitView:") {
  548. } else if action == NSSelectorFromString("menuItemAction_BOTAMode:") {
  549. menuItem.state = .off
  550. if menuItem.tag == 0 && mainVC.viewManager.pdfSideBarType == .thumbnail {
  551. menuItem.state = .on
  552. } else if menuItem.tag == 1 && mainVC.viewManager.pdfSideBarType == .outline {
  553. menuItem.state = .on
  554. } else if menuItem.tag == 2 && mainVC.viewManager.pdfSideBarType == .bookmark {
  555. menuItem.state = .on
  556. } else if menuItem.tag == 3 && mainVC.viewManager.pdfSideBarType == .annotation {
  557. menuItem.state = .on
  558. }
  559. } else if action == NSSelectorFromString("menuItemAction_Themes:") {
  560. menuItem.state = .off
  561. if menuItem.tag == 0 && mainVC.listView.displayMode == .normal {
  562. menuItem.state = .on
  563. } else if menuItem.tag == 1 && mainVC.listView.displayMode == .soft {
  564. menuItem.state = .on
  565. } else if menuItem.tag == 2 && mainVC.listView.displayMode == .green {
  566. menuItem.state = .on
  567. } else if menuItem.tag == 3 && mainVC.listView.displayMode == .night {
  568. menuItem.state = .on
  569. }
  570. } else if action == NSSelectorFromString("menuItemAction_Zoom:") {
  571. } else if action == NSSelectorFromString("menuItemAction_Rotate:") {
  572. } else if action == NSSelectorFromString("menuItemAction_HighlightFormsField:") {
  573. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  574. menuItem.state = enabled ? .on : .off
  575. } else if action == NSSelectorFromString("menuItemAction_HighlightLinks:") {
  576. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  577. menuItem.state = enabled ? .on : .off
  578. } else if action == NSSelectorFromString("menuItemAction_ResetForm:") {
  579. } else if action == NSSelectorFromString("menuItemAction_AutoScroll:") {
  580. menuItem.state = mainVC.isAutoFlowOn() ? .on : .off
  581. }
  582. return true
  583. }
  584. return false
  585. }
  586. //MARK: -IBAction
  587. @IBAction func menuItemAction_ChangeDisplayMode(_ sender: NSMenuItem) {
  588. if let mainVC = self.mainViewController() {
  589. if sender.tag == 1 {
  590. mainVC.updatePDFViewDisplayMode(viewMode: .singlePage)
  591. } else if sender.tag == 2 {
  592. mainVC.updatePDFViewDisplayMode(viewMode: .singlePageContinuous)
  593. } else if sender.tag == 3 {
  594. mainVC.updatePDFViewDisplayMode(viewMode: .twoUp)
  595. } else if sender.tag == 4 {
  596. mainVC.updatePDFViewDisplayMode(viewMode: .twoUpContinuous)
  597. } else if sender.tag == 5 {
  598. mainVC.updatePDFViewDisplayMode(isbookMode: true)
  599. }
  600. }
  601. }
  602. @IBAction func menuItemAction_ReadMode(_ sender: NSMenuItem) {
  603. if let mainVC = self.mainViewController() {
  604. mainVC.viewManager.isPDFReadMode = !mainVC.viewManager.isPDFReadMode
  605. if mainVC.viewManager.isPDFReadMode {
  606. mainVC.openPDFReadMode()
  607. } else {
  608. mainVC.exitPDFReadMode()
  609. }
  610. }
  611. }
  612. @IBAction func menuItemAction_FullScreen(_ sender: NSMenuItem) {
  613. if let mainVC = self.mainViewController() {
  614. mainVC.view.window?.toggleFullScreen(nil)
  615. }
  616. }
  617. @IBAction func menuItemAction_Presentation(_ sender: NSMenuItem) {
  618. if let mainVC = self.mainViewController() {
  619. mainVC.togglePresentation(nil)
  620. }
  621. }
  622. @IBAction func menuItemAction_SplitView(_ sender: NSMenuItem) {
  623. if let mainVC = self.mainViewController() {
  624. if sender.tag == 0 {
  625. mainVC.listView.viewSplitMode = .vertical
  626. } else if sender.tag == 1 {
  627. mainVC.listView.viewSplitMode = .horizontal
  628. } else if sender.tag == 2 {
  629. mainVC.listView.viewSplitMode = .disable
  630. }
  631. mainVC.reloadPDFSplitInfo()
  632. }
  633. }
  634. @IBAction func menuItemAction_BOTAMode(_ sender: NSMenuItem) {
  635. if let mainVC = self.mainViewController() {
  636. if sender.tag == 0 {
  637. if mainVC.viewManager.pdfSideBarType == .thumbnail {
  638. mainVC.viewManager.pdfSideBarType = .none
  639. } else {
  640. mainVC.viewManager.pdfSideBarType = .thumbnail
  641. }
  642. } else if sender.tag == 1 {
  643. if mainVC.viewManager.pdfSideBarType == .outline {
  644. mainVC.viewManager.pdfSideBarType = .none
  645. } else {
  646. mainVC.viewManager.pdfSideBarType = .outline
  647. }
  648. } else if sender.tag == 2 {
  649. if mainVC.viewManager.pdfSideBarType == .bookmark {
  650. mainVC.viewManager.pdfSideBarType = .none
  651. } else {
  652. mainVC.viewManager.pdfSideBarType = .bookmark
  653. }
  654. } else if sender.tag == 3 {
  655. if mainVC.viewManager.pdfSideBarType == .annotation {
  656. mainVC.viewManager.pdfSideBarType = .none
  657. } else {
  658. mainVC.viewManager.pdfSideBarType = .annotation
  659. }
  660. }
  661. if mainVC.viewManager.pdfSideBarType == .none {
  662. mainVC.toggleCloseLeftSide()
  663. } else {
  664. mainVC.toggleOpenLeftSide(pdfSideBarType: mainVC.viewManager.pdfSideBarType)
  665. }
  666. mainVC.reloadSideBar()
  667. }
  668. }
  669. @IBAction func menuItemAction_Themes(_ sender: NSMenuItem) {
  670. if let mainVC = self.mainViewController() {
  671. var model: KMPDFViewMode = .normal
  672. var color = NSColor.clear
  673. if sender.tag == 0 {
  674. model = .normal
  675. } else if sender.tag == 1 {
  676. model = .soft
  677. } else if sender.tag == 2 {
  678. model = .green
  679. } else if sender.tag == 3 {
  680. model = .night
  681. } else {
  682. model = .other
  683. }
  684. mainVC.listView.setPageBackgroundColorWith(color, viewMode: model)
  685. mainVC.updatePDFDisplaySettingView()
  686. }
  687. }
  688. @IBAction func menuItemAction_Zoom(_ sender: NSMenuItem) {
  689. if let mainVC = self.mainViewController() {
  690. var type: KMPDFZoomType = .width
  691. if sender.tag == 0 {
  692. type = .width
  693. } else if sender.tag == 1 {
  694. type = .fit
  695. } else if sender.tag == 2 {
  696. type = .actualSize
  697. } else if sender.tag == 3 {
  698. type = .zoom_In
  699. } else if sender.tag == 4 {
  700. type = .zoom_Out
  701. }
  702. mainVC.selectZoom(type)
  703. }
  704. }
  705. @IBAction func menuItemAction_Rotate(_ sender: NSMenuItem) {
  706. if let mainVC = self.mainViewController() {
  707. if sender.tag == 0 {
  708. mainVC.rotateLeft(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  709. } else if sender.tag == 1 {
  710. mainVC.rotateRight(page: mainVC.listView.currentPage(), listView: mainVC.listView)
  711. }
  712. }
  713. }
  714. @IBAction func menuItemAction_HighlightFormsField(_ sender: NSMenuItem) {
  715. if let mainVC = self.mainViewController() {
  716. let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
  717. CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled)
  718. mainVC.listView.setNeedsDisplayForVisiblePages()
  719. }
  720. }
  721. @IBAction func menuItemAction_HighlightLinks(_ sender: NSMenuItem) {
  722. if let mainVC = self.mainViewController() {
  723. let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
  724. CPDFAnnotation.updateLinkFieldHighlight(mainVC.listView, linkFieldHighlight: !enabled)
  725. }
  726. }
  727. @IBAction func menuItemAction_ResetForm(_ sender: NSMenuItem) {
  728. if let mainVC = self.mainViewController() {
  729. mainVC.listView.resetFormAnnotation()
  730. }
  731. }
  732. @IBAction func menuItemAction_AutoScroll(_ sender: NSMenuItem) {
  733. if let mainVC = self.mainViewController() {
  734. mainVC.toggleAutoFlow(nil)
  735. }
  736. }
  737. }
  738. // MARK: - Go Menu
  739. extension AppDelegate {
  740. func isGoMenuActions(sel: Selector?) -> Bool {
  741. guard let selector = sel else {
  742. return false
  743. }
  744. let selectors = [NSSelectorFromString("menuItemAction_Next:"),
  745. NSSelectorFromString("menuItemAction_Previous:"),
  746. NSSelectorFromString("menuItemAction_First:"),
  747. NSSelectorFromString("menuItemAction_Last:"),
  748. NSSelectorFromString("menuItemAction_GotoPage:"),
  749. NSSelectorFromString("menuItemAction_Back:"),
  750. NSSelectorFromString("menuItemAction_Forward:")]
  751. if selectors.contains(selector) {
  752. return true
  753. }
  754. return false
  755. }
  756. func validateGoMenuItem(_ menuItem: NSMenuItem) -> Bool {
  757. let action = menuItem.action
  758. if let mainVC = self.mainViewController() {
  759. if action == NSSelectorFromString("menuItemAction_Next:") {
  760. if mainVC.listView.isEditing() && mainVC.listView.isEditable() {
  761. return false
  762. }
  763. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToNextPage())
  764. } else if action == NSSelectorFromString("menuItemAction_Previous:") {
  765. if mainVC.listView.isEditing() && mainVC.listView.isEditable() {
  766. return false
  767. }
  768. return (mainVC.pdfViewCanHorizontalScroll() == false && mainVC.listView.canGoToPreviousPage())
  769. } else if action == NSSelectorFromString("menuItemAction_First:") {
  770. return mainVC.listView.canGoToFirstPage()
  771. } else if action == NSSelectorFromString("menuItemAction_Last:") {
  772. return mainVC.listView.canGoToLastPage()
  773. } else if action == NSSelectorFromString("menuItemAction_GotoPage:") {
  774. return true
  775. } else if action == NSSelectorFromString("menuItemAction_Back:") {
  776. return mainVC.listView.km_canGoBack()
  777. } else if action == NSSelectorFromString("menuItemAction_Forward:") {
  778. return mainVC.listView.km_canGoForward()
  779. }
  780. }
  781. return false
  782. }
  783. //MARK: -IBAction
  784. @IBAction func menuItemAction_Next(_ sender: NSMenuItem) {
  785. if let mainVC = self.mainViewController() {
  786. if (mainVC.listView.canGoToNextPage()) {
  787. mainVC.listView.goToNextPage(nil)
  788. }
  789. }
  790. }
  791. @IBAction func menuItemAction_Previous(_ sender: NSMenuItem) {
  792. if let mainVC = self.mainViewController() {
  793. if (mainVC.listView.canGoToPreviousPage()) {
  794. mainVC.listView.goToPreviousPage(nil)
  795. }
  796. }
  797. }
  798. @IBAction func menuItemAction_First(_ sender: NSMenuItem) {
  799. if let mainVC = self.mainViewController() {
  800. mainVC.listView.goToFirstPage(nil)
  801. }
  802. }
  803. @IBAction func menuItemAction_Last(_ sender: NSMenuItem) {
  804. if let mainVC = self.mainViewController() {
  805. mainVC.listView.goToLastPage(nil)
  806. }
  807. }
  808. @IBAction func menuItemAction_GotoPage(_ sender: NSMenuItem) {
  809. if let mainVC = self.mainViewController() {
  810. mainVC.gotoPage(nil)
  811. }
  812. }
  813. @IBAction func menuItemAction_Back(_ sender: NSMenuItem) {
  814. if let mainVC = self.mainViewController() {
  815. if (mainVC.listView.km_canGoBack()) {
  816. mainVC.listView.km_goBack(nil)
  817. }
  818. }
  819. }
  820. @IBAction func menuItemAction_Forward(_ sender: NSMenuItem) {
  821. if let mainVC = self.mainViewController() {
  822. if (mainVC.listView.km_canGoForward()) {
  823. mainVC.listView.km_goForward(nil)
  824. }
  825. }
  826. }
  827. }
  828. // MARK: - Window Menu
  829. extension AppDelegate {
  830. func isWindowMenuActions(sel: Selector?) -> Bool {
  831. guard let selector = sel else {
  832. return false
  833. }
  834. var selectors = [NSSelectorFromString("11:"),
  835. NSSelectorFromString("11:")]
  836. if selectors.contains(selector) {
  837. return true
  838. }
  839. return false
  840. }
  841. func validateWindowMenuItem(_ menuItem: NSMenuItem) -> Bool {
  842. return true
  843. }
  844. //MARK: -IBAction
  845. }
  846. // MARK: - help Menu
  847. extension AppDelegate {
  848. func isHelpMenuActions(sel: Selector?) -> Bool {
  849. guard let selector = sel else {
  850. return false
  851. }
  852. var selectors = [NSSelectorFromString("menuItemAction_APPWebSite:"),
  853. NSSelectorFromString("menuItemAction_quickStudy:"),
  854. NSSelectorFromString("menuItemAction_OnlineHelp:"),
  855. NSSelectorFromString("menuItemAction_Feedback:"),
  856. NSSelectorFromString("menuItemAction_FiveStar:"),
  857. NSSelectorFromString("menuItemAction_SubscribeUs:"),
  858. NSSelectorFromString("menuItemAction_CheckForUpdate:"),
  859. NSSelectorFromString("menuItemAction_VPP:"),
  860. NSSelectorFromString("menuItemAction_FreeTemplate:"),
  861. NSSelectorFromString("menuItemAction_MoreProducts:"),
  862. NSSelectorFromString("menuItemAction_PowerBy:"),
  863. NSSelectorFromString("menuItemAction_privacyPolicy:"),
  864. NSSelectorFromString("menuItemAction_TermsofService:")]
  865. if selectors.contains(selector) {
  866. return true
  867. }
  868. return false
  869. }
  870. func validateHelpMenuItem(_ menuItem: NSMenuItem) -> Bool {
  871. return true
  872. }
  873. //MARK: -IBAction
  874. @IBAction func menuItemAction_APPWebSite(_ sender: NSMenuItem) -> Void {
  875. KMTools.openURL(urlString: APPMain_Link)
  876. }
  877. @IBAction func menuItemAction_quickStudy(_ sender: NSMenuItem) -> Void {
  878. KMTools.openQuickStartStudy()
  879. }
  880. @IBAction func menuItemAction_OnlineHelp(_ sender: NSMenuItem) -> Void {
  881. KMTools.openFAQWebsite()
  882. }
  883. @IBAction func menuItemAction_Feedback(_ sender: NSMenuItem) -> Void {
  884. KMTools.feekback()
  885. }
  886. @IBAction func menuItemAction_FiveStar(_ sender: NSMenuItem) -> Void {
  887. KMTools.rateUs()
  888. }
  889. @IBAction func menuItemAction_SubscribeUs(_ sender: NSMenuItem) -> Void {
  890. KMEmailSubWindowController().showWindow(nil)
  891. }
  892. @IBAction func menuItemAction_CheckForUpdate(_ sender: NSMenuItem) -> Void {
  893. #if VERSION_DMG
  894. SUUpdater.shared().checkForUpdates(sender)
  895. #endif
  896. }
  897. @IBAction func menuItemAction_VPP(_ sender: NSMenuItem) -> Void {
  898. KMTools.openVPPWebSite()
  899. }
  900. @IBAction func menuItemAction_FreeTemplate(_ sender: NSMenuItem) -> Void {
  901. KMTools.openFreePDFTemplatesWebsite()
  902. }
  903. @IBAction func menuItemAction_MoreProducts(_ sender: NSMenuItem) -> Void {
  904. KMTools.openMoreProductWebsite()
  905. }
  906. @IBAction func menuItemAction_PowerBy(_ sender: NSMenuItem) -> Void {
  907. KMTools.openComPDFKitPowerWebsite()
  908. }
  909. @IBAction func menuItemAction_privacyPolicy(_ sender: NSMenuItem) -> Void {
  910. KMTools.openPrivacyPolicyWebSite()
  911. }
  912. @IBAction func menuItemAction_TermsofService(_ sender: NSMenuItem) -> Void {
  913. KMTools.openTermOfServiceWebSite()
  914. }
  915. }