KMMainViewController+MenuAction.swift 28 KB

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