KMMainViewController+MenuAction.swift 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  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 : KMToolbarItemView = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
  435. self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Annatiton, toolbar: item, [])
  436. }
  437. let childitem : KMToolbarItemView = (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: KMSystemToolMenuProtocol {
  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.clickItem(KMDocumentRedactToolbarItemIdentifier)
  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. func compression(_ sender: Any?) {
  531. self.toolbarController.delegate?.clickChildTool?(type: .compress, index: 0)
  532. }
  533. func merge(_ sender: Any?) {
  534. self.toolbarController.delegate?.clickChildTool?(type: .merge, index: 0)
  535. }
  536. func convert(_ sender: Any?) {
  537. self.toolbarController.delegate?.clickChildTool?(type: .word, index: 0)
  538. }
  539. func imageToPDF(_ sender: Any?) {
  540. KMApp.ShowImageToPDFWindow()
  541. }
  542. func extractImage(_ sender: Any?) {
  543. self.extractImageAction(num: 1)
  544. }
  545. func security(_ sender: Any?) {
  546. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 1)
  547. }
  548. func decryption(_ sender: Any?) {
  549. self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 2)
  550. }
  551. func cropAll(_ sender: Any?) {
  552. // NSRect rect[2] = {NSIntegralRect([pdfView currentSelectionRect]), NSZeroRect};
  553. // NSPointerArray *rectArray = [NSPointerArray rectPointerArray];
  554. // BOOL emptySelection = NSIsEmptyRect(rect[0]);
  555. //
  556. // if (emptySelection) {
  557. // NSInteger i, j, count = [[pdfView document] pageCount];
  558. // rect[0] = rect[1] = NSZeroRect;
  559. //
  560. // if (count == 0)
  561. // return;
  562. //
  563. // [self beginProgressSheetWithMessage:[NSLocalizedString(@"Cropping Pages", @"Message for progress sheet") stringByAppendingEllipsis] maxValue:MIN(18, count)];
  564. //
  565. // if (count == 1) {
  566. // rect[0] = [[[pdfView document] pageAtIndex:0] foregroundBox];
  567. // [self incrementProgressSheet];
  568. // } else if (count < 19) {
  569. // for (i = 0; i < count; i++) {
  570. // rect[i % 2] = NSUnionRect(rect[i % 2], [[[pdfView document] pageAtIndex:i] foregroundBox]);
  571. // [self incrementProgressSheet];
  572. // }
  573. // } else {
  574. // NSInteger start[3] = {1, (count - 5) / 2, count - 6};
  575. // for (j = 0; j < 3; j++) {
  576. // for (i = start[j]; i < start[j] + 6; i++) {
  577. // rect[i % 2] = NSUnionRect(rect[i % 2], [[[pdfView document] pageAtIndex:i] foregroundBox]);
  578. // [self incrementProgressSheet];
  579. // }
  580. // }
  581. // }
  582. // CGFloat w = fmax(NSWidth(rect[0]), NSWidth(rect[1]));
  583. // CGFloat h = fmax(NSHeight(rect[0]), NSHeight(rect[1]));
  584. // for (j = 0; j < 2; j++)
  585. // rect[j] = NSMakeRect(floor(NSMidX(rect[j]) - 0.5 * w), floor(NSMidY(rect[j]) - 0.5 * h), w, h);
  586. // [rectArray addPointer:rect];
  587. // [rectArray addPointer:rect + 1];
  588. // } else {
  589. // [rectArray addPointer:rect];
  590. // }
  591. //
  592. // [self cropPagesToRects:rectArray];
  593. // [pdfView setCurrentSelectionRect:NSZeroRect];
  594. self.cropAllPage()
  595. }
  596. func crop(_ sender: Any?) {
  597. self.cropCurrentPage()
  598. }
  599. func autoCropAll(_ sender: Any?) {
  600. #warning("暂时这么处理,后续调整")
  601. self.cropAllPage()
  602. }
  603. func smartAutoCropAll(_ sender: Any?) {
  604. #warning("暂时这么处理,后续调整")
  605. self.cropAllPage()
  606. }
  607. func cropOptionsModel(_ sender: Any?) {
  608. KMPrint("cropOptionsModel ...")
  609. }
  610. func selectToolModel(_ sender: Any?) {
  611. self.toolbarController.clickItem(KMToolbarSelectToolModeItemIdentifier)
  612. }
  613. func takeSnapshot(_ sender: Any?) {
  614. self.listView.takeSnapshot(sender)
  615. }
  616. func takeSnapshotSelectContent(_ sender: Any?) {
  617. self.listView.takeSnapshotSelectContent(sender)
  618. }
  619. func changeAnnotationMode(_ sender: Any?) {
  620. if let data = sender as? NSMenuItem {
  621. self.changeAnnotationMode_itemAction(sender: data)
  622. }
  623. }
  624. func addWatermark(_ sender: Any?) {
  625. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  626. if item == nil {
  627. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  628. }
  629. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  630. }
  631. func removeWatermark(_ sender: Any?) {
  632. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  633. if item == nil {
  634. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  635. }
  636. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  637. }
  638. func batchAddWatermark(_ sender: Any?) {
  639. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  640. if item == nil {
  641. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  642. }
  643. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  644. }
  645. func batchRemoveWatermark(_ sender: Any?) {
  646. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  647. if item == nil {
  648. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  649. }
  650. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
  651. }
  652. func templateWatermark(_ sender: Any?) {
  653. var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
  654. if item == nil {
  655. item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
  656. }
  657. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  658. }
  659. func addBackground(_ sender: Any?) {
  660. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  661. if item == nil {
  662. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  663. }
  664. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  665. }
  666. func removeBackground(_ sender: Any?) {
  667. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  668. if item == nil {
  669. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  670. }
  671. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  672. }
  673. func batchAddBackground(_ sender: Any?) {
  674. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  675. if item == nil {
  676. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  677. }
  678. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  679. }
  680. func batchRemoveBackground(_ sender: Any?) {
  681. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  682. if item == nil {
  683. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  684. }
  685. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil) }
  686. func templateBackground(_ sender: Any?) {
  687. var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
  688. if item == nil {
  689. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
  690. }
  691. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  692. }
  693. func addHeaderFooter(_ sender: Any?) {
  694. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  695. if item == nil {
  696. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  697. }
  698. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  699. }
  700. func removeHeaderFooter(_ sender: Any?) {
  701. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  702. if item == nil {
  703. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  704. }
  705. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  706. }
  707. func batchAddHeaderFooter(_ sender: Any?) {
  708. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  709. if item == nil {
  710. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  711. }
  712. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  713. }
  714. func batchRemoveHeaderFooter(_ sender: Any?) {
  715. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  716. if item == nil {
  717. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  718. }
  719. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
  720. }
  721. func templateHeaderFooter(_ sender: Any?) {
  722. var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
  723. if item == nil {
  724. item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
  725. }
  726. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  727. }
  728. func addHeaderFooterBates(_ sender: Any?) {
  729. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  730. if item == nil {
  731. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  732. }
  733. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
  734. }
  735. func removeHeaderFooterBates(_ sender: Any?) {
  736. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  737. if item == nil {
  738. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  739. }
  740. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
  741. }
  742. func batchAddBates(_ sender: Any?) {
  743. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  744. if item == nil {
  745. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  746. }
  747. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
  748. }
  749. func batchRemoveBates(_ sender: Any?) {
  750. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  751. if item == nil {
  752. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  753. }
  754. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
  755. }
  756. func templateBates(_ sender: Any?) {
  757. var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
  758. if item == nil {
  759. item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
  760. }
  761. self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
  762. }
  763. func togglePoster(_ sender: Any?) {
  764. KMPrintWindowController.showNewPrintWindowControll(inputData: self.listView.document?.documentURL, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .poster)
  765. }
  766. func toggleMultiple(_ sender: Any?) {
  767. KMPrintWindowController.showNewPrintWindowControll(inputData: self.listView.document?.documentURL, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .multipage)
  768. }
  769. func toggleBooklet(_ sender: Any?) {
  770. KMPrintWindowController.showNewPrintWindowControll(inputData: self.listView.document?.documentURL, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .pamphlet)
  771. }
  772. func rotateLeft(_ sender: Any?) {
  773. Task { @MainActor in
  774. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  775. let rotation = page.rotation
  776. page.leftRotate()
  777. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  778. }
  779. }
  780. func rotateRight(_ sender: Any?) {
  781. Task { @MainActor in
  782. let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
  783. let rotation = page.rotation
  784. page.rightRotate()
  785. self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
  786. }
  787. }
  788. func rotateAllLeft(_ sender: Any?) {
  789. Task { @MainActor in
  790. var pageItems: [KMThumbnailPageItem] = []
  791. for index in 0 ... self.listView.document.pageCount - 1 {
  792. let page: CPDFPage = self.listView.document.page(at: index)
  793. let rotation = page.rotation
  794. page.leftRotate()
  795. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  796. }
  797. self.rotatePageItems(pageItems: pageItems)
  798. }
  799. }
  800. func rotateAllRight(_ sender: Any?) {
  801. Task { @MainActor in
  802. var pageItems: [KMThumbnailPageItem] = []
  803. for index in 0 ... self.listView.document.pageCount - 1 {
  804. let page: CPDFPage = self.listView.document.page(at: index)
  805. let rotation = page.rotation
  806. page.leftRotate()
  807. pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
  808. }
  809. self.rotatePageItems(pageItems: pageItems)
  810. }
  811. }
  812. func autoSelectContent(_ sender: Any?) {
  813. self.listView.autoSelectContent(sender)
  814. }
  815. }
  816. // MARK: window Menu
  817. extension KMMainViewController {
  818. @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {
  819. (self.myDocument as? KMMainDocument)?.browser.selectPreviousTab()
  820. }
  821. @IBAction func menuItemAction_showNextTagPage(_ sender: Any) {
  822. (self.myDocument as? KMMainDocument)?.browser.selectNextTab()
  823. }
  824. @IBAction func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
  825. self.browserWindowController?.openNewWindow(sender)
  826. }
  827. @IBAction func menuItemAction_mergeAllWindow(_ sender: Any) {
  828. ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController)?.mergeAllWindow(sender)
  829. }
  830. @IBAction func menuItemAction_currentWindowName(_ sender: Any) {
  831. }
  832. }
  833. extension KMMainViewController: NSMenuItemValidation, NSMenuDelegate {
  834. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  835. if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
  836. menuItem.title = (self.myDocument?.fileURL!.lastPathComponent)!
  837. return true
  838. }
  839. if (menuItem.action == #selector(menuItemAction_thumai) ||
  840. menuItem.action == #selector(menuItemAction_outline) ||
  841. menuItem.action == #selector(menuItemAction_bookmark) ||
  842. menuItem.action == #selector(menuItemAction_annotation) ||
  843. menuItem.action == #selector(menuItemAction_search)) {
  844. menuItem.state = .off
  845. let type = self.leftSideViewController.type.methodType
  846. if (menuItem.action == #selector(menuItemAction_thumai) && type == .Thumbnail) {
  847. menuItem.state = .on
  848. }
  849. if (menuItem.action == #selector(menuItemAction_outline) && type == .Outline) {
  850. menuItem.state = .on
  851. }
  852. if (menuItem.action == #selector(menuItemAction_bookmark) && type == .BookMark) {
  853. menuItem.state = .on
  854. }
  855. if (menuItem.action == #selector(menuItemAction_annotation) && type == .Annotation) {
  856. menuItem.state = .on
  857. }
  858. if (menuItem.action == #selector(menuItemAction_search) && type == .Search) {
  859. menuItem.state = .on
  860. }
  861. }
  862. if (menuItem.action == #selector(menuItemAction_hiddenLeftSide)) {
  863. if (self.leftPanelOpen) {
  864. menuItem.title = NSLocalizedString("Hide Left Side Panel", comment: "")
  865. } else {
  866. menuItem.title = NSLocalizedString("Show Left Side Panel", comment: "")
  867. }
  868. }
  869. if (menuItem.action == #selector(menuItemAction_hiddenRightSide)) {
  870. if (self.rightPanelIsOpen) {
  871. menuItem.title = NSLocalizedString("Hide Right Side Panel", comment: "")
  872. } else {
  873. menuItem.title = NSLocalizedString("Show Right Side Panel", comment: "")
  874. }
  875. }
  876. if (menuItem.action == #selector(menuItemAction_hiddenAllAnnotation)) {
  877. if (self.listView.hideNotes) {
  878. menuItem.title = NSLocalizedString("Show Notes", comment: "")
  879. } else {
  880. menuItem.title = NSLocalizedString("Hide Notes", comment: "")
  881. }
  882. }
  883. if (menuItem.action == #selector(menuItemAction_showForwardTagPage) ||
  884. menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  885. let browser = self.browserWindowController?.browser
  886. if (browser != nil && (browser is KMBrowser)) {
  887. if (menuItem.action == #selector(menuItemAction_showForwardTagPage)) {
  888. return (browser as! KMBrowser).canSelectPreviousTab()
  889. }
  890. if (menuItem.action == #selector(menuItemAction_showNextTagPage)) {
  891. return (browser as! KMBrowser).canSelectNextTab()
  892. }
  893. }
  894. }
  895. if (menuItem.action == #selector(menuItemAction_mergeAllWindow)) {
  896. if let _browserWindowC = ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController) {
  897. return _browserWindowC.canMergeAllWindow()
  898. }
  899. }
  900. if (menuItem.action == #selector(menuItemAction_nextPage) ||
  901. menuItem.action == #selector(menuItemAction_forwardPage) ||
  902. menuItem.action == #selector(menuItemAction_firstPage) ||
  903. menuItem.action == #selector(menuItemAction_lastPage) ||
  904. menuItem.action == #selector(menuItemAction_forward) ||
  905. menuItem.action == #selector(menuItemAction_goback)) {
  906. if (menuItem.action == #selector(menuItemAction_nextPage)) {
  907. if self.listView.isEditing() && self.listView.isEditable() {
  908. return false
  909. }
  910. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage())
  911. }
  912. if (menuItem.action == #selector(menuItemAction_forwardPage)) {
  913. if self.listView.isEditing() && self.listView.isEditable() {
  914. return false
  915. }
  916. return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage())
  917. }
  918. if (menuItem.action == #selector(menuItemAction_firstPage)) {
  919. return self.listView.canGoToFirstPage()
  920. }
  921. if (menuItem.action == #selector(menuItemAction_lastPage)) {
  922. return self.listView.canGoToLastPage()
  923. }
  924. if (menuItem.action == #selector(menuItemAction_forward)) {
  925. return self.listView.km_canGoForward()
  926. }
  927. if (menuItem.action == #selector(menuItemAction_goback)) {
  928. return self.listView.km_canGoBack()
  929. }
  930. }
  931. if menuItem.action == #selector(changeAnnotationMode) || menuItem.action == #selector(changeAnnotationMode_itemAction) {
  932. // if ([[menuItem menu] numberOfItems] > ANNOTATION_MODE_COUNT)
  933. // [menuItem setState:[self toolMode] == SKNoteToolMode && [self annotationMode] == (SKNoteType)[menuItem tag] ? NSOnState : NSOffState];
  934. // else
  935. // [menuItem setState:[self annotationMode] == (SKNoteType)[menuItem tag] ? NSOnState : NSOffState];
  936. if self.listView.annotationType.rawValue == menuItem.tag {
  937. menuItem.state = .on
  938. } else {
  939. menuItem.state = .off
  940. }
  941. return true
  942. }
  943. guard let action = menuItem.action else {
  944. return false
  945. }
  946. if KMSystemMenu.isToolSelector(sel: action) {
  947. if action == KMSystemMenu.Tool.autoSelectContentSelector {
  948. let toolMode = self.listView?.toolMode ?? .none
  949. return toolMode == .selectToolMode
  950. }
  951. }
  952. return true
  953. }
  954. }