123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //
- // KMConvertOCRSettingItemView.swift
- // PDF Master
- //
- // Created by tangchao on 2022/12/6.
- //
- class KMConvertOCRSettingItemView: KMConvertBaseView {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var checkBox: NSBox!
- @IBOutlet weak var languageBox: NSBox!
-
- private var _checkVC: KMDesignButton?
- var checkVC: KMDesignButton? {
- get {
- return self._checkVC
- }
- }
-
- private var _languageVC: KMDesignSelect?
-
- private var _languageIndex: Int = 0
- var languageIndex: Int {
- get {
- return self._languageIndex
- }
- set {
- self._languageIndex = newValue
-
- self._languageVC?.selectItem(at: newValue)
- }
- }
-
- var lanugageDidSelected: KMValueDidChangeBlock?
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self._checkAction()
- }
-
- override func initSubViews() {
- super.initSubViews()
-
- self._checkVC = KMDesignButton(withType: .CheckBox)
- self.checkBox.contentView = self._checkVC!.view
-
- self._languageVC = KMDesignSelect(withType: .Combox)
- self.languageBox.contentView = self._languageVC?.view
- }
-
- override func initDefaultVlaue() {
- super.initDefaultVlaue()
-
- self.titleLabel.stringValue = NSLocalizedString("Text Recognition Settings", comment: "")
- self.titleLabel.textColor = NSColor(hex: "#616469")
- self.titleLabel.font = .SFProTextRegular(12)
-
- self.checkBox.fillColor = .clear
- self._checkVC?.target = self
- self._checkVC?.action = #selector(checkBoxAction)
- self._checkVC?.stringValue = NSLocalizedString("Recognize text if needed", comment: "")
- self._checkVC?.checkbox_radio()
- self._checkVC?.state = .Checked
-
- self.languageBox.fillColor = .clear
- self._languageVC?.delete = self
- self._languageVC?.isScrollPop = true
- self._languageVC?.removeAllItems()
- self._languageVC?.addItems(withObjectValues: KMPDFConvertManager.defaultManager.languages_asc_strings)
- if (self.languageIndex < self._languageVC!.numberOfItems) {
- self._languageVC?.selectItem(at: self.languageIndex)
- } else {
- self._languageVC?.selectItem(at: 2)
- }
- }
-
- @objc func checkBoxAction(sender: NSButton) {
- if let state = self._checkVC?.state {
- self._checkVC?.state = state == .Checked ? .Norm : .Checked
- }
-
- self._checkAction()
- }
-
- public func checkAction() {
- self._checkAction()
- }
-
- private func _checkAction() {
- guard let state = self._checkVC?.state else {
- return
- }
-
- self._languageVC?.enabled = state == .Checked
- }
- }
- extension KMConvertOCRSettingItemView: KMSelectPopButtonDelegate {
- func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
- if (obj.isEqual(to: self._languageVC)) {
- guard let index = self._languageVC?.indexOfSelectedItem, index >= 0 else {
- return
- }
- self._languageIndex = index
-
- guard let callback = self.lanugageDidSelected else {
- return
- }
- callback(index, nil)
- }
- }
- }
|