123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780 |
- //
- // KMPDFViewController.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/10/18.
- //
- import Cocoa
- class KMPDFViewController: NSViewController {
- @IBOutlet var contendBox: NSBox!
-
- @IBOutlet var toolbarBox: NSBox! //工具栏Box
-
- @IBOutlet var bottomContendBox: NSBox! //
-
- @IBOutlet var sidebarBox: NSBox! //左侧边栏Box
-
- @IBOutlet var infoContendSplitView: KMPDFSplitView!
- @IBOutlet var infoSplitLeftView: NSView!
- @IBOutlet var infoSplitRightView: NSView!
- @IBOutlet var infoSplitCenterView: NSView!
-
- @IBOutlet var pdfSplitView: NSSplitView!
- @IBOutlet var pdfSplitTopView: NSView!
- @IBOutlet var pdfSplitBottomView: NSView!
-
- @IBOutlet var toolbarBoxHeightConst: NSLayoutConstraint!
- @IBOutlet var infoSplitViewLeftConst: NSLayoutConstraint!
-
- var viewManager: KMPDFViewManager = KMPDFViewManager.init()
- var toolbarManager: KMPDFToolbarManager = KMPDFToolbarManager.init()
-
- var pdfView: CPDFListView!
- var document: CPDFDocument?
- var myDocument: NSDocument?
-
- var insertDocuments: Set<CPDFDocument> = [] //插入新文档时,SDK会出现崩溃,临时记录
- //工具栏
- private var pdfToolbarController: KMPDFToolbarController?
-
- //BOTA SideBar
- private var sideBarController: KMPDFSideBarController?
-
- //页面编辑
- private var pageEditViewController: KMNPageEditViewController?
-
- //DisplaySetting
- private var displaySettingController: KMNDisplayViewController?
-
- //SPlitPDF 第二个PDF
- private var splitPDFController: KMSplitPDFViewController?
-
- private var pdfBottomToolbar: KMSplitToolbar?
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- toolbarManager.pdfViewManager = viewManager
- }
-
- override func viewDidAppear() {
- super.viewDidAppear()
-
- setupUI()
-
- }
-
- func setupUI() {
-
- initPDFView()
-
- initToolbar()
-
- initSideBar()
-
- setUpSplitView()
-
- }
-
- //MARK: - PDFView
- func initPDFView() {
- if pdfView == nil {
- pdfView = CPDFListView.init(frame: CGRectMake(0, 0, 100, 100))
- pdfView?.autoresizingMask = [.width, .height]
- }
- pdfView.document = self.document
-
- pdfView.delegate = self
- pdfView.pdfListViewDelegate = self
-
- reloadPDFSplitInfo()
- }
-
- //MARK: - SplitView
- func setUpSplitView() {
- infoContendSplitView.wantsLayer = true
- infoContendSplitView.layer?.backgroundColor = NSColor.clear.cgColor
- infoContendSplitView.delegate = self
- infoContendSplitView.layer?.masksToBounds = true
-
- infoContendSplitView.setPosition(-10, ofDividerAt: 0)
- infoContendSplitView.setPosition(CGRectGetWidth(infoContendSplitView.frame), ofDividerAt: 1)
-
- }
-
- func setupSplitPDFController() {
- if splitPDFController == nil {
- splitPDFController = KMSplitPDFViewController.init()
- }
- splitPDFController?.view.frame = pdfSplitBottomView.bounds
- splitPDFController?.view.autoresizingMask = [.height, .width]
- splitPDFController?.viewManager = self.viewManager
- splitPDFController?.delegate = self
- splitPDFController?.reloadData()
-
- pdfSplitBottomView.addSubview(splitPDFController!.view)
- }
-
-
-
- //MARK: - 工具栏
- func initToolbar() {
- toolbarBox.borderWidth = 0
-
- if pdfToolbarController == nil {
- pdfToolbarController = KMPDFToolbarController.init()
- }
- pdfToolbarController?.view.frame = toolbarBox.bounds
- pdfToolbarController?.view.autoresizingMask = [.width, .height]
- pdfToolbarController?.delegate = self
- toolbarBox.contentView = pdfToolbarController?.view
-
- pdfToolbarController?.viewManager = viewManager
- pdfToolbarController?.toolbarManager = toolbarManager
- pdfToolbarController?.pdfView = pdfView
- pdfToolbarController?.setUpData()
-
- refreshToolbarView()
- }
-
- func refreshToolbarView() {
-
- let _manager = viewManager
-
- if _manager.toolMode == .Markup ||
- _manager.toolMode == .Edit ||
- _manager.toolMode == .Form ||
- _manager.toolMode == .Fill ||
- _manager.toolMode == .Convert ||
- _manager.toolMode == .Protect ||
- _manager.toolMode == .Tools {
-
- toolbarBoxHeightConst.constant = 80
- } else {
- if _manager.isPageEditMode {
- toolbarBoxHeightConst.constant = 80
- } else {
- toolbarBoxHeightConst.constant = 40
- }
- }
-
- }
-
- //MARK: - 侧边栏
- func initSideBar() {
- sidebarBox.borderWidth = 0
-
- if sideBarController == nil {
- sideBarController = KMPDFSideBarController.init()
- }
- sideBarController?.view.frame = sidebarBox.bounds
- sideBarController?.view.autoresizingMask = [.width, .height]
- sidebarBox.contentView = sideBarController?.view
-
- sideBarController?.pdfView = pdfView
- sideBarController?.delegate = self
- sideBarController?.pdfViewManager = viewManager
-
- sideBarController?.reloadData()
- }
-
- //MARK: - PDFDisplayView
- func updatePDFDisplaySettingView() {
-
- if viewManager.showDisplayView {
- infoSplitViewLeftConst.constant = 264
- } else {
- infoSplitViewLeftConst.constant = 44
- }
-
- if viewManager.showDisplayView {
- if displaySettingController == nil {
- displaySettingController = KMNDisplayViewController.init()
- }
- displaySettingController?.view.frame = CGRectMake(0, 0, 264, CGRectGetHeight(bottomContendBox.frame))
- displaySettingController?.view.autoresizingMask = [.height, .maxXMargin]
- bottomContendBox.addSubview(displaySettingController!.view)
- displaySettingController?.pdfView = self.pdfView
- displaySettingController?.viewManager = self.viewManager
- displaySettingController?.delegate = self
-
- displaySettingController?.reloadData()
-
- } else {
- displaySettingController?.view.removeFromSuperview()
- displaySettingController = nil
- }
- }
-
-
- //MARK: - 页面编辑
- func enterPageEditMode() {
- pageEditViewController = KMNPageEditViewController(self.document)
- if(pageEditViewController != nil) {
- bottomContendBox.addSubview(pageEditViewController!.view)
- pageEditViewController?.view.frame = bottomContendBox.bounds
- pageEditViewController?.selectionIndexPaths = [IndexPath(item: pdfView.currentPageIndex, section: 0)]
- pageEditViewController?.thumbnailBaseViewDelegate = self
- pageEditViewController?.view.autoresizingMask = [.width,.height]
- }
- }
-
- func exitPageEditMode() {
- if pageEditViewController != nil {
- pageEditViewController?.view.removeFromSuperview()
- pageEditViewController = nil
- }
- }
-
- //MARK: - 阅读模式
- func openPDFReadMode() {
- if viewManager.showDisplayView {
- viewManager.showDisplayView = false
- pdfToolbarController?.reloadLeftIconView()
-
- updatePDFDisplaySettingView()
- }
- infoSplitViewLeftConst.constant = 0
- toolbarBoxHeightConst.constant = 0
-
-
- }
-
- func exitPDFReadMode() {
- viewManager.isPDFReadMode = false
-
- infoSplitViewLeftConst.constant = 44
-
- refreshToolbarView()
- }
-
- //MARK: - PPT
-
-
- //MARK: - PDF分屏视图
- func reloadPDFSplitInfo() {
- if pdfView?.viewSplitMode == .disable {
- pdfSplitView.isHidden = true
- pdfView.frame = infoSplitCenterView.bounds
- infoSplitCenterView.addSubview(pdfView)
-
- if splitPDFController != nil {
- splitPDFController = nil
- }
- } else {
- pdfSplitView.isHidden = false
- pdfView.frame = pdfSplitTopView.bounds
- pdfSplitTopView.addSubview(pdfView)
-
- setUpPDFBottomToolbar()
-
- setupSplitPDFController()
-
- if pdfView.viewSplitMode == .horizontal {
- pdfSplitView.isVertical = true
-
- } else if pdfView.viewSplitMode == .vertical {
- pdfSplitView.isVertical = false
-
- }
- }
- }
-
- func setUpPDFBottomToolbar() {
- if pdfBottomToolbar != nil {
- pdfBottomToolbar = nil
- }
- pdfBottomToolbar = KMSplitToolbar.init()
- pdfBottomToolbar?.frame = CGRectMake(CGRectGetWidth(pdfSplitTopView.frame)/2-144, 20, 288, 40)
- pdfBottomToolbar?.pdfView = self.pdfView
- pdfBottomToolbar?.reloadData()
-
- pdfSplitTopView.addSubview(pdfBottomToolbar!)
- }
-
- func reloadPDFBottomToolbar() {
- if viewManager.splitShowBottomBar {
- pdfBottomToolbar?.isHidden = false
- pdfBottomToolbar?.reloadData()
- } else {
- pdfBottomToolbar?.isHidden = true
- }
- }
-
-
-
- }
- //MARK: - NSSplitViewDelegate
- extension KMPDFViewController: NSSplitViewDelegate {
-
- func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
- return true
-
- }
-
- func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
- return true
- }
-
- func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- if dividerIndex == 0 {
- if proposedPosition > CGRectGetWidth(infoContendSplitView.frame)/2 - 10 {
- print(CGRectGetWidth(infoContendSplitView.frame)/2 - 10, NSDate())
- return CGRectGetWidth(infoContendSplitView.frame)/2 - 10
- }
- } else if dividerIndex == 1 {
- print(CGRectGetWidth(infoContendSplitView.frame)/2 - 10, NSDate())
- }
- return proposedPosition
- }
-
- func splitViewDidResizeSubviews(_ notification: Notification) {
-
- NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(splitViewResizeFinish), object: nil)
- self.perform(#selector(splitViewResizeFinish), with: nil, afterDelay: 0.15)
- }
-
- @objc func splitViewResizeFinish() {
- if infoContendSplitView.isSubviewCollapsed(infoSplitLeftView) {
- if viewManager.pdfSideBarType != .none {
- viewManager.pdfSideBarType = .none
-
- sideBarController?.reloadBOTAData()
- }
- }
- }
-
- }
- //MARK: - KMPDFSideBarControllerDelegate 左侧Sidebar代理
- extension KMPDFViewController: KMPDFSideBarControllerDelegate {
- func kmPDFSideBarControllerDidSidebarTypeUpdated(_ view: KMPDFSideBarController) {
- if viewManager.pdfSideBarType == .none {
- infoContendSplitView.setPosition(-20, ofDividerAt: 0)
- } else if viewManager.pdfSideBarType == .search {
- infoContendSplitView.setPosition(264, ofDividerAt: 0)
- } else if viewManager.pdfSideBarType == .thumbnail {
- infoContendSplitView.setPosition(264, ofDividerAt: 0)
- } else if viewManager.pdfSideBarType == .outline {
- infoContendSplitView.setPosition(264, ofDividerAt: 0)
- } else if viewManager.pdfSideBarType == .bookmark {
- infoContendSplitView.setPosition(264, ofDividerAt: 0)
- } else if viewManager.pdfSideBarType == .annotation {
- infoContendSplitView.setPosition(264, ofDividerAt: 0)
- }
- }
-
- func kmPDFSideBarControllerDidGotoPage(_ view: KMPDFSideBarController, _ pageIndex: Int) {
- pdfView.go(toPageIndex: pageIndex, animated: true)
-
- }
-
- }
- //MARK: - KMPDFToolbarControllerDelegate 工具栏代理
- extension KMPDFViewController: KMPDFToolbarControllerDelegate {
- func kmPDFToolbarControllerDidToolbarItemClicked(_ controller: KMPDFToolbarController, _ itemIdentifier: String) {
-
- print("toolbar点击", itemIdentifier)
- if itemIdentifier == KMPDFToolbar_ViewDisplay_Identifier {
- updatePDFDisplaySettingView()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Identifier {
- if viewManager.isPageEditMode == true {
- enterPageEditMode()
- } else {
- exitPageEditMode()
- }
- } else if itemIdentifier == KMPDFToolbar_convert_word_Identifier {
- let winC = KMConvertWordWindowController()
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_ppt_Identifier {
- let winC = KMConvertPPTsWindowController()
- winC.subType = 1
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_RTF_Identifier {
- let winC = KMConvertPPTsWindowController()
- winC.subType = 2
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_Text_Identifier {
- let winC = KMConvertPPTsWindowController()
- winC.subType = 4
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_CSV_Identifier {
- let winC = KMConvertPPTsWindowController()
- winC.subType = 5
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_excel_Identifier {
- let winC = KMConvertExcelWindowController()
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_image_Identifier {
- let winC = KMConvertImageWindowController()
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_HTML_Identifier {
- let winC = KMConvertHtmlWindowController()
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_convert_Json_Identifier {
- let winC = KMConvertJsonWindowController()
- let model = KMDocumentModel(url: self.pdfView.document.documentURL)
- winC.documentModel = model
- winC.own_beginSheetModal(for: self.view.window, completionHandler: nil)
- } else if itemIdentifier == KMPDFToolbar_PageEdit_InsertFile_Identifier {
- pageEditViewController?.insertFromPDFAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_InsertBlank_Identifier {
- pageEditViewController?.insertFromBlankAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_InsertClip_Identifier {
- pageEditViewController?.insertFromClipboardAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_InsertScanner_Identifier {
- pageEditViewController?.insertFromScannerAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Extract_Identifier {
- pageEditViewController?.extractPDFAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Replace_Identifier {
- pageEditViewController?.replacePDFAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Split_Identifier {
- pageEditViewController?.splitPDFAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Reverse_Identifier {
- pageEditViewController?.reversePDFAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_LeftRotate_Identifier {
- pageEditViewController?.rotatePageLeftAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_RightRotate_Identifier{
- pageEditViewController?.rotatePageRightAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Delete_Identifier {
- pageEditViewController?.deletePageAction()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Reduce_Identifier {
- pageEditViewController?.zoomOutPageAction()
- if(pageEditViewController?.canZoomInPageSize() == false) {
- toolbarManager.page_Increase_Property.isDisabled = true
- } else {
- toolbarManager.page_Increase_Property.isDisabled = false
- }
- if(pageEditViewController?.canZoomOutPageSize() == false) {
- toolbarManager.page_Reduce_Property.isDisabled = true
- } else {
- toolbarManager.page_Reduce_Property.isDisabled = false
- }
- controller.refreshSecondToolbarItemsState()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_Increase_Identifier {
- pageEditViewController?.zoomInPageAction()
-
- if(pageEditViewController?.canZoomInPageSize() == false) {
- toolbarManager.page_Increase_Property.isDisabled = true
- } else {
- toolbarManager.page_Increase_Property.isDisabled = false
- }
- if(pageEditViewController?.canZoomOutPageSize() == false) {
- toolbarManager.page_Reduce_Property.isDisabled = true
- } else {
- toolbarManager.page_Reduce_Property.isDisabled = false
- }
- controller.refreshSecondToolbarItemsState()
- } else if itemIdentifier == KMPDFToolbar_PageEdit_page_oddPage_Identifier {
- pageEditViewController?.thumbnailChoosePageStyle = .odd
- if(toolbarManager.page_pageInfo_Property.creatable == true) {
- toolbarManager.page_pageInfo_Property.creatable = false
- controller.refreshSecondToolbarItemsState()
- }
- } else if itemIdentifier == KMPDFToolbar_PageEdit_page_EvenPage_Identifier {
- pageEditViewController?.thumbnailChoosePageStyle = .even
- if(toolbarManager.page_pageInfo_Property.creatable == true) {
- toolbarManager.page_pageInfo_Property.creatable = false
- controller.refreshSecondToolbarItemsState()
- }
- } else if itemIdentifier == KMPDFToolbar_PageEdit_page_PortraitPage_Identifier {
- pageEditViewController?.thumbnailChoosePageStyle = .horizontal
- if(toolbarManager.page_pageInfo_Property.creatable == true) {
- toolbarManager.page_pageInfo_Property.creatable = false
- controller.refreshSecondToolbarItemsState()
- }
- } else if itemIdentifier == KMPDFToolbar_PageEdit_page_LandscapePage_Identifier {
- pageEditViewController?.thumbnailChoosePageStyle = .vertical
- if(toolbarManager.page_pageInfo_Property.creatable == true) {
- toolbarManager.page_pageInfo_Property.creatable = false
- controller.refreshSecondToolbarItemsState()
- }
- } else if itemIdentifier == KMPDFToolbar_PageEdit_page_AllPage_Identifier {
- pageEditViewController?.thumbnailChoosePageStyle = .allPage
- if(toolbarManager.page_pageInfo_Property.creatable == true) {
- toolbarManager.page_pageInfo_Property.creatable = false
- controller.refreshSecondToolbarItemsState()
- }
- } else if itemIdentifier == KMPDFToolbar_PageEdit_page_CustomPage_Identifier {
- pageEditViewController?.thumbnailChoosePageStyle = .custom
- toolbarManager.page_pageInfo_Property.text = nil
- if(toolbarManager.page_pageInfo_Property.creatable == false) {
- toolbarManager.page_pageInfo_Property.creatable = true
- }
- controller.refreshSecondToolbarItemsState()
- }
-
- refreshToolbarView()
- }
- }
- //MARK: - KMNDisplayViewControllerDelegate代理
- extension KMPDFViewController: KMNDisplayViewControllerDelegate {
- //Display Mode
- func displayViewControllerDidDisplayModeChanged(_ controller: KMNDisplayViewController) {
- pdfView.layoutDocumentView()
-
- }
-
- //阅读模式
- func displayViewControllerDidReadModeUpdated(_ controller: KMNDisplayViewController) {
- if viewManager.isPDFReadMode {
- openPDFReadMode()
- } else {
- exitPDFReadMode()
- }
- }
-
- //PPT
- func displayViewControllerDidGotoSlideShow(_ controller: KMNDisplayViewController) {
-
- }
- //SplitView
- func displayViewControllerDidSplitModeChanged(_ controller: KMNDisplayViewController) {
- reloadPDFSplitInfo()
-
- }
-
- func displayViewControllerDidSplitFileChanged(_ controller: KMNDisplayViewController) {
- splitPDFController?.reloadData()
-
- }
-
- func displayViewControllerDidToolbarStateChanged(_ controller: KMNDisplayViewController) {
- splitPDFController?.refreshToolbarState()
-
- reloadPDFBottomToolbar()
- }
- }
- //MARK: - KMSplitPDFViewControllerDelegate SplitPDFView分屏视图
- extension KMPDFViewController: KMSplitPDFViewControllerDelegate {
- func splitPDFViewControllerDidUpdateFilePath(_ controller: KMSplitPDFViewController) {
- displaySettingController?.reloadData()
-
- }
-
- func splitPDFViewControllerDidUpdatePDFScale(_ controller: KMSplitPDFViewController) {
- if let scaleFactor = controller.pdfView?.scaleFactor {
- pdfView.scaleFactor = scaleFactor
- }
- }
-
- func splitPDFViewControllerDidUpdatePDFPageIndex(_ controller: KMSplitPDFViewController) {
- if let pageIndex = controller.pdfView?.currentPageIndex {
- pdfView.go(toPageIndex: pageIndex, animated: false)
- }
-
- }
- }
- //MARK: - CPDFViewDelegate PDFView代理
- extension KMPDFViewController: CPDFViewDelegate {
- func pdfViewDocumentDidLoaded(_ pdfView: CPDFView!) {
- sideBarController?.reloadPageTurnerData()
- }
-
- func pdfViewCurrentPageDidChanged(_ pdfView: CPDFView!) {
- sideBarController?.reloadPageTurnerData()
-
- reloadPDFBottomToolbar()
- //分屏视图
- if viewManager.splitSyncScroll {
- if splitPDFController?.inPDFFirst == false && splitPDFController?.outPDFFirst == false {
- splitPDFController?.outPDFFirst = true
-
- if let splitPDFView = splitPDFController?.pdfView, let document = splitPDFView.document {
- var index = pdfView.currentPageIndex
- if index > document.pageCount {
- index = Int(splitPDFView.document.pageCount - 1)
- }
- splitPDFView.go(toPageIndex: index, animated: false)
- }
- NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(pdfUpdatedFinish), object: nil)
- self.perform(#selector(pdfUpdatedFinish), with: nil, afterDelay: 0.35)
- } else if splitPDFController?.outPDFFirst == true {
- if let splitPDFView = splitPDFController?.pdfView, let document = splitPDFView.document {
- var index = pdfView.currentPageIndex
- if index > document.pageCount {
- index = Int(splitPDFView.document.pageCount - 1)
- }
- splitPDFView.go(toPageIndex: index, animated: false)
- }
-
- NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(pdfUpdatedFinish), object: nil)
- self.perform(#selector(pdfUpdatedFinish), with: nil, afterDelay: 0.35)
- }
- }
-
- }
-
- func pdfViewScaleDidChanged(_ pdfView: CPDFView!) {
- pdfToolbarController?.reloadSelectZoomView()
-
- reloadPDFBottomToolbar()
-
- //分屏视图
- if viewManager.splitSyncScroll {
- if splitPDFController?.inPDFFirst == false && splitPDFController?.outPDFFirst == false {
- splitPDFController?.outPDFFirst = true
-
- NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(pdfUpdatedFinish), object: nil)
- self.perform(#selector(pdfUpdatedFinish), with: nil, afterDelay: 0.35)
- } else if splitPDFController?.outPDFFirst == true {
- if let splitPDFView = splitPDFController?.pdfView {
- splitPDFView.scaleFactor = pdfView.scaleFactor
- }
- NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(pdfUpdatedFinish), object: nil)
- self.perform(#selector(pdfUpdatedFinish), with: nil, afterDelay: 0.35)
- }
- }
- }
-
-
-
- @objc func pdfUpdatedFinish() {
- splitPDFController?.inPDFFirst = false
- splitPDFController?.outPDFFirst = false
-
- }
-
- }
- extension KMPDFViewController: CPDFListViewDelegate {
-
- func pdfListViewKeyDownIsContinue(_ pdfListView: CPDFListView!, theEvent: NSEvent!) -> Bool {
- let command = theEvent.modifierFlags.contains(.command)
- let control = theEvent.modifierFlags.contains(.control)
- KMPrint(theEvent.keyCode)
- if pdfView.isEditing() {
- if control && theEvent.keyCode == 11 { // ctr + b
-
- return false
- } else if control && theEvent.keyCode == 34 { // ctr +i
-
- return false
- } else if theEvent.keyCode == 36 { // enter
- if pdfView.isCropMode {
-
- return false
- }
- }
- }
-
- if (theEvent.keyCode == 11 && command) { // command + B [添加书签]
-
- return false
- } else if (command && control && theEvent.keyCode == 14) { // command + control + E [注释 橡皮擦]
- return false
- } else if (theEvent.keyCode == 123) { // 向左
- if(self.pdfView.isEditing() && !self.pdfView.isSelecteditAreaNotEdit()) {
- return false
- } else {
-
- }
- } else if (theEvent.keyCode == 126) { // 向上
- if(self.pdfView.isEditing() && !self.pdfView.isSelecteditAreaNotEdit()) {
- return false
- } else {
- if (self.pdfView.isContinousScroll()) {
- return true
- }
- }
- } else if (theEvent.keyCode == 124) { // 向右
- if(self.pdfView.isEditing() && !self.pdfView.isSelecteditAreaNotEdit()) {
- return false
- } else {
-
- }
- } else if (theEvent.keyCode == 125) { // 向下
- if(self.pdfView.isEditing() && !self.pdfView.isSelecteditAreaNotEdit()) {
- return false
- } else {
- if (self.pdfView.isContinousScroll()) {
- return true
- }
- }
- } else if (theEvent.keyCode == 36) {
- if pdfView.annotationType == .addImage || pdfView.annotationType == .addText {
- if self.pdfView.isEditImage {
- }
- }
- }
-
- if theEvent.keyCode == 53 {
- //ESC
- if view.window?.styleMask.contains(.fullScreen) == true {
- view.window?.toggleFullScreen(nil)
- }
-
- //阅读模式
- if viewManager.isPDFReadMode {
- exitPDFReadMode()
- viewManager.isPDFReadMode = false
-
- return true
- }
-
- }
- return true
- }
- }
-
- //MARK: - KMNThumbnailBaseViewDelegate
- extension KMPDFViewController: KMNThumbnailBaseViewDelegate {
- func clickThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,currentIndex:Int) {
- exitPageEditMode()
- viewManager.isPageEditMode = false
- pdfToolbarController?.reloadPageEditView()
- }
-
- func insertPDFThumbnailViewControlle(pageEditVC: KMNThumbnailBaseViewController?, pdfDocment: CPDFDocument?) {
- if(pdfDocment != nil) {
- insertDocuments.insert(pdfDocment!)
- }
- }
-
- func changeIndexPathsThumbnailViewControlle(pageEditVC: KMNThumbnailBaseViewController?, selectionIndexPaths: Set<IndexPath>, selectionStrings: String) {
- toolbarManager.page_pageInfo_Property.text = selectionStrings
-
- if(toolbarManager.page_pageInfo_Property.creatable == false) {
- toolbarManager.page_pageInfo_Property.creatable = true
- }
- pdfToolbarController?.refreshSecondToolbarItemsState()
- }
- }
-
|