KMMainViewController+MenuAction.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. //
  2. // KMMainViewController+MenuAction.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/2/19.
  6. //
  7. import Foundation
  8. // MARK: File Menu
  9. extension KMMainViewController {
  10. @IBAction func menuItemClick_mergePDF(_ sender: Any) {
  11. self.toolbarController.delegate?.clickChildTool?(type: .merge, index: 0)
  12. }
  13. @IBAction func menuItemClick_Compress(_ sender: Any) {
  14. self.toolbarController.delegate?.clickChildTool?(type: .compress, index: 0)
  15. }
  16. @IBAction func menuItemClick_Convert(_ sender: Any) {
  17. }
  18. @IBAction func menuItemAction_ConvertToWord(_ sender: Any) {
  19. self.toolbarController.delegate?.clickChildTool?(type: .word, index: 0)
  20. }
  21. @IBAction func menuItemAction_ConvertToExcel(_ sender: Any) {
  22. self.toolbarController.delegate?.clickChildTool?(type: .excel, index: 0)
  23. }
  24. @IBAction func menuItemAction_ConvertToPPT(_ sender: Any) {
  25. self.toolbarController.delegate?.clickChildTool?(type: .ppt, index: 0)
  26. }
  27. @IBAction func menuItemAction_ConvertToRTF(_ sender: Any) {
  28. self.toolbarController.delegate?.clickChildTool?(type: .rtf, index: 0)
  29. }
  30. @IBAction func menuItemAction_ConvertToHTML(_ sender: Any) {
  31. self.toolbarController.delegate?.clickChildTool?(type: .html, index: 0)
  32. }
  33. @IBAction func menuItemAction_ConvertToText(_ sender: Any) {
  34. self.toolbarController.delegate?.clickChildTool?(type: .conversion_text, index: 0)
  35. }
  36. @IBAction func menuItemAction_ConvertToCSV(_ sender: Any) {
  37. self.toolbarController.delegate?.clickChildTool?(type: .csv, index: 0)
  38. }
  39. @IBAction func menuItemAction_ConvertToImage(_ sender: Any) {
  40. self.toolbarController.delegate?.clickChildTool?(type: .conversion_image, index: 0)
  41. }
  42. @IBAction func menuItemClick_SettingPassword(_ sender: Any) {
  43. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 1)
  44. }
  45. @IBAction func menuItemClick_RemovePassword(_ sender: Any) {
  46. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 2)
  47. }
  48. @IBAction func menuItemAction_closeWindow(_ sender: Any) {
  49. self.view.window?.close()
  50. }
  51. @IBAction func menuItemAction_closeAllWindows(_ sender: Any) {
  52. for window in NSApp.windows {
  53. window.close()
  54. }
  55. }
  56. @IBAction func menuItemAction_closeTagPage(_ sender: Any) {
  57. self.browserWindowController?.browser.closeTab()
  58. }
  59. @IBAction func menuItemAction_showInFinder(_ sender: Any) {
  60. NSWorkspace.shared.activateFileViewerSelecting([self.listView.document.documentURL])
  61. }
  62. @IBAction func menuItemAction_property(_ sender: Any) {
  63. SKInfoWindowController().showWindow(nil)
  64. }
  65. @IBAction func menuItemAction_print(_ sender: Any) {
  66. self.showPrintWindow()
  67. }
  68. }
  69. // MARK: Edit Menu
  70. @objc protocol KMEditMenuProtocol: NSObjectProtocol {
  71. @objc optional func undo(_ sender: Any)
  72. @objc optional func redo(_ sender: Any)
  73. @objc optional func cut(_ sender: Any)
  74. @objc optional func copy(_ sender: Any)
  75. @objc optional func paste(_ sender: Any)
  76. @objc optional func delete(_ sender: Any)
  77. }
  78. extension KMMainViewController: KMEditMenuProtocol {
  79. @IBAction func menuItemAction_find(_ sender: Any) {
  80. if (self.leftSideViewController.isShowPanel) {
  81. self.toolbarController.cancelSelected(KMLeftControlToolbarItemIdentifier)
  82. self.toolbarController.toolbarType = .None
  83. self.leftSideViewController.showPanelView(show: false)
  84. }
  85. // else {
  86. let isSearch = self.leftSideViewController.type.methodType == .Search
  87. self.leftSideViewController.refreshMethodType(methodType: .Search)
  88. if (isSearch) { // 关闭
  89. self.view.window?.makeFirstResponder(self.listView)
  90. }
  91. // }
  92. }
  93. }
  94. // MARK: View Menu
  95. extension KMMainViewController {
  96. // scale
  97. @IBAction func menuItemAction_adjustWidth(_ sender: Any) {
  98. self.selectZoom(.width)
  99. }
  100. @IBAction func menuItemAction_adjustPage(_ sender: Any) {
  101. self.selectZoom(.fit)
  102. }
  103. @IBAction func menuItemAction_size(_ sender: Any) {
  104. self.selectZoom(.actualSize)
  105. }
  106. @IBAction func menuItemAction_zoomOut(_ sender: Any) {
  107. if (self.listView.canZoomOut) {
  108. self.listView.zoomOut(nil)
  109. }
  110. }
  111. @IBAction func menuItemAction_zoomIn(_ sender: Any) {
  112. if (self.listView.canZoomIn) {
  113. self.listView.zoomIn(nil)
  114. }
  115. }
  116. // page show
  117. @IBAction func menuItemAction_singlePage(_ sender: Any) {
  118. self.selectDisplay(display: .singlePage)
  119. }
  120. @IBAction func menuItemAction_singlePageContinue(_ sender: Any) {
  121. self.selectDisplay(display: .singlePageContinuous)
  122. }
  123. @IBAction func menuItemAction_doublePage(_ sender: Any) {
  124. self.selectDisplay(display: .twoUp)
  125. }
  126. @IBAction func menuItemAction_doublePageContinue(_ sender: Any) {
  127. self.selectDisplay(display: .twoUpContinuous)
  128. }
  129. @IBAction func menuItemAction_bookMode(_ sender: Any) {
  130. self.selectDisplay(display: .bookMode)
  131. }
  132. @IBAction func menuItemAction_readMode(_ sender: Any) {
  133. if (self.isReadMode) {
  134. self.closeReadModel()
  135. } else {
  136. self.openReadModel()
  137. }
  138. }
  139. @IBAction func menuItemAction_showSplitPage(_ sender: Any) {
  140. self.listView?.displaysPageBreaks = !(self.listView?.displaysPageBreaks ?? false)
  141. self.listView.layoutDocumentView()
  142. }
  143. @IBAction func menuItemAction_autoScrol(_ sender: Any) {
  144. }
  145. @IBAction func menuItemAction_autoScrolSetting(_ sender: Any) {
  146. }
  147. // rotate
  148. @IBAction func menuItemAction_rotateLeft(_ sender: Any) {
  149. Task { @MainActor in
  150. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  151. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  152. return
  153. }
  154. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  155. let rotation = page.rotation
  156. page.leftRotate()
  157. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  158. }
  159. }
  160. func rotatePageItems(pageItems: [KMThumbnailPageItem]) {
  161. let tempPageItems = pageItems
  162. for pageItem in tempPageItems {
  163. pageItem.page.rotation = pageItem.rotate
  164. }
  165. self.listView.layoutDocumentView()
  166. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView.document)
  167. self.listView.undoManager?.registerUndo(withTarget: self) { [unowned self] targetType in
  168. var tempPageItems: [KMThumbnailPageItem] = []
  169. for pageItem in pageItems {
  170. let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
  171. tempPageItems.append(item)
  172. }
  173. self.rotatePageItems(pageItems: tempPageItems)
  174. }
  175. }
  176. @IBAction func menuItemAction_rotateRight(_ sender: Any) {
  177. Task { @MainActor in
  178. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  179. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  180. return
  181. }
  182. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  183. let rotation = page.rotation
  184. page.rightRotate()
  185. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  186. }
  187. }
  188. @IBAction func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  189. Task { @MainActor in
  190. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  191. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  192. return
  193. }
  194. var pageItems: [KMThumbnailPageItem] = []
  195. for index in 0 ... self.listView.document.pageCount - 1 {
  196. let page: CPDFPage = self.listView.document.page(at: index)
  197. let rotation = page.rotation
  198. page.leftRotate()
  199. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  200. }
  201. self.rotatePageItems(pageItems: pageItems)
  202. }
  203. }
  204. @IBAction func menuItemAction_rotateAllPageRight(_ sender: Any) {
  205. Task { @MainActor in
  206. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  207. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  208. return
  209. }
  210. var pageItems: [KMThumbnailPageItem] = []
  211. for index in 0 ... self.listView.document.pageCount - 1 {
  212. let page : CPDFPage = self.listView.document.page(at: index)
  213. let rotation = page.rotation
  214. page.rightRotate()
  215. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  216. }
  217. self.rotatePageItems(pageItems: pageItems)
  218. }
  219. }
  220. // split screen
  221. @IBAction func menuItemAction_splitScreenVerti(_ sender: Any) {
  222. }
  223. @IBAction func menuItemAction_splitScreenHorti(_ sender: Any) {
  224. }
  225. @IBAction func menuItemAction_splitScreenNo(_ sender: Any) {
  226. }
  227. @IBAction func menuItemAction_view_readMode(_ sender: Any) {
  228. if (self.isReadMode) {
  229. self.closeReadModel()
  230. } else {
  231. self.openReadModel()
  232. }
  233. }
  234. @IBAction func menuItemAction_enterFullScreen(_ sender: Any) {
  235. }
  236. @IBAction func menuItemAction_hiddenLeftSide(_ sender: Any) {
  237. if (self.leftSideViewController.type.methodType != .None) {
  238. self.leftSideViewController.selectType(self.leftSideViewController.type.methodType)
  239. } else {
  240. self.toolbarController.selectItem(KMLeftControlToolbarItemIdentifier)
  241. }
  242. }
  243. @IBAction func menuItemAction_hiddenRightSide(_ sender: Any) {
  244. self.toolbarController.selectItem(KMRightControlToolbarItemIdentifier)
  245. }
  246. @IBAction func menuItemAction_thumai(_ sender: Any) {
  247. self.leftSideViewController.refreshMethodType(methodType: .Thumbnail)
  248. }
  249. @IBAction func menuItemAction_outline(_ sender: Any) {
  250. self.leftSideViewController.refreshMethodType(methodType: .Outline)
  251. }
  252. @IBAction func menuItemAction_bookmark(_ sender: Any) {
  253. self.leftSideViewController.refreshMethodType(methodType: .BookMark)
  254. }
  255. @IBAction func menuItemAction_annotation(_ sender: Any) {
  256. self.leftSideViewController.refreshMethodType(methodType: .Annotation)
  257. }
  258. @IBAction func menuItemAction_search(_ sender: Any) {
  259. self.leftSideViewController.refreshMethodType(methodType: .Search)
  260. }
  261. @IBAction func menuItemAction_topic(_ sender: Any) {
  262. }
  263. @IBAction func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  264. }
  265. }
  266. // MARK: Annotation Menu
  267. extension KMMainViewController {
  268. @IBAction func menuItemAction_highlight(_ sender: Any) {
  269. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarHighlightAnnotationItemIdentifier)
  270. }
  271. @IBAction func menuItemAction_underline(_ sender: Any) {
  272. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarUnderlineAnnotationItemIdentifier)
  273. }
  274. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  275. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarStrikeOutAnnotationItemIdentifier)
  276. }
  277. @IBAction func menuItemAction_freehand(_ sender: Any) {
  278. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarInkAnnotationItemIdentifier)
  279. }
  280. @IBAction func menuItemAction_text(_ sender: Any) {
  281. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarFreeTextAnnotationItemIdentifier)
  282. }
  283. @IBAction func menuItemAction_note(_ sender: Any) {
  284. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarAnchoredAnnotationItemIdentifier)
  285. }
  286. @IBAction func menuItemAction_squre(_ sender: Any) {
  287. UserDefaults.standard.set(6, forKey: KMToolBarToolPDFShapeStyle)
  288. if (self.listView.annotationType == .square) {
  289. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  290. } else {
  291. if (self.listView.annotationType == .circle || self.listView.annotationType == .line || self.listView.annotationType == .arrow) {
  292. self.listView.annotationType = .square
  293. self.rightSideViewController.annotationProperties.annotationMode = .square
  294. } else {
  295. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  296. }
  297. }
  298. }
  299. @IBAction func menuItemAction_circle(_ sender: Any) {
  300. UserDefaults.standard.set(7, forKey: KMToolBarToolPDFShapeStyle)
  301. if (self.listView.annotationType == .circle) { // 取消
  302. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  303. } else {
  304. if (self.listView.annotationType == .square || self.listView.annotationType == .line || self.listView.annotationType == .arrow) { // 切换
  305. self.listView.annotationType = .circle
  306. self.rightSideViewController.annotationProperties.annotationMode = .circle
  307. } else { // 选中
  308. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  309. }
  310. }
  311. }
  312. @IBAction func menuItemAction_arrow(_ sender: Any) {
  313. UserDefaults.standard.set(5, forKey: KMToolBarToolPDFShapeStyle)
  314. if (self.listView.annotationType == .arrow) { // 取消
  315. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  316. } else { // 选中
  317. if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .line) { // 切换
  318. self.listView.annotationType = .arrow
  319. self.rightSideViewController.annotationProperties.annotationMode = .arrow
  320. } else {
  321. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  322. }
  323. }
  324. }
  325. @IBAction func menuItemAction_line(_ sender: Any) {
  326. UserDefaults.standard.set(4, forKey: KMToolBarToolPDFShapeStyle)
  327. if (self.listView.annotationType == .line) { // 取消
  328. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  329. } else { // 选中
  330. if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .arrow) { // 切换
  331. self.listView.annotationType = .line
  332. self.rightSideViewController.annotationProperties.annotationMode = .line
  333. } else {
  334. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  335. }
  336. }
  337. }
  338. // link
  339. @IBAction func menuItemAction_link(_ sender: Any) {
  340. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  341. }
  342. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  343. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  344. }
  345. @IBAction func menuItemAction_linkHttps(_ sender: Any) {
  346. }
  347. @IBAction func menuItemAction_linkEmail(_ sender: Any) {
  348. }
  349. // stamp
  350. @IBAction func menuItemAction_stamp(_ sender: Any) {
  351. self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
  352. }
  353. @IBAction func menuItemAction_stampStandard(_ sender: Any) {
  354. }
  355. @IBAction func menuItemAction_stampDynamic(_ sender: Any) {
  356. }
  357. @IBAction func menuItemAction_stampCustom(_ sender: Any) {
  358. }
  359. @IBAction func menuItemAction_signure(_ sender: Any) {
  360. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSignSignatureAnnotationItemIdentifier)
  361. }
  362. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  363. self.showOrHideNotes()
  364. }
  365. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  366. self.removeAllAnnotations()
  367. }
  368. private func mainMenuUpdateAnnotationStyle(identifier : String) {
  369. if self.toolbarController.toolbarType != .Annatiton {
  370. let item : KMToolBoxItem = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
  371. self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Annatiton, toolbar: item, [])
  372. }
  373. let childitem : KMToolBoxItem = (self.toolbarController.childToolBarView?.toolbarItemFindItemIdentifiers(value: identifier))!
  374. self.toolbarController.mainToolBarView?.delegate?.changeAnnotationModeAction?(item: childitem.clickButton)
  375. }
  376. }
  377. // MARK: goto Menu
  378. extension KMMainViewController {
  379. @IBAction func menuItemAction_nextPage(_ sender: Any) {
  380. if (self.listView.canGoToNextPage()) {
  381. self.listView.goToNextPage(nil)
  382. }
  383. }
  384. @IBAction func menuItemAction_forwardPage(_ sender: Any) {
  385. if (self.listView.canGoToPreviousPage()) {
  386. self.listView.goToPreviousPage(nil)
  387. }
  388. }
  389. @IBAction func menuItemAction_firstPage(_ sender: Any) {
  390. if (self.listView.canGoToFirstPage()) {
  391. self.listView.goToFirstPage(nil)
  392. }
  393. }
  394. @IBAction func menuItemAction_lastPage(_ sender: Any) {
  395. if (self.listView.canGoToLastPage()) {
  396. self.listView.goToLastPage(nil)
  397. }
  398. }
  399. @IBAction func menuItemAction_forward(_ sender: Any) {
  400. if (self.listView.canGoForward()) {
  401. self.listView.goForward(nil)
  402. }
  403. }
  404. @IBAction func menuItemAction_goback(_ sender: Any) {
  405. if (self.listView.canGoBack()) {
  406. self.listView.goBack(nil)
  407. }
  408. }
  409. @IBAction func menuItemAction_gotoPage(_ sender: Any) {
  410. let sheet = SKTextFieldSheetController.init(windowNibName: "PageSheet")
  411. var pages : [String] = []
  412. for i in 0 ..< self.listView.document.pageCount {
  413. pages.append("\(i)")
  414. }
  415. sheet.callback = { [weak self] stringValue in
  416. if (stringValue == nil) {
  417. return
  418. }
  419. guard let index = Int(stringValue!) else {
  420. return
  421. }
  422. if (self?.listView == nil) {
  423. return
  424. }
  425. if (index > 0 && index <= self!.listView.document.pageCount) {
  426. self?.listView.go(toPageIndex: index-1, animated: true)
  427. }
  428. }
  429. sheet.showWindow(nil)
  430. sheet.pageBox.addItems(withObjectValues: pages)
  431. sheet.stringValue = "\(self.listView.currentPageIndex+1)"
  432. }
  433. }
  434. // MARK: tool Menu
  435. extension KMMainViewController {
  436. @IBAction func menuItemAction_textTool(_ sender: Any) {
  437. self.toolbarController.selectItem(KMToolbarZoomToSelectionItemIdentifier)
  438. }
  439. @IBAction func menuItemAction_scrolTool(_ sender: Any) {
  440. self.toolbarController.selectItem(KMToolbarMoveToolModeItemIdentifier)
  441. }
  442. @IBAction func menuItemAction_zoomOutTool(_ sender: Any) {
  443. self.toolbarController.selectItem(KMToolbarMagnifyToolModeItemIdentifier)
  444. }
  445. @IBAction func menuItemAction_selectTool(_ sender: Any) {
  446. self.toolbarController.selectItem(KMToolbarSelectToolModeItemIdentifier)
  447. }
  448. @IBAction func menuItemAction_redact(_ sender: Any) {
  449. self.toolbarController.enterRedact()
  450. }
  451. @IBAction func menuItemAction_warkmark(_ sender: Any) {
  452. self.toolbarController.delegate?.clickChildTool?(type: .watermark, index: 0)
  453. }
  454. @IBAction func menuItemAction_background(_ sender: Any) {
  455. self.toolbarController.delegate?.clickChildTool?(type: .background, index: 0)
  456. }
  457. @IBAction func menuItemAction_headerfooter(_ sender: Any) {
  458. self.toolbarController.delegate?.clickChildTool?(type: .headerAndFooter, index: 0)
  459. }
  460. @IBAction func menuItemAction_bates(_ sender: Any) {
  461. self.toolbarController.delegate?.clickChildTool?(type: .bates, index: 0)
  462. }
  463. @IBAction func menuItemAction_batch(_ sender: Any) {
  464. KMBatchWindowController.openFile(self.listView.document?.documentURL, .Batch)
  465. }
  466. }
  467. // MARK: window Menu
  468. extension KMMainViewController {
  469. @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {
  470. self.browserWindowController?.browser?.selectPreviousTab()
  471. }
  472. @IBAction func menuItemAction_showNextTagPage(_ sender: Any) {
  473. self.browserWindowController?.browser?.selectNextTab()
  474. }
  475. @IBAction func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  476. self.browserWindowController?.openNewWindow(sender)
  477. }
  478. @IBAction func menuItemAction_mergeAllWindow(_ sender: Any) {
  479. self.browserWindowController?.mergeAllWindow(sender)
  480. }
  481. @IBAction func menuItemAction_currentWindowName(_ sender: Any) {
  482. }
  483. }
  484. extension KMMainViewController: NSMenuItemValidation, NSMenuDelegate {
  485. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  486. if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
  487. menuItem.title = (self.myDocument?.fileURL!.lastPathComponent)!
  488. return true
  489. }
  490. if (menuItem.action == #selector(menuItemAction_thumai) ||
  491. menuItem.action == #selector(menuItemAction_outline) ||
  492. menuItem.action == #selector(menuItemAction_bookmark) ||
  493. menuItem.action == #selector(menuItemAction_annotation) ||
  494. menuItem.action == #selector(menuItemAction_search)) {
  495. menuItem.state = .off
  496. let type = self.leftSideViewController.type.methodType
  497. if (menuItem.action == #selector(menuItemAction_thumai) && type == .Thumbnail) {
  498. menuItem.state = .on
  499. }
  500. if (menuItem.action == #selector(menuItemAction_outline) && type == .Outline) {
  501. menuItem.state = .on
  502. }
  503. if (menuItem.action == #selector(menuItemAction_bookmark) && type == .BookMark) {
  504. menuItem.state = .on
  505. }
  506. if (menuItem.action == #selector(menuItemAction_annotation) && type == .Annotation) {
  507. menuItem.state = .on
  508. }
  509. if (menuItem.action == #selector(menuItemAction_search) && type == .Search) {
  510. menuItem.state = .on
  511. }
  512. }
  513. if (menuItem.action == #selector(menuItemAction_hiddenLeftSide)) {
  514. if (self.leftPanelOpen) {
  515. menuItem.title = NSLocalizedString("Hide Left Side Panel", comment: "")
  516. } else {
  517. menuItem.title = NSLocalizedString("Show Left Side Panel", comment: "")
  518. }
  519. }
  520. if (menuItem.action == #selector(menuItemAction_hiddenRightSide)) {
  521. if (self.rightPanelIsOpen) {
  522. menuItem.title = NSLocalizedString("Hide Right Side Panel", comment: "")
  523. } else {
  524. menuItem.title = NSLocalizedString("Show Right Side Panel", comment: "")
  525. }
  526. }
  527. if (menuItem.action == #selector(menuItemAction_hiddenAllAnnotation)) {
  528. if (self.listView.hideNotes) {
  529. menuItem.title = NSLocalizedString("Show Notes", comment: "")
  530. } else {
  531. menuItem.title = NSLocalizedString("Hide Notes", comment: "")
  532. }
  533. }
  534. if (menuItem.action == #selector(menuItemAction_showForwardTagPage) ||
  535. menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  536. let browser = self.browserWindowController?.browser
  537. if (browser != nil && (browser is KMBrowser)) {
  538. if (menuItem.action == #selector(menuItemAction_showForwardTagPage)) {
  539. return (browser as! KMBrowser).canSelectPreviousTab()
  540. }
  541. if (menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  542. return (browser as! KMBrowser).canSelectNextTab()
  543. }
  544. }
  545. }
  546. if (menuItem.action == #selector(menuItemAction_nextPage) ||
  547. menuItem.action == #selector(menuItemAction_forwardPage) ||
  548. menuItem.action == #selector(menuItemAction_firstPage) ||
  549. menuItem.action == #selector(menuItemAction_lastPage) ||
  550. menuItem.action == #selector(menuItemAction_forward) ||
  551. menuItem.action == #selector(menuItemAction_goback)) {
  552. if (menuItem.action == #selector(menuItemAction_nextPage)) {
  553. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage())
  554. }
  555. if (menuItem.action == #selector(menuItemAction_forwardPage)) {
  556. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage())
  557. }
  558. if (menuItem.action == #selector(menuItemAction_firstPage)) {
  559. return self.listView.canGoToFirstPage()
  560. }
  561. if (menuItem.action == #selector(menuItemAction_lastPage)) {
  562. return self.listView.canGoToLastPage()
  563. }
  564. if (menuItem.action == #selector(menuItemAction_forward)) {
  565. return self.listView.canGoForward()
  566. }
  567. if (menuItem.action == #selector(menuItemAction_goback)) {
  568. return self.listView.canGoBack()
  569. }
  570. }
  571. return true
  572. }
  573. }