12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703 |
- //
- // KMMainViewController+MenuAction.swift
- // PDF Reader Pro
- //
- // 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 IAPProductsManager.default().isAvailableAllFunction() == false {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- 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 {
- @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) {
- self.rotateLeft(sender)
- }
-
- 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) { [weak 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) {
- self.rotateRight(sender)
- }
- @IBAction func menuItemAction_rotateAllPageLeft(_ sender: Any) {
- self.rotateAllLeft(sender)
- }
- @IBAction func menuItemAction_rotateAllPageRight(_ sender: Any) {
- self.rotateAllRight(sender)
- }
-
- // 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.switchType(.Thumbnail)
- }
- @IBAction func menuItemAction_outline(_ sender: Any) {
- self.leftSideViewController.switchType(.Outline)
- }
- @IBAction func menuItemAction_bookmark(_ sender: Any) {
- self.leftSideViewController.switchType(.Annotation)
- }
-
- @IBAction func menuItemAction_annotation(_ sender: Any) {
- self.leftSideViewController.switchType(.Annotation)
- }
- @IBAction func menuItemAction_search(_ sender: Any) {
- self.leftSideViewController.switchType(.Search)
- }
- @IBAction func menuItemAction_topic(_ sender: Any) {
- }
-
- @IBAction func menuItemAction_hiddenPageIndicator(_ sender: Any) {
-
- }
-
- @IBAction func togglePresentation(_ sender: Any?) {
- if self.canExitPresentation() {
- self.exitFullScreen("")
- } else if self.canEnterPresentation(){
- self.enterPresentation()
- }
- }
-
- @IBAction func chooseTransition(_ sender: Any?) {
- let presentationSheetController = SKPresentationOptionsSheetController()
- presentationSheetController.controller = self
- // let window = NSWindow.currentWindow()
- self.km_beginSheet(windowC: presentationSheetController)
- presentationSheetController.closeCallBack = {[weak self] vc in
- self?.km_quick_endSheet()
- }
- }
-
- @IBAction func toggleAutoFlow(_ sender: Any?) {
- if (self.listView.isAutoFlow()) {
- self.listView.stopAutoFlow()
- } else {
- self.listView.startAutoFlow()
- }
- }
- @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
- autoFlowOptionsSheetController = KMAutoFlowOptionsSheetController(windowNibName: "KMAutoFlowOptionsSheetController")
- NSWindow.currentWindow().beginSheet((autoFlowOptionsSheetController?.window)!) { responce in }
- }
-
- @IBAction func toggleReadingBar(_ sender: Any?) {
- KMPrint("toggleReadingBar")
- }
-
- @IBAction func toggleLeftSidePane(_ sender: Any?) {
- if self.model.leftPanelOpen {
- self.closeLeftPane()
- } else {
- self.openLeftPane()
- }
- }
-
- @IBAction func changeLeftSidePaneState(_ sender: Any?) {
- guard let item = sender as? NSMenuItem else {
- NSSound.beep()
- return
- }
- if item.tag == 3 {
- self.leftSideViewController.switchType(.snapshot)
- }
- }
-
- @IBAction func splitViewAction(_ sender: Any?) {
- guard let item = sender as? NSMenuItem else {
- return
- }
- if item.tag < 2 && IAPProductsManager.default().isAvailableAllFunction() == false {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- return
- }
- self.splitView(withTag: item.tag)
- }
-
- @IBAction func themesColor(_ sender: Any?) {
- guard let item = sender as? NSMenuItem else {
- NSSound.beep()
- return
- }
- let mode = item.tag
- if mode > 0 {
- if !IAPProductsManager.default().isAvailableAllFunction() {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- return
- }
- }
- if mode == 0 {
- self.listView.displayMode = .normal
- } else if mode == 1 {
- self.listView.displayMode = .soft
- } else if mode == 2 {
- self.listView.displayMode = .night
- } else if mode == 3 {
- self.listView.displayMode = .green
- } else {
- self.listView.displayMode = .custom
-
- var data: Data? = nil
- if let themesData = UserDefaults.standard.object(forKey: "kKMPDFViewModeThemesArray") as? Data {
- data = themesData
- }
- let appArray = NSKeyedUnarchiver.unarchiveObject(with: data ?? Data()) as? [Any] ?? []
- let mutableArray = appArray
- if mutableArray.count > 0 {
- let themesArray = mutableArray as! [NSColor]
- let color = themesArray[mode]
- self.listView.displayModeCustomColor = color
- }
- }
-
- self.listView.layoutDocumentView()
- self.listView.setNeedsDisplayForVisiblePages()
- UserDefaults.standard.set(mode, forKey: "kPDFViewModeKey")
- UserDefaults.standard.synchronize()
- }
-
- @IBAction func toggleStatusBar(_ sender: Any?) {
- KMPrint("toggleStatusBar ...")
- }
-
- @IBAction func toggleToolbarShow(_ sender: Any?) {
- self.toolbarController.mainToolBarisVisable = !self.toolbarController.mainToolBarisVisable
- }
- }
- // 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_wavyLine(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSquigglyAnnotationItemIdentifier)
- }
-
- @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)
- self.toolbarController.clickItem(KMToolbarSquareAnnotationItemIdentifier)
- }
- @IBAction func menuItemAction_circle(_ sender: Any) {
- UserDefaults.standard.set(7, forKey: KMToolBarToolPDFShapeStyle)
- self.toolbarController.clickItem(KMToolbarCircleAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_arrow(_ sender: Any) {
- UserDefaults.standard.set(5, forKey: KMToolBarToolPDFShapeStyle)
- self.toolbarController.clickItem(KMToolbarArrowAnnotationItemIdentifier)
- }
-
- @IBAction func menuItemAction_line(_ sender: Any) {
- UserDefaults.standard.set(4, forKey: KMToolBarToolPDFShapeStyle)
-
- self.toolbarController.clickItem(KMToolbarLineAnnotationItemIdentifier)
- }
- // 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) {
- }
-
- @IBAction func notesLink(_ sender: Any?) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarLinkAnnotationItemIdentifier)
- }
-
- // 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 notesStamp(_ sender: Any?) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMAnnotationStampToolbarItemIdentifier)
- }
-
- @IBAction func menuItemAction_signure(_ sender: Any) {
- self.mainMenuUpdateAnnotationStyle(identifier: KMToolbarSignSignatureAnnotationItemIdentifier)
- }
-
- @IBAction func image(_ sender: Any?) {
- self.toolbarController.clickItem(KMAnnotationImageToolbarItemIdentifier)
- }
-
- @IBAction func table(_ sender: Any?) {
- self.toolbarController.clickItem(KMAnnotationTableToolbarItemIdentifier)
- }
-
- @IBAction func addForm(_ sender: Any?) {
- guard let item = sender as? NSMenuItem else {
- NSSound.beep()
- return
- }
- var identifiers: String?
- let idx = item.tag
- if idx == 0 { // raido
- identifiers = KMToolbarToolRadioButtonItemIdentifier
- } else if idx == 1 { // checkbox
- identifiers = KMToolbarToolCheckBoxItemIdentifier
- } else if idx == 2 { // textfiled
- identifiers = KMToolbarToolTextFieldItemIdentifier
- } else if idx == 3 { // combobox
- identifiers = KMToolbarToolPullDownmenuItemIdentifier
- } else if idx == 4 { // listbox
- identifiers = KMToolbarToolListBoxItemIdentifier
- } else if idx == 5 { // button
- identifiers = KMToolbarToolButtonIdentifier
- } else if idx == 6 { // sign
- identifiers = KMToolbarToolSignBoxIdentifier
- }
- if let itemID = identifiers {
- self.toolbarController.clickItem(itemID)
- }
- }
-
- @IBAction func editNote(_ sender: Any?) {
- if self.listView.hideNotes {
- NSSound.beep()
- return
- }
- if let anno = self.listView.activeAnnotation {
- self.listView.edit(anno)
- }
- }
-
- @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 {
- self.toolbarController.clickItem(KMDocumentAnnotationToolbarItemIdentifier)
- }
- self.toolbarController.clickItem(identifier)
- }
- }
- // MARK: - KMSystemPDFMenuProtocol
- 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)
- }
-
- func toggleDisplayPageBreaks(_ sender: Any?) {
- self.listView?.displaysPageBreaks = !(self.listView?.displaysPageBreaks ?? false)
- self.listView.layoutDocumentView()
- }
-
- func changeDisplayBox(_ sender: Any?) {
- guard let item = sender as? NSMenuItem else {
- NSSound.beep()
- return
- }
- let mode = item.tag
- if mode == 0 {
- self.listView.displayBox = .mediaBox
- } else if mode == 1 {
- self.listView.displayBox = .cropBox
- }
- }
-
- func toggleAutoScale(_ sender: Any?) {
- // if ([self interactionMode] == SKPresentationMode)
- // [pdfView toggleAutoActualSize:sender];
- // else
- // [pdfView setAutoScales:[pdfView autoScales] == NO];
- self.listView.autoScales = !self.listView.autoScales
- }
-
- func doZoomToActualSize(_ sender: Any?) {
- self.selectZoom(.actualSize)
- }
-
- func doZoomToFit(_ sender: Any?) {
- self.selectZoom(.fit)
- }
-
- func doZoomIn(_ sender: Any?) {
- if (self.listView.canZoomIn) {
- self.listView.zoomIn(nil)
- }
- if self.digitalSignController?.pdfView != nil {
- if (self.digitalSignController?.pdfView.canZoomIn) == true {
- self.digitalSignController?.pdfView.zoomIn(nil)
- }
- }
- if self.redactController?.redactPdfView != nil {
- if (self.redactController?.redactPdfView.canZoomIn) == true {
- self.redactController?.redactPdfView.zoomIn(nil)
- }
- }
- }
-
- func doZoomOut(_ sender: Any?) {
- if (self.listView.canZoomOut) {
- self.listView.zoomOut(nil)
- }
- if self.digitalSignController?.pdfView != nil {
- if (self.digitalSignController?.pdfView.canZoomOut) == true {
- self.digitalSignController?.pdfView.zoomOut(nil)
- }
- }
- if self.redactController?.redactPdfView != nil {
- if (self.redactController?.redactPdfView.canZoomOut) == true {
- self.redactController?.redactPdfView.zoomOut(nil)
- }
- }
- }
-
- func doMarqueeZoomTool(_ sender: Any?) {
- let isSelected = self.toolbarController.findItem(KMToolbarZoomToSelectionItemIdentifier)?.isSelected ?? false
- if isSelected == false {
- self.toolbarController.clickItem(KMToolbarZoomToSelectionItemIdentifier)
- }
- }
-
- func highlightFormFiled(_ sender: Any?) {
- let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
- CPDFKitConfig.sharedInstance().setEnableFormFieldHighlight(!enabled)
-
- self.listView.setNeedsDisplayForVisiblePages()
- }
-
- func highlightLinks(_ sender: Any?) {
- let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
- CPDFKitConfig.sharedInstance().setEnableLinkFieldHighlight(!enabled)
-
- self.listView.setNeedsDisplayForVisiblePages()
- }
-
- func resetForm(_ sender: Any?) {
- self.listView.resetFormAnnotation()
- }
-
- func removeAllAnnotation(_ sender: Any?) {
- self.listView.removeAllAnnotation()
- }
-
- func savePDFSettingToDefaults(_ sender: Any?) {
- if self.interactionMode == .normal {
- UserDefaults.standard.sync_setValue(self.currentPDFSettings(), forKey: KMDefaultPDFDisplaySettingsKey)
- } else if self.interactionMode != .presentation {
- UserDefaults.standard.sync_setValue(self.currentPDFSettings(), forKey: KMDefaultFullScreenPDFDisplaySettingsKey)
- }
-
- if listView.displaysAsBook && self.listView.displayTwoUp {
- if listView.fetchDisplayViewMode() == .twoUp {
- KMPreferenceManager.shared.viewPageDisplayType = .bookMode
- } else {
- KMPreferenceManager.shared.viewPageDisplayType = .bookContinuous
- }
- } else {
- KMPreferenceManager.shared.viewPageDisplayType = KMPDFDisplayType(rawValue: listView.fetchDisplayViewMode().rawValue) ?? .singlePage
- }
-
- self.savePageNumberIfNeed()
- }
- }
- // 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
- 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 self.model.beforeMarkedPageIndex != NSNotFound {
- self.listView.goToPage(at: min(UInt(self.model.beforeMarkedPageIndex), pdfDoc.pageCount-1), point: self.model.beforeMarkedPagePoint)
- } else if (currentPageIndex != self.model.markedPageIndex) {
- // NSUInteger lastPageIndex = [pdfView currentPageIndexAndPoint:&beforeMarkedPagePoint rotated:NULL];
- let lastPageIndex = self.listView.currentPageIndexAndPoint(&self.model.beforeMarkedPagePoint, rotated: nil)
- self.listView.goToPage(at: min(UInt(self.model.markedPageIndex), pdfDoc.pageCount-1), point: self.model.markedPagePoint)
- self.model.beforeMarkedPageIndex = Int(lastPageIndex)
- }
- }
- @IBAction func markPage(_ sender: Any?) {
- self.model.markedPageIndex = Int(self.listView.currentPageIndexAndPoint(&self.model.markedPagePoint, rotated: nil))
- self.model.beforeMarkedPageIndex = NSNotFound
- }
- }
- // MARK: - tool Menu
- extension KMMainViewController: KMSystemToolMenuProtocol {
- func getInfo(_ sender: Any?) {
- KMInfoWindowController.shared.showWindow(sender)
- }
-
- @IBAction func menuItemAction_textTool(_ sender: Any) {
- self.listView?.toolMode = .textToolMode
- self.listView?.annotationType = .unkown
- }
-
- @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 value = KMDataManager.ud_integer(forKey: SKLastAnnotationModeKey)
- var aType: CAnnotationType = .highlight
- if let data = CAnnotationType(rawValue: value) {
- aType = data
- }
- if aType.isMarkup() || aType.isSquare() || aType == .freeText || aType == .anchored {
-
- } else {
- aType = .highlight
- }
- var itemId: String = KMToolbarHighlightAnnotationItemIdentifier
- if aType == .highlight {
-
- } else if aType == .underline {
- itemId = KMToolbarUnderlineAnnotationItemIdentifier
- } else if aType == .strikeOut {
- itemId = KMToolbarStrikeOutAnnotationItemIdentifier
- } else if aType == .ink {
- itemId = KMToolbarInkAnnotationItemIdentifier
- } else if aType == .freeText {
- itemId = KMToolbarFreeTextAnnotationItemIdentifier
- } else if aType == .anchored {
- itemId = KMToolbarAnchoredAnnotationItemIdentifier
- } else if aType == .square {
- itemId = KMToolbarSquareAnnotationItemIdentifier
- } else if aType == .circle {
- itemId = KMToolbarCircleAnnotationItemIdentifier
- } else if aType == .line {
- itemId = KMToolbarLineAnnotationItemIdentifier
- } else if aType == .arrow {
- itemId = KMToolbarArrowAnnotationItemIdentifier
- } else if aType == .link {
- itemId = KMToolbarLinkAnnotationItemIdentifier
- }
- let isSelected = self.toolbarController.findItem(itemId)?.isSelected ?? false
- if isSelected == false {
- self.toolbarController.selectItem(itemId)
- }
- }
-
- @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?) {
- self.cropAllPage()
- }
-
- func crop(_ sender: Any?) {
- self.cropCurrentPage()
- }
-
- // 白边距
- func autoCropAll(_ sender: Any?) {
- self.smart_cropAllPage()
- }
-
- // 自动
- func smartAutoCropAll(_ sender: Any?) {
- self.auto_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)
- var itemId: String?
- if data.tag == 8 {
- itemId = KMToolbarHighlightAnnotationItemIdentifier
- } else if data.tag == 9 {
- itemId = KMToolbarUnderlineAnnotationItemIdentifier
- } else if data.tag == 10 {
- itemId = KMToolbarStrikeOutAnnotationItemIdentifier
- }
- // else if data.tag == CAnnotationType.squiggly.rawValue {
- // itemId = KMToolbarSquigglyAnnotationItemIdentifier
- // }
- else if data.tag == 13 {
- itemId = KMToolbarInkAnnotationItemIdentifier
- } else if data.tag == 3 {
- itemId = KMToolbarFreeTextAnnotationItemIdentifier
- } else if data.tag == 1 {
- itemId = KMToolbarAnchoredAnnotationItemIdentifier
- } else if data.tag == 6 {
- itemId = KMToolbarSquareAnnotationItemIdentifier
- } else if data.tag == 7 {
- itemId = KMToolbarCircleAnnotationItemIdentifier
- }
- // else if data.tag == 4 {
- // itemId = KMToolbarArrowAnnotationItemIdentifier
- // }
- else if data.tag == 4 {
- itemId = KMToolbarLineAnnotationItemIdentifier
- } else if data.tag == 2 {
- itemId = KMToolbarLinkAnnotationItemIdentifier
- }
- if let data = itemId {
- self.toolbarController.clickItem(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?) {
- self.saveDocument()
- KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .poster)
- }
-
- func toggleMultiple(_ sender: Any?) {
- self.saveDocument()
- KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .multipage)
- }
-
- func toggleBooklet(_ sender: Any?) {
- self.saveDocument()
- KMPrintWindowController.showNewPrintWindowControll(inputDocument: self.listView.document, inputPageRange: KMPrintPageRange(), printType: .pamphlet)
- }
-
- func rotateLeft(_ sender: Any?) {
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- let winC = KMPurchaseCompareWindowController.sharedInstance()
- winC?.kEventName = "Reading_Rotate_BuyNow"
- winC?.kEventTag = 1
- winC?.showWindow(nil)
- return
- }
-
- 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)])
- self.handlePageBoundsDidChange(page: page, action: CPDFPage.Action.rotate)
- }
- }
-
- func rotateRight(_ sender: Any?) {
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- let winC = KMPurchaseCompareWindowController.sharedInstance()
- winC?.kEventName = "Reading_Rotate_BuyNow"
- winC?.kEventTag = 1
- winC?.showWindow(nil)
- return
- }
-
- 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)])
- self.handlePageBoundsDidChange(page: page, action: CPDFPage.Action.rotate)
- }
- }
-
- func rotateAllLeft(_ sender: Any?) {
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- return
- }
-
- 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)
- self.handlePageBoundsDidChange(page: nil, action: CPDFPage.Action.rotate)
- }
- }
-
- func rotateAllRight(_ sender: Any?) {
- if IAPProductsManager.default().isAvailableAllFunction() == false {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- return
- }
-
- 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.rightRotate()
- pageItems.append(KMThumbnailPageItem(page: page, rotate: page.rotation, oldRotate: rotation))
- }
- self.rotatePageItems(pageItems: pageItems)
- self.handlePageBoundsDidChange(page: nil, action: CPDFPage.Action.rotate)
- }
- }
-
- 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) {
-
- }
-
- @IBAction func performFit(_ sender: Any?) {
- if self.interactionMode != .normal {
- NSSound.beep()
- return
- }
-
- let displayMode = self.listView.fetchDisplayViewMode()
- let scaleFactor = self.listView.scaleFactor
- let autoScales = self.listView.autoScales
- var isSingleRow = false
- if displayMode == .singlePage || displayMode == .twoUp {
- isSingleRow = true
- } else if displayMode == .singlePageContinuous || self.listView.displaysAsBook {
- isSingleRow = (self.listView?.document?.pageCount ?? 0) <= 1
- } else {
- isSingleRow = (self.listView?.document?.pageCount ?? 0) <= 2
- }
-
- var frame = self.view.window?.frame ?? .zero
- var size: NSSize = .zero
- let oldSize = self.listView.frame.size
- let documentView = self.listView.documentView()
- let documentRect = documentView?.convert(documentView?.bounds ?? .zero, to: nil) ?? .zero
- let page = self.listView.currentPage()
- let box = self.listView.displayBox
- let PAGE_BREAK_MARGIN: CGFloat = 8.0
- let margin = self.listView.displaysPageBreaks ? PAGE_BREAK_MARGIN : 0.0
-
- // Calculate the new size for the pdfView
- size.width = NSWidth(documentRect)
- if (autoScales) {
- size.width /= scaleFactor
- }
- if (isSingleRow) {
- size.height = NSHeight(documentRect)
- } else {
- let rect = self.listView.convert(page?.bounds(for: box) ?? .zero, from: page)
- size.height = NSHeight(rect) + margin * scaleFactor
- // if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)] == NO || [NSScroller preferredScrollerStyle] == NSScrollerStyleLegacy)
- // size.width += [NSScroller scrollerWidth];
- if NSScroller.responds(to: NSSelectorFromString("preferredScrollerStyle")) == false {
- let w = NSScroller.scrollerWidth(for: .regular, scrollerStyle: .legacy)
- size.width += w
- } else {
- if NSScroller.preferredScrollerStyle == .legacy {
- let w = NSScroller.scrollerWidth(for: .regular, scrollerStyle: .legacy)
- size.width += w
- }
- }
- }
- if (autoScales) {
- size.height /= scaleFactor
- }
- // Calculate the new size for the window
- size.width = ceil(NSWidth(frame) + size.width - oldSize.width)
- size.height = ceil(NSHeight(frame) + size.height - oldSize.height)
- // Align the window frame from the old topleft point and constrain to the screen
- frame.origin.y = NSMaxY(frame) - size.height
- frame.size = size
- if let screen = self.view.window?.screen ?? NSScreen.main {
- frame = self.view.window?.constrainFrameRect(frame, to: screen) ?? .zero
- }
-
- self.view.window?.setFrame(frame, display: self.view.window?.isVisible ?? false)
- if displayMode == .singlePageContinuous || displayMode == .twoUpContinuous {
- self.listView.go(to: NSInsetRect(page?.bounds(for: box) ?? .zero, -0.5 * margin, -0.5 * margin), on: page)
- }
- }
- }
- extension KMMainViewController {
- override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
- if (menuItem.action == #selector(menuItemAction_currentWindowName)) {
- menuItem.title = (self.myDocument?.fileURL?.lastPathComponent) ?? ""
- return true
- }
-
- let act = menuItem.action
- if act == #selector(menuItemAnnotationClick_addStype) ||
- act == #selector(menuItemAnnotationClick_add) ||
- act == #selector(menuItemAnnotationClick_toolModel) ||
- act == #selector(changeAnnotationMode_itemAction) {
- return !(self.listView?.hideNotes ?? false)
- }
-
- if let data = act, KMSystemMenu.isAnnotationSelector(sel: data) {
- if KMSystemMenu.Annotation.hiddenAllSelector == act {
- // return true
- } else {
- return !(self.listView?.hideNotes ?? false)
- }
- }
-
- 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 == .Annotation) {
- 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.model.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.model.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 self.hasEnterPageEdit() {
- return false
- }
- 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) {
- let type = self.listView.annotationType
- if type == .highlight {
- menuItem.state = menuItem.tag == 8 ? .on : .off
- } else if type == .underline {
- menuItem.state = menuItem.tag == 9 ? .on : .off
- } else if type == .strikeOut {
- menuItem.state = menuItem.tag == 10 ? .on : .off
- } else if type == .ink {
- menuItem.state = menuItem.tag == 13 ? .on : .off
- } else if type == .freeText {
- menuItem.state = menuItem.tag == 3 ? .on : .off
- } else if type == .anchored {
- menuItem.state = menuItem.tag == 1 ? .on : .off
- } else if type == .square {
- menuItem.state = menuItem.tag == 6 ? .on : .off
- } else if type == .circle {
- menuItem.state = menuItem.tag == 7 ? .on : .off
- } else if type == .line {
- menuItem.state = menuItem.tag == 4 ? .on : .off
- } else if type == .link {
- menuItem.state = menuItem.tag == 2 ? .on : .off
- } else {
- menuItem.state = .off
- }
- return !self.listView.hideNotes
- }
- if 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
- }
-
- if menuItem.action == #selector(menuItemAction_print) {
- if self.listView.document.permissionsStatus == .user && !self.listView.document.allowsPrinting {
- return false
- }
- }
-
- if menuItem.action == #selector(highlightFormFiled) {
- let enabled = CPDFKitConfig.sharedInstance().enableFormFieldHighlight()
- menuItem.state = enabled ? .on : .off
-
- return true
- }
-
- if menuItem.action == #selector(highlightLinks) {
- let enabled = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight()
- menuItem.state = enabled ? .on : .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
- } else if action == KMSystemMenu.Tool.textToolSelector {
- let toolMode = self.listView?.toolMode ?? .textToolMode
- menuItem.state = toolMode == .textToolMode ? .on : .off
- return true
- } else if action == KMSystemMenu.Tool.scrolToolSelector {
- let toolMode = self.listView?.toolMode ?? .textToolMode
- menuItem.state = toolMode == .moveToolMode ? .on : .off
- return true
- } else if action == KMSystemMenu.Tool.zoomToolSelector {
- let toolMode = self.listView?.toolMode ?? .textToolMode
- menuItem.state = toolMode == .magnifyToolMode ? .on : .off
- return true
- } else if action == KMSystemMenu.Tool.selectToolSelector {
- let toolMode = self.listView?.toolMode ?? .textToolMode
- menuItem.state = toolMode == .selectToolMode ? .on : .off
- return true
- } else if action == KMSystemMenu.Tool.changeToolModeSelector {
- let aType = self.listView?.annotationType ?? .unkown
- if aType.isMarkup() || aType == .freeText || aType == .anchored || aType.isSquare() || aType == .link {
- menuItem.state = .on
- } else {
- menuItem.state = .off
- }
- return true
- }
- }
- if KMSystemMenu.isViewSelector(sel: action) {
- if action == KMSystemMenu.View.toggleLeftSidePaneSelector {
- if self.model.leftPanelOpen {
- menuItem.title = NSLocalizedString("Hide Panel", comment: "Menu item title")
- } else {
- menuItem.title = NSLocalizedString("Show Panel", comment: "Menu item title")
- }
- return true
- } else if action == KMSystemMenu.View.changeLeftSidePaneStateSelector {
- if menuItem.tag == 3 { // 快照
- menuItem.state = self.leftSideViewController.type.methodType == .snapshot ? .on : .off
- }
- return true
- } else if action == KMSystemMenu.View.themesColorSelector {
- let mode = menuItem.tag
-
- var viewMode: KMPDFViewMode = .normal
- if let storedViewMode = UserDefaults.standard.value(forKey: "kPDFViewModeKey") as? Int {
- viewMode = KMPDFViewMode(rawValue: UInt(storedViewMode)) ?? .normal
- }
- if mode == 0 {
- menuItem.state = viewMode == .normal ? .on : .off
- } else if mode == 1 {
- menuItem.state = viewMode == .soft ? .on : .off
- } else if mode == 2 {
- menuItem.state = viewMode == .night ? .on : .off
- } else if mode == 3 {
- menuItem.state = viewMode == .green ? .on : .off
- } else if mode == 4 {
- menuItem.state = viewMode == .themes1 ? .on : .off
- } else if mode == 5 {
- menuItem.state = viewMode == .themes2 ? .on : .off
- } else if mode == 6 {
- menuItem.state = viewMode == .themes3 ? .on : .off
- } else if mode == 7 {
- menuItem.state = viewMode == .themes4 ? .on : .off
- }
-
- var data: Data? = nil
- if let themesData = UserDefaults.standard.object(forKey: "kKMPDFViewModeThemesArray") as? Data {
- data = themesData
- }
- var themesCount = 0
- let appArray = NSKeyedUnarchiver.unarchiveObject(with: data ?? Data()) as? [Any] ?? []
- if appArray.count > 0 {
- themesCount = menuItem.tag - appArray.count
- } else {
- themesCount = menuItem.tag - 4
- }
- if themesCount >= 0 {
- menuItem.isHidden = true
- return false
- }else {
- menuItem.isHidden = false
- return true
- }
- // return true
- } else if action == KMSystemMenu.View.splitViewActionSelector {
- let mode = menuItem.tag
- if mode == 0 { // hor
- menuItem.state = self.listView.viewSplitMode == .horizontal ? .on : .off
- } else if mode == 1 { // verti
- menuItem.state = self.listView.viewSplitMode == .vertical ? .on : .off
- } else if mode == 2 { // single
- menuItem.state = self.listView.viewSplitMode == .disable ? .on : .off
- }
- } else if action == KMSystemMenu.View.toggleToolbarShowSelector {
- menuItem.title = self.toolbarController.mainToolBarisVisable ? KMLocalizedString("Hide Toolbar") : KMLocalizedString("Show Toolbar")
- }
- }
-
- if KMSystemMenu.isAnnotationSelector(sel: action) {
- if action == KMSystemMenu.Annotation.editNoteSelector {
- if self.interactionMode == .presentation {
- return false
- }
- guard let anno = self.listView?.activeAnnotation else {
- return false
- }
- return anno.isEditable()
- }
- }
- if action == NSSelectorFromString("changeDisplayBox:") {
- if menuItem.tag == 0 {
- menuItem.state = self.listView.displayBox == .mediaBox ? .on : .off
- } else if menuItem.tag == 1 {
- menuItem.state = self.listView.displayBox == .cropBox ? .on : .off
- }
- }
-
- return true
- }
- }
|