KMOCRChooseView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // KMOCRChooseView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2022/12/7.
  6. //
  7. import Cocoa
  8. class KMOCRChooseView: KMBaseXibView {
  9. @IBOutlet weak var titleLabel: NSTextField!
  10. @IBOutlet weak var languageButton: NSButton!
  11. @IBOutlet weak var exportFormatLabel: NSTextField!
  12. @IBOutlet weak var exportPDFButton: NSButton!
  13. @IBOutlet weak var exportTXTButton: NSButton!
  14. lazy var presenter: KMOCRPresenter! = KMOCRPresenter()
  15. lazy var data: KMOCRModel! = KMOCRModel()
  16. var delegate: KMOCRChooseViewDelegate?
  17. deinit {
  18. }
  19. override func draw(_ dirtyRect: NSRect) {
  20. super.draw(dirtyRect)
  21. KMPrint("Drawing code here.")
  22. }
  23. override func setup() {
  24. super.setup()
  25. self.presenter.initPresenter(delegate: self, data: KMOCRModel())
  26. }
  27. override func reloadData() {
  28. super.reloadData()
  29. if self.data.exportOptions.contains(.pdf) {
  30. self.exportPDFButton.state = .on
  31. } else {
  32. self.exportPDFButton.state = .off
  33. }
  34. if self.data.exportOptions.contains(.txt) {
  35. self.exportTXTButton.state = .on
  36. } else {
  37. self.exportTXTButton.state = .off
  38. }
  39. self.languageButton.title = self.data.languageDic[KMGOCRLanguageStringKey] as! String
  40. }
  41. }
  42. protocol KMOCRChooseViewAction {}
  43. extension KMOCRChooseView: KMOCRChooseViewAction {
  44. @IBAction func exportAction(_ sender: NSButton) {
  45. if self.data.exportFilePath == "" {
  46. KMBatchProcessingView.openfiles(window: self.window!) { openPanel in
  47. openPanel.prompt = ""
  48. openPanel.canChooseDirectories = true //是否允许选择目录
  49. openPanel.canChooseFiles = false //是否可以选择文件
  50. openPanel.allowsMultipleSelection = false //是否允许多选
  51. } completion: { [unowned self](panel ,data) in
  52. if data.count != 0 {
  53. self.presenter.export(filePath: data.first!.path)
  54. }
  55. }
  56. } else {
  57. self.presenter.export(filePath: self.data.exportFilePath)
  58. }
  59. }
  60. @IBAction func languageAction(_ sender: NSButton) {
  61. self.presenter.selectLanguage(sender: sender)
  62. }
  63. @IBAction func exportTXTAction(_ sender: NSButton) {
  64. self.presenter.saveTXT(sender: sender)
  65. }
  66. @IBAction func exportPDFAction(_ sender: NSButton) {
  67. self.presenter.savePDF(sender: sender)
  68. }
  69. }
  70. extension KMOCRChooseView: KMOCRPresenterDelegate {
  71. func showData(presenter: KMOCRPresenter, data: KMOCRModel) {
  72. self.data = data
  73. self.reloadData()
  74. }
  75. func export(presenter: KMOCRPresenter, data: KMOCRModel) {
  76. if (self.delegate != nil) {
  77. self.delegate?.exportAction(data: data)
  78. }
  79. }
  80. }
  81. protocol KMOCRChooseViewDelegate: NSObject {
  82. /**
  83. 导出
  84. */
  85. func exportAction(data: KMOCRModel)
  86. }