KMMainViewController+MenuAction.swift 29 KB

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