// // KMOCRWindowController.swift // PDF Master // // Created by lizhe on 2022/12/7. // import Cocoa class KMOCRWindowController: NSWindowController { @IBOutlet weak var batchPrecessingView: KMBatchProcessingView! @IBOutlet weak var chooseView: KMOCRChooseView! var chooseData: KMImageToPDFChooseModel? var batchData: [KMBatchProcessingTableViewModel]? var inputType: DataNavigationViewButtonActionType? deinit { KMPrint("KMOCRWindowController 释放") } override func windowDidLoad() { super.windowDidLoad() // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. self.window?.title = "批量OCR" self.setup() self.reloadData() } func setup() { self.batchPrecessingView.delegate = self self.batchPrecessingView.inputType = self.inputType self.chooseView.delegate = self } func reloadData() { } //MARK: 打开文件 static func openFiles(window:NSWindow) { KMBatchProcessingView.openfiles(window: window) { openPanel in openPanel.title = "选择图片" openPanel.canChooseDirectories = false openPanel.canChooseFiles = true openPanel.allowsMultipleSelection = true openPanel.allowedFileTypes = ["pdf"] } completion: {(panel ,data) in if data.count != 0 { let imageToPDFWindow: KMOCRWindowController = KMOCRWindowController.init(windowNibName: "KMOCRWindowController") imageToPDFWindow.showWindow(window) imageToPDFWindow.batchPrecessingView.inputData = data imageToPDFWindow.inputType = .OCR } } } } extension KMOCRWindowController: KMImageToPDFChooseViewDelegate { func exportAction(data: KMImageToPDFChooseModel) { KMPrint("导出") self.chooseData = data if self.batchData != nil { self.chooseData?.imageFilePaths = self.batchData KMImageToPDFManager.manager.exportPDF(model: self.chooseData!) { success, savePath, errors, OCRerrors in KMPrint(success) if success { NSWorkspace.shared.selectFile(savePath, inFileViewerRootedAtPath: ""); } else { let alert = NSAlert() alert.alertStyle = .critical alert.messageText = NSLocalizedString("导出失败", comment: "") alert.runModal() return } } progress: { status in } } } } extension KMOCRWindowController: KMOCRChooseViewDelegate { func exportAction(data: KMOCRModel) { KMPrint("export ocr success") } } extension KMOCRWindowController: KMBatchProcessingViewDelegate { func reloadData(data: [KMBatchProcessingTableViewModel]) { self.batchData = data } }