KMConvertOCRSettingItemView.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // KMConvertOCRSettingItemView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. class KMConvertOCRSettingItemView: KMConvertBaseView {
  8. @IBOutlet weak var titleLabel: NSTextField!
  9. @IBOutlet weak var checkBox: NSBox!
  10. @IBOutlet weak var languageBox: NSBox!
  11. private var _checkVC: KMDesignButton?
  12. var checkVC: KMDesignButton? {
  13. get {
  14. return self._checkVC
  15. }
  16. }
  17. private var _languageVC: KMDesignSelect?
  18. private var _languageIndex: Int = 0
  19. var languageIndex: Int {
  20. get {
  21. return self._languageIndex
  22. }
  23. set {
  24. self._languageIndex = newValue
  25. self._languageVC?.selectItem(at: newValue)
  26. }
  27. }
  28. var lanugageDidSelected: KMValueDidChangeBlock?
  29. override func awakeFromNib() {
  30. super.awakeFromNib()
  31. self._checkAction()
  32. }
  33. override func initSubViews() {
  34. super.initSubViews()
  35. self._checkVC = KMDesignButton(withType: .CheckBox)
  36. self.checkBox.contentView = self._checkVC!.view
  37. self._languageVC = KMDesignSelect(withType: .Combox)
  38. self.languageBox.contentView = self._languageVC?.view
  39. }
  40. override func initDefaultVlaue() {
  41. super.initDefaultVlaue()
  42. self.titleLabel.stringValue = NSLocalizedString("Text Recognition Settings", comment: "")
  43. self.titleLabel.textColor = NSColor(hex: "#616469")
  44. self.titleLabel.font = .SFProTextRegular(12)
  45. self.checkBox.fillColor = .clear
  46. self._checkVC?.target = self
  47. self._checkVC?.action = #selector(checkBoxAction)
  48. self._checkVC?.stringValue = NSLocalizedString("Recognize text if needed", comment: "")
  49. self._checkVC?.checkbox_radio()
  50. self._checkVC?.state = .Checked
  51. self.languageBox.fillColor = .clear
  52. self._languageVC?.delete = self
  53. self._languageVC?.isScrollPop = true
  54. self._languageVC?.removeAllItems()
  55. self._languageVC?.addItems(withObjectValues: KMPDFConvertManager.defaultManager.languages_asc_strings)
  56. if (self.languageIndex < self._languageVC!.numberOfItems) {
  57. self._languageVC?.selectItem(at: self.languageIndex)
  58. } else {
  59. self._languageVC?.selectItem(at: 2)
  60. }
  61. }
  62. @objc func checkBoxAction(sender: NSButton) {
  63. if let state = self._checkVC?.state {
  64. self._checkVC?.state = state == .Checked ? .Norm : .Checked
  65. }
  66. self._checkAction()
  67. }
  68. public func checkAction() {
  69. self._checkAction()
  70. }
  71. private func _checkAction() {
  72. guard let state = self._checkVC?.state else {
  73. return
  74. }
  75. self._languageVC?.enabled = state == .Checked
  76. }
  77. }
  78. extension KMConvertOCRSettingItemView: KMSelectPopButtonDelegate {
  79. func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
  80. if (obj.isEqual(to: self._languageVC)) {
  81. guard let index = self._languageVC?.indexOfSelectedItem, index >= 0 else {
  82. return
  83. }
  84. self._languageIndex = index
  85. guard let callback = self.lanugageDidSelected else {
  86. return
  87. }
  88. callback(index, nil)
  89. }
  90. }
  91. }