1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228 |
- //
- // KMMainViewController+MenuAction.swift
- // PDF Master
- //
- // Created by tangchao on 2023/2/19.
- //
- import Foundation
- // MARK: File Menu
- extension KMMainViewController {
- @IBAction func menuItemClick_mergePDF(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .merge, index: 0)
- }
-
- @IBAction func menuItemClick_Compress(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .compress, index: 0)
- }
-
- @IBAction func menuItemClick_Convert(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_ConvertToWord(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .word, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToExcel(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .excel, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToPPT(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .ppt, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToRTF(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .rtf, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToHTML(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .html, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToText(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .conversion_text, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToCSV(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .csv, index: 0)
- }
-
- @IBAction func menuItemAction_ConvertToImage(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .conversion_image, index: 0)
- }
-
- @IBAction func menuItemClick_SettingPassword(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 1)
- }
-
- @IBAction func menuItemClick_RemovePassword(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 2)
- }
-
- @IBAction func menuItemAction_closeWindow(_ sender: Any) {
- self.view.window?.close()
- }
-
- @IBAction func menuItemAction_closeAllWindows(_ sender: Any) {
- for window in NSApp.windows {
- window.close()
- }
- }
-
- @IBAction func menuItemAction_closeTagPage(_ sender: Any) {
- self.browserWindowController?.browser.closeTab()
- }
-
- @IBAction func menuItemAction_showInFinder(_ sender: Any) {
- NSWorkspace.shared.activateFileViewerSelecting([self.listView.document.documentURL])
- }
-
- @IBAction func menuItemAction_property(_ sender: Any) {
- KMInfoWindowController.shared.showWindow(sender)
- }
-
- @IBAction func menuItemAction_print(_ sender: Any) {
- self.showPrintWindow()
- }
- }
- extension KMMainViewController: KMSystemFileMenuProtocol {
- @IBAction func menuItemClick_saveAsFlattenedPDF(_ sender: Any) {
- Task { @MainActor in
- #if VERSION_DMG
- if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
- let _ = KMComparativeTableViewController.show(window: self.view.window!)
- return
- }
- #endif
- if await (KMLightMemberManager.manager.canPayFunction() == false) {
- let _ = KMSubscribeWaterMarkWindowController.show(window: self.view.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
- if (isClose) {
- return
- }
- if (isSubscribeSuccess) {
- self.saveAsFlattenedPDFAction()
- return
- }
- if (isWaterMarkExport) {
- self.saveAsFlattenedPDFAction(limit: true)
- return
- }
- }
- return
- }
- self.saveAsFlattenedPDFAction()
- }
- }
-
- func saveAsFlattenedPDFAction(limit: Bool = false) {
- DispatchQueue.main.async {
- NSPanel.savePanel(self.view.window!, true) { panel in
- panel.nameFieldStringValue = self.listView.document.documentURL.deletingPathExtension().lastPathComponent + "_flatten" + ".pdf"
- } completion: { response, url, isOpen in
- if (response == .cancel) {
- return
- }
-
- var result = false
- if (limit) {
- let data = KMTools.saveWatermarkDocumentForFlatten(document: self.listView.document, to: url!)
- result = data != nil
- } else {
- result = self.listView.document.writeFlatten(to: url!)
- }
- if (!result) {
- return
- }
-
- if (isOpen) {
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: url!, display: true) { _, _, _ in
-
- }
- } else {
- NSWorkspace.shared.activateFileViewerSelecting([url!])
- }
- }
- }
- }
- }
- // MARK: Edit Menu
- @objc protocol KMEditMenuProtocol: NSObjectProtocol {
- @objc optional func undo(_ sender: Any)
- @objc optional func redo(_ sender: Any)
-
- @objc optional func cut(_ sender: Any)
- @objc optional func copy(_ sender: Any)
- @objc optional func paste(_ sender: Any)
- @objc optional func delete(_ sender: Any)
- }
- extension KMMainViewController: KMEditMenuProtocol {
- @IBAction func menuItemAction_find(_ sender: Any) {
- if (self.leftSideViewController.isShowPanel) {
- self.toolbarController.cancelSelected(KMLeftControlToolbarItemIdentifier)
- self.toolbarController.toolbarType = .None
- self.leftSideViewController.showPanelView(show: false)
- }
- // else {
- let isSearch = self.leftSideViewController.type.methodType == .Search
- self.leftSideViewController.refreshMethodType(methodType: .Search)
- if (isSearch) { // 关闭
- self.view.window?.makeFirstResponder(self.listView)
- }
- // }
- }
- }
- // MARK: View Menu
- extension KMMainViewController {
-
- // scale
-
- @IBAction func menuItemAction_adjustWidth(_ sender: Any) {
- self.selectZoom(.width)
- }
- @IBAction func menuItemAction_adjustPage(_ sender: Any) {
- self.selectZoom(.fit)
- }
- @IBAction func menuItemAction_size(_ sender: Any) {
- self.selectZoom(.actualSize)
- }
- @IBAction func menuItemAction_zoomOut(_ sender: Any) {
- if (self.listView.canZoomOut) {
- self.listView.zoomOut(nil)
- }
- }
- @IBAction func menuItemAction_zoomIn(_ sender: Any) {
- if (self.listView.canZoomIn) {
- self.listView.zoomIn(nil)
- }
- }
-
- // page show
-
- @IBAction func menuItemAction_singlePage(_ sender: Any) {
- self.selectDisplay(display: .singlePage)
- }
- @IBAction func menuItemAction_singlePageContinue(_ sender: Any) {
- self.selectDisplay(display: .singlePageContinuous)
- }
- @IBAction func menuItemAction_doublePage(_ sender: Any) {
- self.selectDisplay(display: .twoUp)
- }
- @IBAction func menuItemAction_doublePageContinue(_ sender: Any) {
- self.selectDisplay(display: .twoUpContinuous)
- }
- @IBAction func menuItemAction_bookMode(_ sender: Any) {
- self.selectDisplay(display: .bookMode)
- }
-
- @IBAction func menuItemAction_readMode(_ sender: Any) {
- if (self.isReadMode) {
- self.closeReadModel()
- } else {
- self.openReadModel()
- }
- }
- @IBAction func menuItemAction_showSplitPage(_ sender: Any) {
- self.listView?.displaysPageBreaks = !(self.listView?.displaysPageBreaks ?? false)
- self.listView.layoutDocumentView()
- }
- @IBAction func menuItemAction_autoScrol(_ sender: Any) {
- }
- @IBAction func menuItemAction_autoScrolSetting(_ sender: Any) {
- }
-
- // rotate
-
- @IBAction func menuItemAction_rotateLeft(_ sender: Any) {
- Task { @MainActor in
- #if VERSION_DMG
- if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
- let _ = KMComparativeTableViewController.show(window: self.view.window!)
- return
- }
- #endif
- let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
- let rotation = page.rotation
- page.leftRotate()
-
- self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
- }
- }
-
- func rotatePageItems(pageItems: [KMThumbnailPageItem]) {
- let tempPageItems = pageItems
- for pageItem in tempPageItems {
- pageItem.page.rotation = pageItem.rotate
- }
-
- self.listView.layoutDocumentView()
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView.document)
-
- self.listView.undoManager?.registerUndo(withTarget: self) { [unowned self] targetType in
- var tempPageItems: [KMThumbnailPageItem] = []
- for pageItem in pageItems {
- let item = KMThumbnailPageItem(page: pageItem.page, rotate: pageItem.oldRotate, oldRotate: pageItem.rotate)
- tempPageItems.append(item)
- }
- self.rotatePageItems(pageItems: tempPageItems)
- }
- }
- @IBAction func menuItemAction_rotateRight(_ sender: Any) {
- Task { @MainActor in
- #if VERSION_DMG
- if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
- let _ = KMComparativeTableViewController.show(window: self.view.window!)
- return
- }
- #endif
-
- let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
- let rotation = page.rotation
- page.rightRotate()
-
- self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
- }
- }
- @IBAction func menuItemAction_rotateAllPageLeft(_ sender: Any) {
- Task { @MainActor in
- #if VERSION_DMG
- if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
- let _ = KMComparativeTableViewController.show(window: self.view.window!)
- return
- }
- #endif
-
- var pageItems: [KMThumbnailPageItem] = []
- for index in 0 ... self.listView.document.pageCount - 1 {
- let page: CPDFPage = self.listView.document.page(at: index)
- let rotation = page.rotation
- page.leftRotate()
- pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
- }
- self.rotatePageItems(pageItems: pageItems)
- }
- }
- @IBAction func menuItemAction_rotateAllPageRight(_ sender: Any) {
- Task { @MainActor in
- #if VERSION_DMG
- if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
- let _ = KMComparativeTableViewController.show(window: self.view.window!)
- return
- }
- #endif
-
- var pageItems: [KMThumbnailPageItem] = []
- for index in 0 ... self.listView.document.pageCount - 1 {
- let page : CPDFPage = self.listView.document.page(at: index)
- let rotation = page.rotation
- page.rightRotate()
- pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
- }
- self.rotatePageItems(pageItems: pageItems)
- }
- }
-
- // split screen
-
- @IBAction func menuItemAction_splitScreenVerti(_ sender: Any) {
- }
- @IBAction func menuItemAction_splitScreenHorti(_ sender: Any) {
- }
- @IBAction func menuItemAction_splitScreenNo(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_view_readMode(_ sender: Any) {
- if (self.isReadMode) {
- self.closeReadModel()
- } else {
- self.openReadModel()
- }
- }
- @IBAction func menuItemAction_enterFullScreen(_ sender: Any) {
- }
- @IBAction func menuItemAction_hiddenLeftSide(_ sender: Any) {
- if (self.leftSideViewController.type.methodType != .None) {
- self.leftSideViewController.selectType(self.leftSideViewController.type.methodType)
- } else {
- self.toolbarController.selectItem(KMLeftControlToolbarItemIdentifier)
- }
- }
-
- @IBAction func menuItemAction_hiddenRightSide(_ sender: Any) {
- self.toolbarController.selectItem(KMRightControlToolbarItemIdentifier)
- }
-
- @IBAction func menuItemAction_thumai(_ sender: Any) {
- self.leftSideViewController.refreshMethodType(methodType: .Thumbnail)
- }
- @IBAction func menuItemAction_outline(_ sender: Any) {
- self.leftSideViewController.refreshMethodType(methodType: .Outline)
- }
- @IBAction func menuItemAction_bookmark(_ sender: Any) {
- self.leftSideViewController.refreshMethodType(methodType: .BookMark)
- }
-
- @IBAction func menuItemAction_annotation(_ sender: Any) {
- self.leftSideViewController.refreshMethodType(methodType: .Annotation)
- }
- @IBAction func menuItemAction_search(_ sender: Any) {
- self.leftSideViewController.refreshMethodType(methodType: .Search)
- }
- @IBAction func menuItemAction_topic(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_hiddenPageIndicator(_ sender: Any) {
-
- }
- }
- // MARK: Annotation Menu
- extension KMMainViewController {
- @IBAction func menuItemAction_highlight(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarHighlightAnnotationItemIdentifier)
- }
- @IBAction func menuItemAction_underline(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarUnderlineAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_deleteLine(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarStrikeOutAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_freehand(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarInkAnnotationItemIdentifier)
- }
- @IBAction func menuItemAction_text(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarFreeTextAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_note(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarAnchoredAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_squre(_ sender: Any) {
- UserDefaults.standard.set(6, forKey: KMToolBarToolPDFShapeStyle)
- if (self.listView.annotationType == .square) {
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- } else {
- if (self.listView.annotationType == .circle || self.listView.annotationType == .line || self.listView.annotationType == .arrow) {
- self.listView.annotationType = .square
- self.rightSideViewController.annotationProperties.annotationMode = .square
- } else {
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- }
- }
- }
- @IBAction func menuItemAction_circle(_ sender: Any) {
- UserDefaults.standard.set(7, forKey: KMToolBarToolPDFShapeStyle)
- if (self.listView.annotationType == .circle) { // 取消
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- } else {
- if (self.listView.annotationType == .square || self.listView.annotationType == .line || self.listView.annotationType == .arrow) { // 切换
- self.listView.annotationType = .circle
- self.rightSideViewController.annotationProperties.annotationMode = .circle
- } else { // 选中
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- }
- }
- }
-
- @IBAction func menuItemAction_arrow(_ sender: Any) {
- UserDefaults.standard.set(5, forKey: KMToolBarToolPDFShapeStyle)
- if (self.listView.annotationType == .arrow) { // 取消
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- } else { // 选中
- if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .line) { // 切换
- self.listView.annotationType = .arrow
- self.rightSideViewController.annotationProperties.annotationMode = .arrow
- } else {
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- }
- }
- }
-
- @IBAction func menuItemAction_line(_ sender: Any) {
- UserDefaults.standard.set(4, forKey: KMToolBarToolPDFShapeStyle)
- if (self.listView.annotationType == .line) { // 取消
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- } else { // 选中
- if (self.listView.annotationType == .square || self.listView.annotationType == .circle || self.listView.annotationType == .arrow) { // 切换
- self.listView.annotationType = .line
- self.rightSideViewController.annotationProperties.annotationMode = .line
- } else {
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- }
- }
- }
- // link
-
- @IBAction func menuItemAction_link(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_linkPage(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_linkHttps(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_linkEmail(_ sender: Any) {
- }
-
- // stamp
-
- @IBAction func menuItemAction_stamp(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
- }
-
- @IBAction func menuItemAction_stampStandard(_ sender: Any) {
-
- }
-
- @IBAction func menuItemAction_stampDynamic(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_stampCustom(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_signure(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSignSignatureAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_hiddenAllAnnotation(_ sender: Any) {
- self.showOrHideNotes()
- }
-
- @IBAction func menuItemAction_clearAllAnnotation(_ sender: Any) {
- self.removeAllAnnotations()
- }
-
- private func mainMenuUpdateAnnotationStyle(identifier : String) {
- if self.toolbarController.toolbarType != .Annatiton {
- let item : KMToolbarItemView = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
- self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Annatiton, toolbar: item, [])
- }
- let childitem : KMToolbarItemView = (self.toolbarController.childToolBarView?.toolbarItemFindItemIdentifiers(value: identifier))!
- self.toolbarController.mainToolBarView?.delegate?.changeAnnotationModeAction?(item: childitem.clickButton)
- }
- }
- extension KMMainViewController: KMSystemPDFMenuProtocol {
- func changeDisplayMode(_ sender: Any?) {
- guard let item = sender as? NSMenuItem else {
- NSSound.beep()
- return
- }
- let mode = item.tag
- if mode == 0 {
- self.selectDisplay(display: .singlePage)
- } else if mode == 1 {
- self.selectDisplay(display: .singlePageContinuous)
- } else if mode == 2 {
- self.selectDisplay(display: .twoUp)
- } else if mode == 3 {
- self.selectDisplay(display: .twoUpContinuous)
- }
- }
-
- func toggleDisplayAsBook(_ sender: Any?) {
- self.selectDisplay(display: .bookMode)
- }
- }
- // MARK: goto Menu
- extension KMMainViewController {
- @IBAction func menuItemAction_nextPage(_ sender: Any) {
- if (self.listView.canGoToNextPage()) {
- self.listView.goToNextPage(nil)
- }
- }
-
- @IBAction func menuItemAction_forwardPage(_ sender: Any) {
- if (self.listView.canGoToPreviousPage()) {
- self.listView.goToPreviousPage(nil)
- }
- }
-
- @IBAction func menuItemAction_firstPage(_ sender: Any) {
- if (self.listView.canGoToFirstPage()) {
- self.listView.goToFirstPage(nil)
- }
- }
-
- @IBAction func menuItemAction_lastPage(_ sender: Any) {
- if (self.listView.canGoToLastPage()) {
- self.listView.goToLastPage(nil)
- }
- }
-
- @IBAction func menuItemAction_forward(_ sender: Any) {
- if (self.listView.km_canGoForward()) {
- self.listView.km_goForward(nil)
- }
- }
-
- @IBAction func menuItemAction_goback(_ sender: Any) {
- if (self.listView.km_canGoBack()) {
- self.listView.km_goBack(nil)
- }
- }
-
- @IBAction func menuItemAction_gotoPage(_ sender: Any) {
- let sheet = KMTextFieldSheetController.init(windowNibName: "PageSheet")
- var pages : [String] = []
- for i in 0 ..< self.listView.document.pageCount {
- pages.append("\(i)")
- }
- sheet.callback = { [weak self] stringValue in
- if (stringValue == nil) {
- return
- }
- guard let index = Int(stringValue) else {
- return
- }
- if (self?.listView == nil) {
- return
- }
- if (index > 0 && index <= self!.listView.document.pageCount) {
- self?.listView.go(toPageIndex: index-1, animated: true)
- }
- }
- sheet.showWindow(nil)
- sheet.pageBox.addItems(withObjectValues: pages)
- sheet.stringValue = "\(self.listView.currentPageIndex+1)"
- }
-
- @IBAction func goToMarkedPage(_ sender: Any?) {
- guard let pdfDoc = self.listView.document, pdfDoc.isLocked == false && pdfDoc.pageCount > 0 else {
- NSSound.beep()
- return
- }
- guard let currentPageIndex = self.listView.currentPage()?.pageIndex() else {
- NSSound.beep()
- return
- }
- // if (markedPageIndex == NSNotFound || [pdfDoc isLocked] || [pdfDoc pageCount] == 0) {
- // NSBeep();
- // } else if (beforeMarkedPageIndex != NSNotFound) {
- if self.beforeMarkedPageIndex != NSNotFound {
- self.listView.goToPage(at: min(UInt(self.beforeMarkedPageIndex), pdfDoc.pageCount-1), point: self.beforeMarkedPagePoint)
- } else if (currentPageIndex != self.markedPageIndex) {
- // NSUInteger lastPageIndex = [pdfView currentPageIndexAndPoint:&beforeMarkedPagePoint rotated:NULL];
- let lastPageIndex = self.listView.currentPageIndexAndPoint(&self.beforeMarkedPagePoint, rotated: nil)
- self.listView.goToPage(at: min(UInt(self.markedPageIndex), pdfDoc.pageCount-1), point: self.markedPagePoint)
- self.beforeMarkedPageIndex = Int(lastPageIndex)
- }
- }
- @IBAction func markPage(_ sender: Any?) {
- self.markedPageIndex = Int(self.listView.currentPageIndexAndPoint(&self.markedPagePoint, rotated: nil))
- self.beforeMarkedPageIndex = NSNotFound
- }
- }
- // MARK: tool Menu
- extension KMMainViewController: KMSystemToolMenuProtocol {
- func getInfo(_ sender: Any?) {
- KMInfoWindowController.shared.showWindow(sender)
- }
-
- @IBAction func menuItemAction_textTool(_ sender: Any) {
- self.toolbarController.selectItem(KMToolbarZoomToSelectionItemIdentifier)
- }
-
- @IBAction func menuItemAction_scrolTool(_ sender: Any) {
- self.toolbarController.selectItem(KMToolbarMoveToolModeItemIdentifier)
- }
-
- @IBAction func menuItemAction_zoomOutTool(_ sender: Any) {
- self.toolbarController.selectItem(KMToolbarMagnifyToolModeItemIdentifier)
- }
-
- @IBAction func menuItemAction_selectTool(_ sender: Any) {
- self.toolbarController.selectItem(KMToolbarSelectToolModeItemIdentifier)
- }
-
- func changeToolMode(_ sender: Any?) {
- let isSelected = self.toolbarController.findItem(KMToolbarHighlightAnnotationItemIdentifier)?.isSelected ?? false
- if isSelected == false {
- self.toolbarController.selectItem(KMToolbarHighlightAnnotationItemIdentifier)
- }
- }
-
- @IBAction func menuItemAction_redact(_ sender: Any) {
- self.toolbarController.clickItem(KMDocumentRedactToolbarItemIdentifier)
- }
-
- @IBAction func menuItemAction_warkmark(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .watermark, index: 0)
- }
-
- @IBAction func menuItemAction_background(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .background, index: 0)
- }
-
- @IBAction func menuItemAction_headerfooter(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .headerAndFooter, index: 0)
- }
-
- @IBAction func menuItemAction_bates(_ sender: Any) {
- self.toolbarController.delegate?.clickChildTool?(type: .bates, index: 0)
- }
-
- @IBAction func menuItemAction_batch(_ sender: Any) {
- // KMBatchWindowController.openFile(self.listView.document?.documentURL, .Batch)
- }
-
- func compression(_ sender: Any?) {
- self.toolbarController.delegate?.clickChildTool?(type: .compress, index: 0)
- }
-
- func merge(_ sender: Any?) {
- self.toolbarController.delegate?.clickChildTool?(type: .merge, index: 0)
- }
-
- func convert(_ sender: Any?) {
- self.toolbarController.delegate?.clickChildTool?(type: .word, index: 0)
- }
-
- func imageToPDF(_ sender: Any?) {
- KMApp.ShowImageToPDFWindow()
- }
-
- func ocr(_ sender: Any?) {
- self.toolbarController.clickItem(KMDocumentScanOCRToolbarItemIdentifier)
- }
-
- func extractImage(_ sender: Any?) {
- self.extractImageAction(num: 1)
- }
-
- func pageEdit(_ sender: Any?) {
- self.toolbarController.clickItem(KMDocumentPageToolbarItemIdentifier)
- }
-
- func textEditAction(_ sender: Any?) {
- self.toolbarController.clickItem(KMDocumentEditToolbarItemIdentifier)
- }
-
- func security(_ sender: Any?) {
- self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 1)
- }
-
- func decryption(_ sender: Any?) {
- self.toolbarController.delegate?.clickChildTool?(type: .secure, index: 2)
- }
-
- func cropAll(_ sender: Any?) {
- // NSRect rect[2] = {NSIntegralRect([pdfView currentSelectionRect]), NSZeroRect};
- // NSPointerArray *rectArray = [NSPointerArray rectPointerArray];
- // BOOL emptySelection = NSIsEmptyRect(rect[0]);
- //
- // if (emptySelection) {
- // NSInteger i, j, count = [[pdfView document] pageCount];
- // rect[0] = rect[1] = NSZeroRect;
- //
- // if (count == 0)
- // return;
- //
- // [self beginProgressSheetWithMessage:[NSLocalizedString(@"Cropping Pages", @"Message for progress sheet") stringByAppendingEllipsis] maxValue:MIN(18, count)];
- //
- // if (count == 1) {
- // rect[0] = [[[pdfView document] pageAtIndex:0] foregroundBox];
- // [self incrementProgressSheet];
- // } else if (count < 19) {
- // for (i = 0; i < count; i++) {
- // rect[i % 2] = NSUnionRect(rect[i % 2], [[[pdfView document] pageAtIndex:i] foregroundBox]);
- // [self incrementProgressSheet];
- // }
- // } else {
- // NSInteger start[3] = {1, (count - 5) / 2, count - 6};
- // for (j = 0; j < 3; j++) {
- // for (i = start[j]; i < start[j] + 6; i++) {
- // rect[i % 2] = NSUnionRect(rect[i % 2], [[[pdfView document] pageAtIndex:i] foregroundBox]);
- // [self incrementProgressSheet];
- // }
- // }
- // }
- // CGFloat w = fmax(NSWidth(rect[0]), NSWidth(rect[1]));
- // CGFloat h = fmax(NSHeight(rect[0]), NSHeight(rect[1]));
- // for (j = 0; j < 2; j++)
- // rect[j] = NSMakeRect(floor(NSMidX(rect[j]) - 0.5 * w), floor(NSMidY(rect[j]) - 0.5 * h), w, h);
- // [rectArray addPointer:rect];
- // [rectArray addPointer:rect + 1];
- // } else {
- // [rectArray addPointer:rect];
- // }
- //
- // [self cropPagesToRects:rectArray];
- // [pdfView setCurrentSelectionRect:NSZeroRect];
- self.cropAllPage()
- }
-
- func crop(_ sender: Any?) {
- self.cropCurrentPage()
- }
-
- func autoCropAll(_ sender: Any?) {
- #warning("暂时这么处理,后续调整")
- self.cropAllPage()
- }
-
- func smartAutoCropAll(_ sender: Any?) {
- #warning("暂时这么处理,后续调整")
- self.cropAllPage()
- }
-
- func cropOptionsModel(_ sender: Any?) {
- KMPrint("cropOptionsModel ...")
- }
-
- func selectToolModel(_ sender: Any?) {
- self.toolbarController.clickItem(KMToolbarSelectToolModeItemIdentifier)
- }
-
- func takeSnapshot(_ sender: Any?) {
- self.listView.takeSnapshot(sender)
- }
-
- func takeSnapshotSelectContent(_ sender: Any?) {
- self.listView.takeSnapshotSelectContent(sender)
- }
-
- func changeAnnotationMode(_ sender: Any?) {
- if let data = sender as? NSMenuItem {
- self.changeAnnotationMode_itemAction(sender: data)
- }
- }
-
- func addWatermark(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
- }
-
- func removeWatermark(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
- }
-
- func batchAddWatermark(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
- }
-
- func batchRemoveWatermark(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
- }
-
- func templateWatermark(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolWatermarkItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolWatermarkItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
- }
-
- func addBackground(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
- }
-
- func removeBackground(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
- }
-
- func batchAddBackground(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
- }
-
- func batchRemoveBackground(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil) }
-
- func templateBackground(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBackgroundItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBackgroundItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
- }
-
- func addHeaderFooter(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
- }
-
- func removeHeaderFooter(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
- }
-
- func batchAddHeaderFooter(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
- }
-
- func batchRemoveHeaderFooter(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
- }
-
- func templateHeaderFooter(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolHeaderFooterItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolHeaderFooterItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
- }
-
- func addHeaderFooterBates(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 1, info: nil)
- }
-
- func removeHeaderFooterBates(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 2, info: nil)
- }
-
- func batchAddBates(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 3, info: nil)
- }
-
- func batchRemoveBates(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 4, info: nil)
- }
-
- func templateBates(_ sender: Any?) {
- var item = self.toolbarController.findItem(KMToolbarToolBatesItemIdentifier)
- if item == nil {
- item = KMToolbarItemView(itemIdentifier: KMToolbarToolBatesItemIdentifier)
- }
- self.toolbarController.toolbarViewController(self.toolbarController.childToolBarView!, menuItemDidClick: item!, index: 5, info: nil)
- }
-
- func togglePoster(_ sender: Any?) {
- KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .poster)
- }
-
- func toggleMultiple(_ sender: Any?) {
- KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .multipage)
- }
-
- func toggleBooklet(_ sender: Any?) {
- KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .pamphlet)
- }
-
- func rotateLeft(_ sender: Any?) {
- Task { @MainActor in
- let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
- let rotation = page.rotation
- page.leftRotate()
-
- self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
- }
- }
-
- func rotateRight(_ sender: Any?) {
- Task { @MainActor in
- let page : CPDFPage = self.listView?.currentPage() ?? CPDFPage()
- let rotation = page.rotation
- page.rightRotate()
-
- self.rotatePageItems(pageItems: [KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation)])
- }
- }
-
- func rotateAllLeft(_ sender: Any?) {
- Task { @MainActor in
- var pageItems: [KMThumbnailPageItem] = []
- for index in 0 ... self.listView.document.pageCount - 1 {
- let page: CPDFPage = self.listView.document.page(at: index)
- let rotation = page.rotation
- page.leftRotate()
- pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
- }
- self.rotatePageItems(pageItems: pageItems)
- }
- }
-
- func rotateAllRight(_ sender: Any?) {
- Task { @MainActor in
- var pageItems: [KMThumbnailPageItem] = []
- for index in 0 ... self.listView.document.pageCount - 1 {
- let page: CPDFPage = self.listView.document.page(at: index)
- let rotation = page.rotation
- page.leftRotate()
- pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
- }
- self.rotatePageItems(pageItems: pageItems)
- }
- }
-
- func autoSelectContent(_ sender: Any?) {
- self.listView.autoSelectContent(sender)
- }
- }
- // MARK: window Menu
- extension KMMainViewController {
- @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {
- (self.myDocument as? KMMainDocument)?.browser.selectPreviousTab()
- }
-
- @IBAction func menuItemAction_showNextTagPage(_ sender: Any) {
- (self.myDocument as? KMMainDocument)?.browser.selectNextTab()
- }
-
- @IBAction func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
- self.browserWindowController?.openNewWindow(sender)
- }
-
- @IBAction func menuItemAction_mergeAllWindow(_ sender: Any) {
- ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController)?.mergeAllWindow(sender)
- }
-
- @IBAction func menuItemAction_currentWindowName(_ sender: Any) {
-
- }
- }
- extension KMMainViewController: NSMenuItemValidation, NSMenuDelegate {
- func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
- if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
- menuItem.title = (self.myDocument?.fileURL!.lastPathComponent)!
- return true
- }
-
- if (menuItem.action == #selector(menuItemAction_thumai) ||
- menuItem.action == #selector(menuItemAction_outline) ||
- menuItem.action == #selector(menuItemAction_bookmark) ||
- menuItem.action == #selector(menuItemAction_annotation) ||
- menuItem.action == #selector(menuItemAction_search)) {
- menuItem.state = .off
- let type = self.leftSideViewController.type.methodType
- if (menuItem.action == #selector(menuItemAction_thumai) && type == .Thumbnail) {
- menuItem.state = .on
- }
- if (menuItem.action == #selector(menuItemAction_outline) && type == .Outline) {
- menuItem.state = .on
- }
- if (menuItem.action == #selector(menuItemAction_bookmark) && type == .BookMark) {
- menuItem.state = .on
- }
- if (menuItem.action == #selector(menuItemAction_annotation) && type == .Annotation) {
- menuItem.state = .on
- }
- if (menuItem.action == #selector(menuItemAction_search) && type == .Search) {
- menuItem.state = .on
- }
- }
- if (menuItem.action == #selector(menuItemAction_hiddenLeftSide)) {
- if (self.leftPanelOpen) {
- menuItem.title = NSLocalizedString("Hide Left Side Panel", comment: "")
- } else {
- menuItem.title = NSLocalizedString("Show Left Side Panel", comment: "")
- }
- }
- if (menuItem.action == #selector(menuItemAction_hiddenRightSide)) {
- if (self.rightPanelIsOpen) {
- menuItem.title = NSLocalizedString("Hide Right Side Panel", comment: "")
- } else {
- menuItem.title = NSLocalizedString("Show Right Side Panel", comment: "")
- }
- }
-
- if (menuItem.action == #selector(menuItemAction_hiddenAllAnnotation)) {
- if (self.listView.hideNotes) {
- menuItem.title = NSLocalizedString("Show Notes", comment: "")
- } else {
- menuItem.title = NSLocalizedString("Hide Notes", comment: "")
- }
- }
-
- if (menuItem.action == #selector(menuItemAction_showForwardTagPage) ||
- menuItem.action == #selector(menuItemAction_showNextTagPage)) {
- let browser = self.browserWindowController?.browser
- if (browser != nil && (browser is KMBrowser)) {
- if (menuItem.action == #selector(menuItemAction_showForwardTagPage)) {
- return (browser as! KMBrowser).canSelectPreviousTab()
- }
- if (menuItem.action == #selector(menuItemAction_showNextTagPage)) {
- return (browser as! KMBrowser).canSelectNextTab()
- }
- }
- }
- if (menuItem.action == #selector(menuItemAction_mergeAllWindow)) {
- if let _browserWindowC = ((self.myDocument as? KMMainDocument)?.browser.windowController as? KMBrowserWindowController) {
- return _browserWindowC.canMergeAllWindow()
- }
- }
-
- if (menuItem.action == #selector(menuItemAction_nextPage) ||
- menuItem.action == #selector(menuItemAction_forwardPage) ||
- menuItem.action == #selector(menuItemAction_firstPage) ||
- menuItem.action == #selector(menuItemAction_lastPage) ||
- menuItem.action == #selector(menuItemAction_forward) ||
- menuItem.action == #selector(menuItemAction_goback)) {
- if (menuItem.action == #selector(menuItemAction_nextPage)) {
- if self.listView.isEditing() && self.listView.isEditable() {
- return false
- }
- return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToNextPage())
- }
- if (menuItem.action == #selector(menuItemAction_forwardPage)) {
- if self.listView.isEditing() && self.listView.isEditable() {
- return false
- }
- return (self.pdfViewCanHorizontalScroll() == false && self.listView.canGoToPreviousPage())
- }
- if (menuItem.action == #selector(menuItemAction_firstPage)) {
- return self.listView.canGoToFirstPage()
- }
- if (menuItem.action == #selector(menuItemAction_lastPage)) {
- return self.listView.canGoToLastPage()
- }
- if (menuItem.action == #selector(menuItemAction_forward)) {
- return self.listView.km_canGoForward()
- }
- if (menuItem.action == #selector(menuItemAction_goback)) {
- return self.listView.km_canGoBack()
- }
- }
-
- if menuItem.action == #selector(changeAnnotationMode) || menuItem.action == #selector(changeAnnotationMode_itemAction) {
- // if ([[menuItem menu] numberOfItems] > ANNOTATION_MODE_COUNT)
- // [menuItem setState:[self toolMode] == SKNoteToolMode && [self annotationMode] == (SKNoteType)[menuItem tag] ? NSOnState : NSOffState];
- // else
- // [menuItem setState:[self annotationMode] == (SKNoteType)[menuItem tag] ? NSOnState : NSOffState];
- if self.listView.annotationType.rawValue == menuItem.tag {
- menuItem.state = .on
- } else {
- menuItem.state = .off
- }
- return true
- }
- guard let action = menuItem.action else {
- return false
- }
-
- if KMSystemMenu.isToolSelector(sel: action) {
- if action == KMSystemMenu.Tool.autoSelectContentSelector {
- let toolMode = self.listView?.toolMode ?? .none
- return toolMode == .selectToolMode
- }
- }
-
- return true
- }
- }
|