123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- //
- // KMConvertExcelSettingView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/6.
- //
- import KMComponentLibrary
- class KMConvertExcelSettingView: KMConvertSettingView {
- @IBOutlet weak var excelSettingTitleLabel: NSTextField!
- @IBOutlet weak var tableFormatComboBox: NSComboBox!
-
- @IBOutlet weak var allContentsBox: NSBox!
- @IBOutlet weak var sheetBox: NSBox!
- @IBOutlet weak var onlyTableBox: NSBox!
- @IBOutlet weak var tableFormatBox: NSBox!
- @IBOutlet weak var onlyTextBox: NSBox!
-
- @IBOutlet weak var ocrBox: NSBox!
- @IBOutlet weak var pageRangeBox: NSBox!
- var selectedSettingIndex: Int = 0
- var selectedTableFormatIndex: Int = 0
- var selectedSheetIndex: Int = 0
-
- private var allContentRadio_: ComponentRadio = {
- let view = ComponentRadio()
- view.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: NSLocalizedString("All Content", comment: ""),
- checkboxType: .normal)
- return view
- }()
-
- private lazy var sheetSelect_: ComponentSelect = {
- let view = ComponentSelect()
-
- view.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: NSLocalizedString("", comment: ""))
- view.delegate = self
- return view
- }()
-
- private var onlyTableRadio_: ComponentRadio = {
- let view = ComponentRadio()
- view.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: NSLocalizedString("Only Table", comment: ""),
- checkboxType: .normal)
- return view
- }()
-
- private lazy var tableFormatSelect_: ComponentSelect = {
- let view = ComponentSelect()
-
- view.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: NSLocalizedString("", comment: ""))
- view.delegate = self
- return view
- }()
-
- private var onlyTextRadio_: ComponentRadio = {
- let view = ComponentRadio()
- view.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: NSLocalizedString("Only Text", comment: ""),
- checkboxType: .normal)
- return view
- }()
-
- override func awakeFromNib() {
- super.awakeFromNib()
- self.radioAction(sender: self.allContentRadio_)
- }
-
- override func initSubViews() {
- super.initSubViews()
-
- self.allContentsBox.contentView = self.allContentRadio_
- self.allContentRadio_.setTarget(self, action: #selector(radioAction))
-
- self.onlyTableBox.contentView = self.onlyTableRadio_
- self.onlyTableRadio_.setTarget(self, action: #selector(radioAction))
-
- self.onlyTextBox.contentView = self.onlyTextRadio_
- self.onlyTextRadio_.setTarget(self, action: #selector(radioAction))
-
- self.sheetBox.contentView = self.sheetSelect_
- var menuItemArr: [ComponentMenuitemProperty] = []
- for string in [NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")] {
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: string)
- menuItemArr.append(itemProperty)
- }
-
- sheetSelect_.updateMenuItemsArr(menuItemArr)
-
- sheetSelect_.selectItemAtIndex(0)
- sheetSelect_.properties.creatable = false
- sheetSelect_.properties.text = NSLocalizedString("Create Sheet for each Page", comment: "")
- sheetSelect_.reloadData()
-
- self.tableFormatBox.contentView = self.tableFormatSelect_
- var menuItemArr2: [ComponentMenuitemProperty] = []
- for string in [NSLocalizedString("Create Sheet for each Table", comment: ""),NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")] {
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: string)
- menuItemArr2.append(itemProperty)
- }
-
- tableFormatSelect_.updateMenuItemsArr(menuItemArr2)
-
- tableFormatSelect_.selectItemAtIndex(0)
- tableFormatSelect_.properties.creatable = false
- tableFormatSelect_.properties.text = NSLocalizedString("Create Sheet for each Table", comment: "")
- tableFormatSelect_.reloadData()
-
- self.tipView?.km_add_left_constraint(constant: 8)
- self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
- self.tipView?.km_add_right_constraint()
- self.tipView?.km_add_height_constraint(constant: 16+20+16)
- }
-
- override func initDefaultVlaue() {
- super.initDefaultVlaue()
-
- self.excelSettingTitleLabel.stringValue = NSLocalizedString("Excel Worksheet Settings", comment: "")
- self.excelSettingTitleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-
- self.allContentsBox.fillColor = .clear
- self.onlyTableBox.fillColor = .clear
- self.onlyTextBox.fillColor = .clear
- self.sheetBox.fillColor = .clear
- self.tableFormatBox.fillColor = .clear
- }
-
- override func viewDidMoveToWindow() {
- super.viewDidMoveToWindow()
-
- if (self.ocrItemView == nil) {
- self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
- self.ocrBox.contentView = self.ocrItemView
-
- self.ocrItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
- updateViewColor()
- }
- self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
- if (self.pageRangeItemView == nil) {
- self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
- self.pageRangeBox.contentView = self.pageRangeItemView
-
- self.pageRangeItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
- self.pageRangeItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- updateViewColor()
- }
-
- self.pageRangeItemView?.isHidden = self.isBatch
- }
-
- override func updateViewColor() {
- super.updateViewColor()
-
- KMMainThreadExecute {
- self.excelSettingTitleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- }
- }
-
- @objc func radioAction(sender: Any) {
- for radio in [self.allContentRadio_, self.onlyTableRadio_, self.onlyTextRadio_] {
- if (radio.isEqual(to: sender)) {
- radio.properties.checkboxType = .selected
- radio.reloadData()
- } else {
- radio.properties.checkboxType = .normal
- radio.reloadData()
- }
- }
-
- if self.onlyTableRadio_.properties.checkboxType == .selected {
- self.tableFormatSelect_.properties.isDisabled = false
- self.tableFormatSelect_.reloadData()
- self.sheetSelect_.properties.isDisabled = true
- self.sheetSelect_.reloadData()
-
- self.ocrItemView?.checkVC?.state = .None
- self.ocrItemView?.checkVC?.enabled = false
- self.ocrItemView?.checkAction()
-
- self.selectedSettingIndex = 1
- } else {
- if self.allContentRadio_.properties.checkboxType == .selected {
- self.tableFormatSelect_.properties.isDisabled = true
- self.tableFormatSelect_.reloadData()
- self.sheetSelect_.properties.isDisabled = false
- self.sheetSelect_.reloadData()
-
- self.selectedSettingIndex = 0
- } else {
- self.tableFormatSelect_.properties.isDisabled = true
- self.tableFormatSelect_.reloadData()
- self.sheetSelect_.properties.isDisabled = true
- self.sheetSelect_.reloadData()
-
- self.selectedSettingIndex = 2
- }
-
- self.ocrItemView?.checkVC?.enabled = true
- self.ocrItemView?.checkAction()
- }
- }
-
- override func reloadData() {
- allContentRadio_.properties.isDisabled = self.isDisable
- sheetSelect_.properties.isDisabled = self.isDisable
- onlyTableRadio_.properties.isDisabled = self.isDisable
- tableFormatSelect_.properties.isDisabled = self.isDisable
- onlyTextRadio_.properties.isDisabled = self.isDisable
- }
- }
- extension KMConvertExcelSettingView: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- guard let index = view?.indexOfSelect(), index >= 0 else {
- return
- }
-
- if self.sheetSelect_.isEqual(to: view) {
- self.selectedSheetIndex = max(index, 0)
- } else if self.tableFormatSelect_.isEqual(to: view) {
- self.selectedTableFormatIndex = max(index, 0)
- }
- }
- }
|