// // KMConvertExcelSettingView.swift // PDF Master // // Created by tangchao on 2022/12/6. // 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 sheetView: KMDesignSelect? var tableFormatView: KMDesignSelect? var allContentsVC: KMDesignButton? var onlyTableVC: KMDesignButton? var onlyTextVC: KMDesignButton? var selectedSettingIndex: Int = 0 var selectedTableFormatIndex: Int = 0 var selectedSheetIndex: Int = 0 override func awakeFromNib() { super.awakeFromNib() self.radioAction(sender: self.allContentsVC!.button as Any) } override func initSubViews() { super.initSubViews() self.allContentsVC = KMDesignButton.init(withType: .RadioButton) self.allContentsBox.contentView = self.allContentsVC!.view self.onlyTableVC = KMDesignButton.init(withType: .RadioButton) self.onlyTableBox.contentView = self.onlyTableVC!.view self.onlyTextVC = KMDesignButton.init(withType: .RadioButton) self.onlyTextBox.contentView = self.onlyTextVC!.view let titles = ["All Content", "Only Table", "Only Text"] var i: Int = 0 for radio in [self.allContentsVC, self.onlyTableVC, self.onlyTextVC] { radio?.stringValue = NSLocalizedString(titles[i], comment: "") radio?.target = self radio?.action = #selector(self.radioAction(sender:)) radio?.checkbox_radio() i += 1 } self.sheetView = KMDesignSelect.init(withType: .Combox) self.sheetBox.contentView = self.sheetView!.view self.sheetView?.removeAllItems() self.sheetView?.addItems(withObjectValues: [NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")]) self.sheetView?.selectItem(at: 0) self.sheetView?.editable = false //默认属性,初始化可不设置 self.sheetView?.delete = self self.sheetView?.updateUI() self.tableFormatView = KMDesignSelect.init(withType: .Combox) self.tableFormatBox.contentView = self.tableFormatView!.view self.tableFormatView?.removeAllItems() self.tableFormatView?.addItems(withObjectValues: [NSLocalizedString("Create Sheet for each Table", comment: ""),NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")]) self.tableFormatView?.selectItem(at: 0) self.tableFormatView?.editable = false //默认属性,初始化可不设置 self.tableFormatView?.delete = self self.tableFormatView?.updateUI() 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.textColor = NSColor.km_init(hex: "#616469") self.excelSettingTitleLabel.font = .SFProTextSemiboldFont(12) 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?.languageIndex = self.ocrLanuguageIndex if (self.pageRangeItemView == nil) { self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib() self.pageRangeBox.contentView = self.pageRangeItemView // 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) } } @objc func radioAction(sender: Any) { for radio in [self.allContentsVC, self.onlyTableVC, self.onlyTextVC] { if ((radio?.button.isEqual(to: sender))!) { radio?.state = .Checked } else { radio?.state = .Norm } } if let state = self.onlyTableVC?.state, state == .Checked { self.tableFormatView?.enabled = true self.sheetView?.enabled = false //#if VERSION_DMG // let isExist = KMResourceDownload.manager().documentAIBundleIsExist() // if isExist { // self.ocrItemView?.checkVC?.state = .None // self.ocrItemView?.checkVC?.enabled = false // self.ocrItemView?.checkAction() // } //#else self.ocrItemView?.checkVC?.state = .None self.ocrItemView?.checkVC?.enabled = false self.ocrItemView?.checkAction() //#endif } else { if let state = self.allContentsVC?.state, state == .Checked { self.tableFormatView?.enabled = false self.sheetView?.enabled = true } else { self.tableFormatView?.enabled = false self.sheetView?.enabled = false } //#if VERSION_DMG // let isExist = KMResourceDownload.manager().documentAIBundleIsExist() // if isExist { // self.ocrItemView?.checkVC?.enabled = true // self.ocrItemView?.checkVC?.state = .Checked // self.ocrItemView?.checkAction() // } //#else self.ocrItemView?.checkVC?.enabled = true // self.ocrItemView?.checkVC?.state = .Checked self.ocrItemView?.checkAction() //#endif } if let state = self.allContentsVC?.state, state == .Checked { self.selectedSettingIndex = 0 } else if let state = self.onlyTableVC?.state, state == .Checked { self.selectedSettingIndex = 1 } else if let state = self.onlyTextVC?.state, state == .Checked { self.selectedSettingIndex = 2 } } } extension KMConvertExcelSettingView: KMSelectPopButtonDelegate { func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) { if (obj.isEqual(to: self.tableFormatView)) { if let index = self.tableFormatView?.indexOfSelectedItem, index >= 0 { self.selectedTableFormatIndex = index return } self.selectedTableFormatIndex = 0 } else if (obj.isEqual(to: self.sheetView)) { if let view = self.sheetView { self.selectedSheetIndex = max(view.indexOfSelectedItem, 0) } } } }