KMMainViewController+MenuAction.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. extension KMMainViewController: KMSystemFileMenuProtocol {
  70. @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
  71. Task { @MainActor in
  72. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  73. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  74. return
  75. }
  76. if await (KMLightMemberManager.manager.canPayFunction() == false) {
  77. let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
  78. if (isClose) {
  79. return
  80. }
  81. if (isSubscribeSuccess) {
  82. self.saveAsFlattenedPDFAction()
  83. return
  84. }
  85. if (isWaterMarkExport) {
  86. self.saveAsFlattenedPDFAction(limit: true)
  87. return
  88. }
  89. }
  90. return
  91. }
  92. self.saveAsFlattenedPDFAction()
  93. }
  94. }
  95. func saveAsFlattenedPDFAction(limit: Bool = false) {
  96. DispatchQueue.main.async {
  97. NSPanel.savePanel(self.view.window!, true) { panel in
  98. panel.nameFieldStringValue = self.listView.document.documentURL.deletingPathExtension().lastPathComponent + "_flatten" + ".pdf"
  99. } completion: { response, url, isOpen in
  100. if (response == .cancel) {
  101. return
  102. }
  103. var result = false
  104. if (limit) {
  105. let data = KMTools.saveWatermarkDocumentForFlatten(document: self.listView.document, to: url!)
  106. result = data != nil
  107. } else {
  108. result = self.listView.document.writeFlatten(to: url!)
  109. }
  110. if (!result) {
  111. return
  112. }
  113. if (isOpen) {
  114. NSDocumentController.shared.km_safe_openDocument(withContentsOf: url!, display: true) { _, _, _ in
  115. }
  116. } else {
  117. NSWorkspace.shared.activateFileViewerSelecting([url!])
  118. }
  119. }
  120. }
  121. }
  122. }
  123. // MARK: Edit Menu
  124. @objc protocol KMEditMenuProtocol: NSObjectProtocol {
  125. @objc optional func undo(_ sender: Any)
  126. @objc optional func redo(_ sender: Any)
  127. @objc optional func cut(_ sender: Any)
  128. @objc optional func copy(_ sender: Any)
  129. @objc optional func paste(_ sender: Any)
  130. @objc optional func delete(_ sender: Any)
  131. }
  132. extension KMMainViewController: KMEditMenuProtocol {
  133. @IBAction func menuItemAction_find(_ sender: Any) {
  134. if (self.leftSideViewController.isShowPanel) {
  135. self.toolbarController.cancelSelected(KMLeftControlToolbarItemIdentifier)
  136. self.toolbarController.toolbarType = .None
  137. self.leftSideViewController.showPanelView(show: false)
  138. }
  139. // else {
  140. let isSearch = self.leftSideViewController.type.methodType == .Search
  141. self.leftSideViewController.refreshMethodType(methodType: .Search)
  142. if (isSearch) { // 关闭
  143. self.view.window?.makeFirstResponder(self.listView)
  144. }
  145. // }
  146. }
  147. }
  148. // MARK: View Menu
  149. extension KMMainViewController {
  150. // scale
  151. @IBAction func menuItemAction_adjustWidth(_ sender: Any) {
  152. self.selectZoom(.width)
  153. }
  154. @IBAction func menuItemAction_adjustPage(_ sender: Any) {
  155. self.selectZoom(.fit)
  156. }
  157. @IBAction func menuItemAction_size(_ sender: Any) {
  158. self.selectZoom(.actualSize)
  159. }
  160. @IBAction func menuItemAction_zoomOut(_ sender: Any) {
  161. if (self.listView.canZoomOut) {
  162. self.listView.zoomOut(nil)
  163. }
  164. }
  165. @IBAction func menuItemAction_zoomIn(_ sender: Any) {
  166. if (self.listView.canZoomIn) {
  167. self.listView.zoomIn(nil)
  168. }
  169. }
  170. // page show
  171. @IBAction func menuItemAction_singlePage(_ sender: Any) {
  172. self.selectDisplay(display: .singlePage)
  173. }
  174. @IBAction func menuItemAction_singlePageContinue(_ sender: Any) {
  175. self.selectDisplay(display: .singlePageContinuous)
  176. }
  177. @IBAction func menuItemAction_doublePage(_ sender: Any) {
  178. self.selectDisplay(display: .twoUp)
  179. }
  180. @IBAction func menuItemAction_doublePageContinue(_ sender: Any) {
  181. self.selectDisplay(display: .twoUpContinuous)
  182. }
  183. @IBAction func menuItemAction_bookMode(_ sender: Any) {
  184. self.selectDisplay(display: .bookMode)
  185. }
  186. @IBAction func menuItemAction_readMode(_ sender: Any) {
  187. if (self.isReadMode) {
  188. self.closeReadModel()
  189. } else {
  190. self.openReadModel()
  191. }
  192. }
  193. @IBAction func menuItemAction_showSplitPage(_ sender: Any) {
  194. self.listView?.displaysPageBreaks = !(self.listView?.displaysPageBreaks ?? false)
  195. self.listView.layoutDocumentView()
  196. }
  197. @IBAction func menuItemAction_autoScrol(_ sender: Any) {
  198. }
  199. @IBAction func menuItemAction_autoScrolSetting(_ sender: Any) {
  200. }
  201. // rotate
  202. @IBAction func menuItemAction_rotateLeft(_ sender: Any) {
  203. Task { @MainActor in
  204. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  205. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  206. return
  207. }
  208. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  209. let rotation = page.rotation
  210. page.leftRotate()
  211. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  212. }
  213. }
  214. func rotatePageItems(pageItems: [KMThumbnailPageItem]) {
  215. let tempPageItems = pageItems
  216. for pageItem in tempPageItems {
  217. pageItem.page.rotation = pageItem.rotate
  218. }
  219. self.listView.layoutDocumentView()
  220. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView.document)
  221. self.listView.undoManager?.registerUndo(withTarget: self) { [unowned self] targetType in
  222. var tempPageItems: [KMThumbnailPageItem] = []
  223. for pageItem in pageItems {
  224. let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
  225. tempPageItems.append(item)
  226. }
  227. self.rotatePageItems(pageItems: tempPageItems)
  228. }
  229. }
  230. @IBAction func menuItemAction_rotateRight(_ sender: Any) {
  231. Task { @MainActor in
  232. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  233. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  234. return
  235. }
  236. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  237. let rotation = page.rotation
  238. page.rightRotate()
  239. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  240. }
  241. }
  242. @IBAction func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  243. Task { @MainActor in
  244. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  245. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  246. return
  247. }
  248. var pageItems: [KMThumbnailPageItem] = []
  249. for index in 0 ... self.listView.document.pageCount - 1 {
  250. let page: CPDFPage = self.listView.document.page(at: index)
  251. let rotation = page.rotation
  252. page.leftRotate()
  253. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  254. }
  255. self.rotatePageItems(pageItems: pageItems)
  256. }
  257. }
  258. @IBAction func menuItemAction_rotateAllPageRight(_ sender: Any) {
  259. Task { @MainActor in
  260. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  261. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  262. return
  263. }
  264. var pageItems: [KMThumbnailPageItem] = []
  265. for index in 0 ... self.listView.document.pageCount - 1 {
  266. let page : CPDFPage = self.listView.document.page(at: index)
  267. let rotation = page.rotation
  268. page.rightRotate()
  269. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  270. }
  271. self.rotatePageItems(pageItems: pageItems)
  272. }
  273. }
  274. // split screen
  275. @IBAction func menuItemAction_splitScreenVerti(_ sender: Any) {
  276. }
  277. @IBAction func menuItemAction_splitScreenHorti(_ sender: Any) {
  278. }
  279. @IBAction func menuItemAction_splitScreenNo(_ sender: Any) {
  280. }
  281. @IBAction func menuItemAction_view_readMode(_ sender: Any) {
  282. if (self.isReadMode) {
  283. self.closeReadModel()
  284. } else {
  285. self.openReadModel()
  286. }
  287. }
  288. @IBAction func menuItemAction_enterFullScreen(_ sender: Any) {
  289. }
  290. @IBAction func menuItemAction_hiddenLeftSide(_ sender: Any) {
  291. if (self.leftSideViewController.type.methodType != .None) {
  292. self.leftSideViewController.selectType(self.leftSideViewController.type.methodType)
  293. } else {
  294. self.toolbarController.selectItem(KMLeftControlToolbarItemIdentifier)
  295. }
  296. }
  297. @IBAction func menuItemAction_hiddenRightSide(_ sender: Any) {
  298. self.toolbarController.selectItem(KMRightControlToolbarItemIdentifier)
  299. }
  300. @IBAction func menuItemAction_thumai(_ sender: Any) {
  301. self.leftSideViewController.refreshMethodType(methodType: .Thumbnail)
  302. }
  303. @IBAction func menuItemAction_outline(_ sender: Any) {
  304. self.leftSideViewController.refreshMethodType(methodType: .Outline)
  305. }
  306. @IBAction func menuItemAction_bookmark(_ sender: Any) {
  307. self.leftSideViewController.refreshMethodType(methodType: .BookMark)
  308. }
  309. @IBAction func menuItemAction_annotation(_ sender: Any) {
  310. self.leftSideViewController.refreshMethodType(methodType: .Annotation)
  311. }
  312. @IBAction func menuItemAction_search(_ sender: Any) {
  313. self.leftSideViewController.refreshMethodType(methodType: .Search)
  314. }
  315. @IBAction func menuItemAction_topic(_ sender: Any) {
  316. }
  317. @IBAction func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  318. }
  319. }
  320. // MARK: Annotation Menu
  321. extension KMMainViewController {
  322. @IBAction func menuItemAction_highlight(_ sender: Any) {
  323. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarHighlightAnnotationItemIdentifier)
  324. }
  325. @IBAction func menuItemAction_underline(_ sender: Any) {
  326. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarUnderlineAnnotationItemIdentifier)
  327. }
  328. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  329. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarStrikeOutAnnotationItemIdentifier)
  330. }
  331. @IBAction func menuItemAction_freehand(_ sender: Any) {
  332. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarInkAnnotationItemIdentifier)
  333. }
  334. @IBAction func menuItemAction_text(_ sender: Any) {
  335. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarFreeTextAnnotationItemIdentifier)
  336. }
  337. @IBAction func menuItemAction_note(_ sender: Any) {
  338. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarAnchoredAnnotationItemIdentifier)
  339. }
  340. @IBAction func menuItemAction_squre(_ sender: Any) {
  341. UserDefaults.standard.set(6, forKey: KMToolBarToolPDFShapeStyle)
  342. if (self.listView.annotationType == .square) {
  343. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  344. } else {
  345. if (self.listView.annotationType == .circle || self.listView.annotationType == .line || self.listView.annotationType == .arrow) {
  346. self.listView.annotationType = .square
  347. self.rightSideViewController.annotationProperties.annotationMode = .square
  348. } else {
  349. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  350. }
  351. }
  352. }
  353. @IBAction func menuItemAction_circle(_ sender: Any) {
  354. UserDefaults.standard.set(7, forKey: KMToolBarToolPDFShapeStyle)
  355. if (self.listView.annotationType == .circle) { // 取消
  356. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  357. } else {
  358. if (self.listView.annotationType == .square || self.listView.annotationType == .line || self.listView.annotationType == .arrow) { // 切换
  359. self.listView.annotationType = .circle
  360. self.rightSideViewController.annotationProperties.annotationMode = .circle
  361. } else { // 选中
  362. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  363. }
  364. }
  365. }
  366. @IBAction func menuItemAction_arrow(_ sender: Any) {
  367. UserDefaults.standard.set(5, forKey: KMToolBarToolPDFShapeStyle)
  368. if (self.listView.annotationType == .arrow) { // 取消
  369. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  370. } else { // 选中
  371. if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .line) { // 切换
  372. self.listView.annotationType = .arrow
  373. self.rightSideViewController.annotationProperties.annotationMode = .arrow
  374. } else {
  375. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  376. }
  377. }
  378. }
  379. @IBAction func menuItemAction_line(_ sender: Any) {
  380. UserDefaults.standard.set(4, forKey: KMToolBarToolPDFShapeStyle)
  381. if (self.listView.annotationType == .line) { // 取消
  382. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  383. } else { // 选中
  384. if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .arrow) { // 切换
  385. self.listView.annotationType = .line
  386. self.rightSideViewController.annotationProperties.annotationMode = .line
  387. } else {
  388. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  389. }
  390. }
  391. }
  392. // link
  393. @IBAction func menuItemAction_link(_ sender: Any) {
  394. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  395. }
  396. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  397. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  398. }
  399. @IBAction func menuItemAction_linkHttps(_ sender: Any) {
  400. }
  401. @IBAction func menuItemAction_linkEmail(_ sender: Any) {
  402. }
  403. // stamp
  404. @IBAction func menuItemAction_stamp(_ sender: Any) {
  405. self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
  406. }
  407. @IBAction func menuItemAction_stampStandard(_ sender: Any) {
  408. }
  409. @IBAction func menuItemAction_stampDynamic(_ sender: Any) {
  410. }
  411. @IBAction func menuItemAction_stampCustom(_ sender: Any) {
  412. }
  413. @IBAction func menuItemAction_signure(_ sender: Any) {
  414. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSignSignatureAnnotationItemIdentifier)
  415. }
  416. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  417. self.showOrHideNotes()
  418. }
  419. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  420. self.removeAllAnnotations()
  421. }
  422. private func mainMenuUpdateAnnotationStyle(identifier : String) {
  423. if self.toolbarController.toolbarType != .Annatiton {
  424. let item : KMToolBoxItem = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
  425. self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Annatiton, toolbar: item, [])
  426. }
  427. let childitem : KMToolBoxItem = (self.toolbarController.childToolBarView?.toolbarItemFindItemIdentifiers(value: identifier))!
  428. self.toolbarController.mainToolBarView?.delegate?.changeAnnotationModeAction?(item: childitem.clickButton)
  429. }
  430. }
  431. // MARK: goto Menu
  432. extension KMMainViewController {
  433. @IBAction func menuItemAction_nextPage(_ sender: Any) {
  434. if (self.listView.canGoToNextPage()) {
  435. self.listView.goToNextPage(nil)
  436. }
  437. }
  438. @IBAction func menuItemAction_forwardPage(_ sender: Any) {
  439. if (self.listView.canGoToPreviousPage()) {
  440. self.listView.goToPreviousPage(nil)
  441. }
  442. }
  443. @IBAction func menuItemAction_firstPage(_ sender: Any) {
  444. if (self.listView.canGoToFirstPage()) {
  445. self.listView.goToFirstPage(nil)
  446. }
  447. }
  448. @IBAction func menuItemAction_lastPage(_ sender: Any) {
  449. if (self.listView.canGoToLastPage()) {
  450. self.listView.goToLastPage(nil)
  451. }
  452. }
  453. @IBAction func menuItemAction_forward(_ sender: Any) {
  454. if (self.listView.km_canGoForward()) {
  455. self.listView.km_goForward(nil)
  456. }
  457. }
  458. @IBAction func menuItemAction_goback(_ sender: Any) {
  459. if (self.listView.km_canGoBack()) {
  460. self.listView.km_goBack(nil)
  461. }
  462. }
  463. @IBAction func menuItemAction_gotoPage(_ sender: Any) {
  464. let sheet = SKTextFieldSheetController.init(windowNibName: "PageSheet")
  465. var pages : [String] = []
  466. for i in 0 ..< self.listView.document.pageCount {
  467. pages.append("\(i)")
  468. }
  469. sheet.callback = { [weak self] stringValue in
  470. if (stringValue == nil) {
  471. return
  472. }
  473. guard let index = Int(stringValue!) else {
  474. return
  475. }
  476. if (self?.listView == nil) {
  477. return
  478. }
  479. if (index > 0 && index <= self!.listView.document.pageCount) {
  480. self?.listView.go(toPageIndex: index-1, animated: true)
  481. }
  482. }
  483. sheet.showWindow(nil)
  484. sheet.pageBox.addItems(withObjectValues: pages)
  485. sheet.stringValue = "\(self.listView.currentPageIndex+1)"
  486. }
  487. }
  488. // MARK: tool Menu
  489. extension KMMainViewController {
  490. @IBAction func menuItemAction_textTool(_ sender: Any) {
  491. self.toolbarController.selectItem(KMToolbarZoomToSelectionItemIdentifier)
  492. }
  493. @IBAction func menuItemAction_scrolTool(_ sender: Any) {
  494. self.toolbarController.selectItem(KMToolbarMoveToolModeItemIdentifier)
  495. }
  496. @IBAction func menuItemAction_zoomOutTool(_ sender: Any) {
  497. self.toolbarController.selectItem(KMToolbarMagnifyToolModeItemIdentifier)
  498. }
  499. @IBAction func menuItemAction_selectTool(_ sender: Any) {
  500. self.toolbarController.selectItem(KMToolbarSelectToolModeItemIdentifier)
  501. }
  502. @IBAction func menuItemAction_redact(_ sender: Any) {
  503. self.toolbarController.enterRedact()
  504. }
  505. @IBAction func menuItemAction_warkmark(_ sender: Any) {
  506. self.toolbarController.delegate?.clickChildTool?(type: .watermark, index: 0)
  507. }
  508. @IBAction func menuItemAction_background(_ sender: Any) {
  509. self.toolbarController.delegate?.clickChildTool?(type: .background, index: 0)
  510. }
  511. @IBAction func menuItemAction_headerfooter(_ sender: Any) {
  512. self.toolbarController.delegate?.clickChildTool?(type: .headerAndFooter, index: 0)
  513. }
  514. @IBAction func menuItemAction_bates(_ sender: Any) {
  515. self.toolbarController.delegate?.clickChildTool?(type: .bates, index: 0)
  516. }
  517. @IBAction func menuItemAction_batch(_ sender: Any) {
  518. KMBatchWindowController.openFile(self.listView.document?.documentURL, .Batch)
  519. }
  520. }
  521. // MARK: window Menu
  522. extension KMMainViewController {
  523. @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {
  524. (self.myDocument as? KMMainDocument)?.browser.selectPreviousTab()
  525. }
  526. @IBAction func menuItemAction_showNextTagPage(_ sender: Any) {
  527. (self.myDocument as? KMMainDocument)?.browser.selectNextTab()
  528. }
  529. @IBAction func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  530. self.browserWindowController?.openNewWindow(sender)
  531. }
  532. @IBAction func menuItemAction_mergeAllWindow(_ sender: Any) {
  533. ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController)?.mergeAllWindow(sender)
  534. }
  535. @IBAction func menuItemAction_currentWindowName(_ sender: Any) {
  536. }
  537. }
  538. extension KMMainViewController: NSMenuItemValidation, NSMenuDelegate {
  539. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  540. if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
  541. menuItem.title = (self.myDocument?.fileURL!.lastPathComponent)!
  542. return true
  543. }
  544. if (menuItem.action == #selector(menuItemAction_thumai) ||
  545. menuItem.action == #selector(menuItemAction_outline) ||
  546. menuItem.action == #selector(menuItemAction_bookmark) ||
  547. menuItem.action == #selector(menuItemAction_annotation) ||
  548. menuItem.action == #selector(menuItemAction_search)) {
  549. menuItem.state = .off
  550. let type = self.leftSideViewController.type.methodType
  551. if (menuItem.action == #selector(menuItemAction_thumai) && type == .Thumbnail) {
  552. menuItem.state = .on
  553. }
  554. if (menuItem.action == #selector(menuItemAction_outline) && type == .Outline) {
  555. menuItem.state = .on
  556. }
  557. if (menuItem.action == #selector(menuItemAction_bookmark) && type == .BookMark) {
  558. menuItem.state = .on
  559. }
  560. if (menuItem.action == #selector(menuItemAction_annotation) && type == .Annotation) {
  561. menuItem.state = .on
  562. }
  563. if (menuItem.action == #selector(menuItemAction_search) && type == .Search) {
  564. menuItem.state = .on
  565. }
  566. }
  567. if (menuItem.action == #selector(menuItemAction_hiddenLeftSide)) {
  568. if (self.leftPanelOpen) {
  569. menuItem.title = NSLocalizedString("Hide Left Side Panel", comment: "")
  570. } else {
  571. menuItem.title = NSLocalizedString("Show Left Side Panel", comment: "")
  572. }
  573. }
  574. if (menuItem.action == #selector(menuItemAction_hiddenRightSide)) {
  575. if (self.rightPanelIsOpen) {
  576. menuItem.title = NSLocalizedString("Hide Right Side Panel", comment: "")
  577. } else {
  578. menuItem.title = NSLocalizedString("Show Right Side Panel", comment: "")
  579. }
  580. }
  581. if (menuItem.action == #selector(menuItemAction_hiddenAllAnnotation)) {
  582. if (self.listView.hideNotes) {
  583. menuItem.title = NSLocalizedString("Show Notes", comment: "")
  584. } else {
  585. menuItem.title = NSLocalizedString("Hide Notes", comment: "")
  586. }
  587. }
  588. if (menuItem.action == #selector(menuItemAction_showForwardTagPage) ||
  589. menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  590. let browser = self.browserWindowController?.browser
  591. if (browser != nil && (browser is KMBrowser)) {
  592. if (menuItem.action == #selector(menuItemAction_showForwardTagPage)) {
  593. return (browser as! KMBrowser).canSelectPreviousTab()
  594. }
  595. if (menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  596. return (browser as! KMBrowser).canSelectNextTab()
  597. }
  598. }
  599. }
  600. if (menuItem.action == #selector(menuItemAction_mergeAllWindow)) {
  601. if let _browserWindowC = ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController) {
  602. return _browserWindowC.canMergeAllWindow()
  603. }
  604. }
  605. if (menuItem.action == #selector(menuItemAction_nextPage) ||
  606. menuItem.action == #selector(menuItemAction_forwardPage) ||
  607. menuItem.action == #selector(menuItemAction_firstPage) ||
  608. menuItem.action == #selector(menuItemAction_lastPage) ||
  609. menuItem.action == #selector(menuItemAction_forward) ||
  610. menuItem.action == #selector(menuItemAction_goback)) {
  611. if (menuItem.action == #selector(menuItemAction_nextPage)) {
  612. if self.listView.isEditing() && self.listView.isEditable() {
  613. return false
  614. }
  615. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage())
  616. }
  617. if (menuItem.action == #selector(menuItemAction_forwardPage)) {
  618. if self.listView.isEditing() && self.listView.isEditable() {
  619. return false
  620. }
  621. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage())
  622. }
  623. if (menuItem.action == #selector(menuItemAction_firstPage)) {
  624. return self.listView.canGoToFirstPage()
  625. }
  626. if (menuItem.action == #selector(menuItemAction_lastPage)) {
  627. return self.listView.canGoToLastPage()
  628. }
  629. if (menuItem.action == #selector(menuItemAction_forward)) {
  630. return self.listView.km_canGoForward()
  631. }
  632. if (menuItem.action == #selector(menuItemAction_goback)) {
  633. return self.listView.km_canGoBack()
  634. }
  635. }
  636. return true
  637. }
  638. }