KMMainViewController+MenuAction.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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 VERSION_DMG
  205. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  206. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  207. return
  208. }
  209. #endif
  210. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  211. let rotation = page.rotation
  212. page.leftRotate()
  213. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  214. }
  215. }
  216. func rotatePageItems(pageItems: [KMThumbnailPageItem]) {
  217. let tempPageItems = pageItems
  218. for pageItem in tempPageItems {
  219. pageItem.page.rotation = pageItem.rotate
  220. }
  221. self.listView.layoutDocumentView()
  222. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView.document)
  223. self.listView.undoManager?.registerUndo(withTarget: self) { [unowned self] targetType in
  224. var tempPageItems: [KMThumbnailPageItem] = []
  225. for pageItem in pageItems {
  226. let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
  227. tempPageItems.append(item)
  228. }
  229. self.rotatePageItems(pageItems: tempPageItems)
  230. }
  231. }
  232. @IBAction func menuItemAction_rotateRight(_ sender: Any) {
  233. Task { @MainActor in
  234. #if VERSION_DMG
  235. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  236. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  237. return
  238. }
  239. #endif
  240. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  241. let rotation = page.rotation
  242. page.rightRotate()
  243. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  244. }
  245. }
  246. @IBAction func menuItemAction_rotateAllPageLeft(_ sender: Any) {
  247. Task { @MainActor in
  248. #if VERSION_DMG
  249. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  250. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  251. return
  252. }
  253. #endif
  254. var pageItems: [KMThumbnailPageItem] = []
  255. for index in 0 ... self.listView.document.pageCount - 1 {
  256. let page: CPDFPage = self.listView.document.page(at: index)
  257. let rotation = page.rotation
  258. page.leftRotate()
  259. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  260. }
  261. self.rotatePageItems(pageItems: pageItems)
  262. }
  263. }
  264. @IBAction func menuItemAction_rotateAllPageRight(_ sender: Any) {
  265. Task { @MainActor in
  266. #if VERSION_DMG
  267. if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
  268. let _ = KMComparativeTableViewController.show(window: self.view.window!)
  269. return
  270. }
  271. #endif
  272. var pageItems: [KMThumbnailPageItem] = []
  273. for index in 0 ... self.listView.document.pageCount - 1 {
  274. let page : CPDFPage = self.listView.document.page(at: index)
  275. let rotation = page.rotation
  276. page.rightRotate()
  277. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  278. }
  279. self.rotatePageItems(pageItems: pageItems)
  280. }
  281. }
  282. // split screen
  283. @IBAction func menuItemAction_splitScreenVerti(_ sender: Any) {
  284. }
  285. @IBAction func menuItemAction_splitScreenHorti(_ sender: Any) {
  286. }
  287. @IBAction func menuItemAction_splitScreenNo(_ sender: Any) {
  288. }
  289. @IBAction func menuItemAction_view_readMode(_ sender: Any) {
  290. if (self.isReadMode) {
  291. self.closeReadModel()
  292. } else {
  293. self.openReadModel()
  294. }
  295. }
  296. @IBAction func menuItemAction_enterFullScreen(_ sender: Any) {
  297. }
  298. @IBAction func menuItemAction_hiddenLeftSide(_ sender: Any) {
  299. if (self.leftSideViewController.type.methodType != .None) {
  300. self.leftSideViewController.selectType(self.leftSideViewController.type.methodType)
  301. } else {
  302. self.toolbarController.selectItem(KMLeftControlToolbarItemIdentifier)
  303. }
  304. }
  305. @IBAction func menuItemAction_hiddenRightSide(_ sender: Any) {
  306. self.toolbarController.selectItem(KMRightControlToolbarItemIdentifier)
  307. }
  308. @IBAction func menuItemAction_thumai(_ sender: Any) {
  309. self.leftSideViewController.refreshMethodType(methodType: .Thumbnail)
  310. }
  311. @IBAction func menuItemAction_outline(_ sender: Any) {
  312. self.leftSideViewController.refreshMethodType(methodType: .Outline)
  313. }
  314. @IBAction func menuItemAction_bookmark(_ sender: Any) {
  315. self.leftSideViewController.refreshMethodType(methodType: .BookMark)
  316. }
  317. @IBAction func menuItemAction_annotation(_ sender: Any) {
  318. self.leftSideViewController.refreshMethodType(methodType: .Annotation)
  319. }
  320. @IBAction func menuItemAction_search(_ sender: Any) {
  321. self.leftSideViewController.refreshMethodType(methodType: .Search)
  322. }
  323. @IBAction func menuItemAction_topic(_ sender: Any) {
  324. }
  325. @IBAction func menuItemAction_hiddenPageIndicator(_ sender: Any) {
  326. }
  327. }
  328. // MARK: Annotation Menu
  329. extension KMMainViewController {
  330. @IBAction func menuItemAction_highlight(_ sender: Any) {
  331. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarHighlightAnnotationItemIdentifier)
  332. }
  333. @IBAction func menuItemAction_underline(_ sender: Any) {
  334. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarUnderlineAnnotationItemIdentifier)
  335. }
  336. @IBAction func menuItemAction_deleteLine(_ sender: Any) {
  337. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarStrikeOutAnnotationItemIdentifier)
  338. }
  339. @IBAction func menuItemAction_freehand(_ sender: Any) {
  340. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarInkAnnotationItemIdentifier)
  341. }
  342. @IBAction func menuItemAction_text(_ sender: Any) {
  343. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarFreeTextAnnotationItemIdentifier)
  344. }
  345. @IBAction func menuItemAction_note(_ sender: Any) {
  346. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarAnchoredAnnotationItemIdentifier)
  347. }
  348. @IBAction func menuItemAction_squre(_ sender: Any) {
  349. UserDefaults.standard.set(6, forKey: KMToolBarToolPDFShapeStyle)
  350. if (self.listView.annotationType == .square) {
  351. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  352. } else {
  353. if (self.listView.annotationType == .circle || self.listView.annotationType == .line || self.listView.annotationType == .arrow) {
  354. self.listView.annotationType = .square
  355. self.rightSideViewController.annotationProperties.annotationMode = .square
  356. } else {
  357. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  358. }
  359. }
  360. }
  361. @IBAction func menuItemAction_circle(_ sender: Any) {
  362. UserDefaults.standard.set(7, forKey: KMToolBarToolPDFShapeStyle)
  363. if (self.listView.annotationType == .circle) { // 取消
  364. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  365. } else {
  366. if (self.listView.annotationType == .square || self.listView.annotationType == .line || self.listView.annotationType == .arrow) { // 切换
  367. self.listView.annotationType = .circle
  368. self.rightSideViewController.annotationProperties.annotationMode = .circle
  369. } else { // 选中
  370. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  371. }
  372. }
  373. }
  374. @IBAction func menuItemAction_arrow(_ sender: Any) {
  375. UserDefaults.standard.set(5, forKey: KMToolBarToolPDFShapeStyle)
  376. if (self.listView.annotationType == .arrow) { // 取消
  377. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  378. } else { // 选中
  379. if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .line) { // 切换
  380. self.listView.annotationType = .arrow
  381. self.rightSideViewController.annotationProperties.annotationMode = .arrow
  382. } else {
  383. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  384. }
  385. }
  386. }
  387. @IBAction func menuItemAction_line(_ sender: Any) {
  388. UserDefaults.standard.set(4, forKey: KMToolBarToolPDFShapeStyle)
  389. if (self.listView.annotationType == .line) { // 取消
  390. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  391. } else { // 选中
  392. if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .arrow) { // 切换
  393. self.listView.annotationType = .line
  394. self.rightSideViewController.annotationProperties.annotationMode = .line
  395. } else {
  396. self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
  397. }
  398. }
  399. }
  400. // link
  401. @IBAction func menuItemAction_link(_ sender: Any) {
  402. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  403. }
  404. @IBAction func menuItemAction_linkPage(_ sender: Any) {
  405. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
  406. }
  407. @IBAction func menuItemAction_linkHttps(_ sender: Any) {
  408. }
  409. @IBAction func menuItemAction_linkEmail(_ sender: Any) {
  410. }
  411. // stamp
  412. @IBAction func menuItemAction_stamp(_ sender: Any) {
  413. self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
  414. }
  415. @IBAction func menuItemAction_stampStandard(_ sender: Any) {
  416. }
  417. @IBAction func menuItemAction_stampDynamic(_ sender: Any) {
  418. }
  419. @IBAction func menuItemAction_stampCustom(_ sender: Any) {
  420. }
  421. @IBAction func menuItemAction_signure(_ sender: Any) {
  422. self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSignSignatureAnnotationItemIdentifier)
  423. }
  424. @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
  425. self.showOrHideNotes()
  426. }
  427. @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
  428. self.removeAllAnnotations()
  429. }
  430. private func mainMenuUpdateAnnotationStyle(identifier : String) {
  431. if self.toolbarController.toolbarType != .Annatiton {
  432. let item : KMToolBoxItem = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
  433. self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Annatiton, toolbar: item, [])
  434. }
  435. let childitem : KMToolBoxItem = (self.toolbarController.childToolBarView?.toolbarItemFindItemIdentifiers(value: identifier))!
  436. self.toolbarController.mainToolBarView?.delegate?.changeAnnotationModeAction?(item: childitem.clickButton)
  437. }
  438. }
  439. // MARK: goto Menu
  440. extension KMMainViewController {
  441. @IBAction func menuItemAction_nextPage(_ sender: Any) {
  442. if (self.listView.canGoToNextPage()) {
  443. self.listView.goToNextPage(nil)
  444. }
  445. }
  446. @IBAction func menuItemAction_forwardPage(_ sender: Any) {
  447. if (self.listView.canGoToPreviousPage()) {
  448. self.listView.goToPreviousPage(nil)
  449. }
  450. }
  451. @IBAction func menuItemAction_firstPage(_ sender: Any) {
  452. if (self.listView.canGoToFirstPage()) {
  453. self.listView.goToFirstPage(nil)
  454. }
  455. }
  456. @IBAction func menuItemAction_lastPage(_ sender: Any) {
  457. if (self.listView.canGoToLastPage()) {
  458. self.listView.goToLastPage(nil)
  459. }
  460. }
  461. @IBAction func menuItemAction_forward(_ sender: Any) {
  462. if (self.listView.km_canGoForward()) {
  463. self.listView.km_goForward(nil)
  464. }
  465. }
  466. @IBAction func menuItemAction_goback(_ sender: Any) {
  467. if (self.listView.km_canGoBack()) {
  468. self.listView.km_goBack(nil)
  469. }
  470. }
  471. @IBAction func menuItemAction_gotoPage(_ sender: Any) {
  472. let sheet = SKTextFieldSheetController.init(windowNibName: "PageSheet")
  473. var pages : [String] = []
  474. for i in 0 ..< self.listView.document.pageCount {
  475. pages.append("\(i)")
  476. }
  477. sheet.callback = { [weak self] stringValue in
  478. if (stringValue == nil) {
  479. return
  480. }
  481. guard let index = Int(stringValue!) else {
  482. return
  483. }
  484. if (self?.listView == nil) {
  485. return
  486. }
  487. if (index > 0 && index <= self!.listView.document.pageCount) {
  488. self?.listView.go(toPageIndex: index-1, animated: true)
  489. }
  490. }
  491. sheet.showWindow(nil)
  492. sheet.pageBox.addItems(withObjectValues: pages)
  493. sheet.stringValue = "\(self.listView.currentPageIndex+1)"
  494. }
  495. }
  496. // MARK: tool Menu
  497. extension KMMainViewController {
  498. @IBAction func menuItemAction_textTool(_ sender: Any) {
  499. self.toolbarController.selectItem(KMToolbarZoomToSelectionItemIdentifier)
  500. }
  501. @IBAction func menuItemAction_scrolTool(_ sender: Any) {
  502. self.toolbarController.selectItem(KMToolbarMoveToolModeItemIdentifier)
  503. }
  504. @IBAction func menuItemAction_zoomOutTool(_ sender: Any) {
  505. self.toolbarController.selectItem(KMToolbarMagnifyToolModeItemIdentifier)
  506. }
  507. @IBAction func menuItemAction_selectTool(_ sender: Any) {
  508. self.toolbarController.selectItem(KMToolbarSelectToolModeItemIdentifier)
  509. }
  510. @IBAction func menuItemAction_redact(_ sender: Any) {
  511. self.toolbarController.enterRedact()
  512. }
  513. @IBAction func menuItemAction_warkmark(_ sender: Any) {
  514. self.toolbarController.delegate?.clickChildTool?(type: .watermark, index: 0)
  515. }
  516. @IBAction func menuItemAction_background(_ sender: Any) {
  517. self.toolbarController.delegate?.clickChildTool?(type: .background, index: 0)
  518. }
  519. @IBAction func menuItemAction_headerfooter(_ sender: Any) {
  520. self.toolbarController.delegate?.clickChildTool?(type: .headerAndFooter, index: 0)
  521. }
  522. @IBAction func menuItemAction_bates(_ sender: Any) {
  523. self.toolbarController.delegate?.clickChildTool?(type: .bates, index: 0)
  524. }
  525. @IBAction func menuItemAction_batch(_ sender: Any) {
  526. KMBatchWindowController.openFile(self.listView.document?.documentURL, .Batch)
  527. }
  528. }
  529. // MARK: window Menu
  530. extension KMMainViewController {
  531. @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {
  532. (self.myDocument as? KMMainDocument)?.browser.selectPreviousTab()
  533. }
  534. @IBAction func menuItemAction_showNextTagPage(_ sender: Any) {
  535. (self.myDocument as? KMMainDocument)?.browser.selectNextTab()
  536. }
  537. @IBAction func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  538. self.browserWindowController?.openNewWindow(sender)
  539. }
  540. @IBAction func menuItemAction_mergeAllWindow(_ sender: Any) {
  541. ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController)?.mergeAllWindow(sender)
  542. }
  543. @IBAction func menuItemAction_currentWindowName(_ sender: Any) {
  544. }
  545. }
  546. extension KMMainViewController: NSMenuItemValidation, NSMenuDelegate {
  547. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  548. if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
  549. menuItem.title = (self.myDocument?.fileURL!.lastPathComponent)!
  550. return true
  551. }
  552. if (menuItem.action == #selector(menuItemAction_thumai) ||
  553. menuItem.action == #selector(menuItemAction_outline) ||
  554. menuItem.action == #selector(menuItemAction_bookmark) ||
  555. menuItem.action == #selector(menuItemAction_annotation) ||
  556. menuItem.action == #selector(menuItemAction_search)) {
  557. menuItem.state = .off
  558. let type = self.leftSideViewController.type.methodType
  559. if (menuItem.action == #selector(menuItemAction_thumai) && type == .Thumbnail) {
  560. menuItem.state = .on
  561. }
  562. if (menuItem.action == #selector(menuItemAction_outline) && type == .Outline) {
  563. menuItem.state = .on
  564. }
  565. if (menuItem.action == #selector(menuItemAction_bookmark) && type == .BookMark) {
  566. menuItem.state = .on
  567. }
  568. if (menuItem.action == #selector(menuItemAction_annotation) && type == .Annotation) {
  569. menuItem.state = .on
  570. }
  571. if (menuItem.action == #selector(menuItemAction_search) && type == .Search) {
  572. menuItem.state = .on
  573. }
  574. }
  575. if (menuItem.action == #selector(menuItemAction_hiddenLeftSide)) {
  576. if (self.leftPanelOpen) {
  577. menuItem.title = NSLocalizedString("Hide Left Side Panel", comment: "")
  578. } else {
  579. menuItem.title = NSLocalizedString("Show Left Side Panel", comment: "")
  580. }
  581. }
  582. if (menuItem.action == #selector(menuItemAction_hiddenRightSide)) {
  583. if (self.rightPanelIsOpen) {
  584. menuItem.title = NSLocalizedString("Hide Right Side Panel", comment: "")
  585. } else {
  586. menuItem.title = NSLocalizedString("Show Right Side Panel", comment: "")
  587. }
  588. }
  589. if (menuItem.action == #selector(menuItemAction_hiddenAllAnnotation)) {
  590. if (self.listView.hideNotes) {
  591. menuItem.title = NSLocalizedString("Show Notes", comment: "")
  592. } else {
  593. menuItem.title = NSLocalizedString("Hide Notes", comment: "")
  594. }
  595. }
  596. if (menuItem.action == #selector(menuItemAction_showForwardTagPage) ||
  597. menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  598. let browser = self.browserWindowController?.browser
  599. if (browser != nil && (browser is KMBrowser)) {
  600. if (menuItem.action == #selector(menuItemAction_showForwardTagPage)) {
  601. return (browser as! KMBrowser).canSelectPreviousTab()
  602. }
  603. if (menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  604. return (browser as! KMBrowser).canSelectNextTab()
  605. }
  606. }
  607. }
  608. if (menuItem.action == #selector(menuItemAction_mergeAllWindow)) {
  609. if let _browserWindowC = ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController) {
  610. return _browserWindowC.canMergeAllWindow()
  611. }
  612. }
  613. if (menuItem.action == #selector(menuItemAction_nextPage) ||
  614. menuItem.action == #selector(menuItemAction_forwardPage) ||
  615. menuItem.action == #selector(menuItemAction_firstPage) ||
  616. menuItem.action == #selector(menuItemAction_lastPage) ||
  617. menuItem.action == #selector(menuItemAction_forward) ||
  618. menuItem.action == #selector(menuItemAction_goback)) {
  619. if (menuItem.action == #selector(menuItemAction_nextPage)) {
  620. if self.listView.isEditing() && self.listView.isEditable() {
  621. return false
  622. }
  623. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage())
  624. }
  625. if (menuItem.action == #selector(menuItemAction_forwardPage)) {
  626. if self.listView.isEditing() && self.listView.isEditable() {
  627. return false
  628. }
  629. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage())
  630. }
  631. if (menuItem.action == #selector(menuItemAction_firstPage)) {
  632. return self.listView.canGoToFirstPage()
  633. }
  634. if (menuItem.action == #selector(menuItemAction_lastPage)) {
  635. return self.listView.canGoToLastPage()
  636. }
  637. if (menuItem.action == #selector(menuItemAction_forward)) {
  638. return self.listView.km_canGoForward()
  639. }
  640. if (menuItem.action == #selector(menuItemAction_goback)) {
  641. return self.listView.km_canGoBack()
  642. }
  643. }
  644. return true
  645. }
  646. }