// // KMConvertJsonSettingView.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/10/29. // import Cocoa import KMComponentLibrary class KMConvertJsonSettingView: KMConvertSettingView { @IBOutlet weak var setBox: NSBox! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var extractTextRadio: ComponentRadio! @IBOutlet weak var extactTableRadio: ComponentRadio! @IBOutlet weak var ocrBox: NSBox! @IBOutlet weak var pageRangeBox: NSBox! var extractIndex = 0 override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } static func json_createFromNib(in bundle: Bundle = Bundle.main) -> Self? { let nibName = "KMConvertJsonSettingView" var topLevelArray: NSArray? = nil bundle.loadNibNamed(NSNib.Name(nibName), owner: nil, topLevelObjects: &topLevelArray) guard let results = topLevelArray else { return nil } let views = Array(results).filter { $0 is Self } return views.last as? Self } override func initSubViews() { super.initSubViews() extractTextRadio.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: NSLocalizedString("Extract Text", comment: ""), checkboxType: .normal) extractTextRadio.setTarget(self, action: #selector(radioAction)) extactTableRadio.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: NSLocalizedString("Extract Tables", comment: ""), checkboxType: .normal) extactTableRadio.setTarget(self, action: #selector(radioAction)) self.radioAction(sender: self.extractTextRadio) } override func initDefaultVlaue() { super.initDefaultVlaue() self.titleLabel.stringValue = NSLocalizedString("Json Worksheet Settings", comment: "") self.titleLabel.textColor = NSColor.km_init(hex: "#616469") self.titleLabel.font = .SFProTextRegularFont(12) self.setBox.borderWidth = 0 self.ocrBox.borderWidth = 0 self.pageRangeBox.borderWidth = 0 } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() if (self.ocrItemView == nil) { self.ocrItemView = KMConvertOCRSettingItemView.createFromNib() self.ocrBox.contentView = self.ocrItemView } self.ocrItemView?.languageIndex = self.ocrLanuguageIndex if (self.pageRangeItemView == nil) { self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib() self.pageRangeBox.contentView = self.pageRangeItemView } } @objc func radioAction(sender: ComponentRadio) { for radio in [self.extractTextRadio, self.extactTableRadio] { if sender.isEqual(to: radio) { radio?.properties.checkboxType = .selected } else { radio?.properties.checkboxType = .normal } radio?.reloadData() } if sender.isEqual(to: self.extractTextRadio) { self.extractIndex = 0 } else if sender.isEqual(to: self.extactTableRadio) { self.extractIndex = 1 } } }