// // KMOCRChooseView.swift // PDF Master // // Created by lizhe on 2022/12/7. // import Cocoa class KMOCRChooseView: KMBaseXibView { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var languageButton: NSButton! @IBOutlet weak var exportFormatLabel: NSTextField! @IBOutlet weak var exportPDFButton: NSButton! @IBOutlet weak var exportTXTButton: NSButton! lazy var presenter: KMOCRPresenter! = KMOCRPresenter() lazy var data: KMOCRModel! = KMOCRModel() var delegate: KMOCRChooseViewDelegate? deinit { } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) KMPrint("Drawing code here.") } override func setup() { super.setup() self.presenter.initPresenter(delegate: self, data: KMOCRModel()) } override func reloadData() { super.reloadData() if self.data.exportOptions.contains(.pdf) { self.exportPDFButton.state = .on } else { self.exportPDFButton.state = .off } if self.data.exportOptions.contains(.txt) { self.exportTXTButton.state = .on } else { self.exportTXTButton.state = .off } self.languageButton.title = self.data.languageDic[KMGOCRLanguageStringKey] as! String } } protocol KMOCRChooseViewAction {} extension KMOCRChooseView: KMOCRChooseViewAction { @IBAction func exportAction(_ sender: NSButton) { if self.data.exportFilePath == "" { KMBatchProcessingView.openfiles(window: self.window!) { openPanel in openPanel.prompt = "" openPanel.canChooseDirectories = true //是否允许选择目录 openPanel.canChooseFiles = false //是否可以选择文件 openPanel.allowsMultipleSelection = false //是否允许多选 } completion: { [unowned self](panel ,data) in if data.count != 0 { self.presenter.export(filePath: data.first!.path) } } } else { self.presenter.export(filePath: self.data.exportFilePath) } } @IBAction func languageAction(_ sender: NSButton) { self.presenter.selectLanguage(sender: sender) } @IBAction func exportTXTAction(_ sender: NSButton) { self.presenter.saveTXT(sender: sender) } @IBAction func exportPDFAction(_ sender: NSButton) { self.presenter.savePDF(sender: sender) } } extension KMOCRChooseView: KMOCRPresenterDelegate { func showData(presenter: KMOCRPresenter, data: KMOCRModel) { self.data = data self.reloadData() } func export(presenter: KMOCRPresenter, data: KMOCRModel) { if (self.delegate != nil) { self.delegate?.exportAction(data: data) } } } protocol KMOCRChooseViewDelegate: NSObject { /** 导出 */ func exportAction(data: KMOCRModel) }