KMConvertExcelSettingView.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // KMConvertExcelSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. import KMComponentLibrary
  8. class KMConvertExcelSettingView: KMConvertSettingView {
  9. @IBOutlet weak var excelSettingTitleLabel: NSTextField!
  10. @IBOutlet weak var tableFormatComboBox: NSComboBox!
  11. @IBOutlet weak var allContentsBox: NSBox!
  12. @IBOutlet weak var sheetBox: NSBox!
  13. @IBOutlet weak var onlyTableBox: NSBox!
  14. @IBOutlet weak var tableFormatBox: NSBox!
  15. @IBOutlet weak var onlyTextBox: NSBox!
  16. @IBOutlet weak var ocrBox: NSBox!
  17. @IBOutlet weak var pageRangeBox: NSBox!
  18. var selectedSettingIndex: Int = 0
  19. var selectedTableFormatIndex: Int = 0
  20. var selectedSheetIndex: Int = 0
  21. private var allContentRadio_: ComponentRadio = {
  22. let view = ComponentRadio()
  23. view.properties = ComponentCheckBoxProperty(size: .s,
  24. state: .normal,
  25. isDisabled: false,
  26. showhelp: false,
  27. text: NSLocalizedString("All Content", comment: ""),
  28. checkboxType: .normal)
  29. return view
  30. }()
  31. private lazy var sheetSelect_: ComponentSelect = {
  32. let view = ComponentSelect()
  33. view.properties = ComponentSelectProperties(size: .s,
  34. state: .normal,
  35. isDisabled: false,
  36. isError: false,
  37. leftIcon: false,
  38. placeholder: nil,
  39. errorText: nil,
  40. creatable: false,
  41. text: NSLocalizedString("", comment: ""))
  42. view.delegate = self
  43. return view
  44. }()
  45. private var onlyTableRadio_: ComponentRadio = {
  46. let view = ComponentRadio()
  47. view.properties = ComponentCheckBoxProperty(size: .s,
  48. state: .normal,
  49. isDisabled: false,
  50. showhelp: false,
  51. text: NSLocalizedString("Only Table", comment: ""),
  52. checkboxType: .normal)
  53. return view
  54. }()
  55. private lazy var tableFormatSelect_: ComponentSelect = {
  56. let view = ComponentSelect()
  57. view.properties = ComponentSelectProperties(size: .s,
  58. state: .normal,
  59. isDisabled: false,
  60. isError: false,
  61. leftIcon: false,
  62. placeholder: nil,
  63. errorText: nil,
  64. creatable: false,
  65. text: NSLocalizedString("", comment: ""))
  66. view.delegate = self
  67. return view
  68. }()
  69. private var onlyTextRadio_: ComponentRadio = {
  70. let view = ComponentRadio()
  71. view.properties = ComponentCheckBoxProperty(size: .s,
  72. state: .normal,
  73. isDisabled: false,
  74. showhelp: false,
  75. text: NSLocalizedString("Only Text", comment: ""),
  76. checkboxType: .normal)
  77. return view
  78. }()
  79. override func awakeFromNib() {
  80. super.awakeFromNib()
  81. self.radioAction(sender: self.allContentRadio_)
  82. }
  83. override func initSubViews() {
  84. super.initSubViews()
  85. self.allContentsBox.contentView = self.allContentRadio_
  86. self.allContentRadio_.setTarget(self, action: #selector(radioAction))
  87. self.onlyTableBox.contentView = self.onlyTableRadio_
  88. self.onlyTableRadio_.setTarget(self, action: #selector(radioAction))
  89. self.onlyTextBox.contentView = self.onlyTextRadio_
  90. self.onlyTextRadio_.setTarget(self, action: #selector(radioAction))
  91. self.sheetBox.contentView = self.sheetSelect_
  92. var menuItemArr: [ComponentMenuitemProperty] = []
  93. for string in [NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")] {
  94. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  95. itemSelected: false,
  96. isDisabled: false,
  97. keyEquivalent: nil,
  98. text: string)
  99. menuItemArr.append(itemProperty)
  100. }
  101. sheetSelect_.updateMenuItemsArr(menuItemArr)
  102. sheetSelect_.selectItemAtIndex(0)
  103. sheetSelect_.properties.creatable = false
  104. sheetSelect_.properties.text = NSLocalizedString("Create Sheet for each Page", comment: "")
  105. sheetSelect_.reloadData()
  106. self.tableFormatBox.contentView = self.tableFormatSelect_
  107. var menuItemArr2: [ComponentMenuitemProperty] = []
  108. for string in [NSLocalizedString("Create Sheet for each Table", comment: ""),NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")] {
  109. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  110. itemSelected: false,
  111. isDisabled: false,
  112. keyEquivalent: nil,
  113. text: string)
  114. menuItemArr2.append(itemProperty)
  115. }
  116. tableFormatSelect_.updateMenuItemsArr(menuItemArr2)
  117. tableFormatSelect_.selectItemAtIndex(0)
  118. tableFormatSelect_.properties.creatable = false
  119. tableFormatSelect_.properties.text = NSLocalizedString("Create Sheet for each Table", comment: "")
  120. tableFormatSelect_.reloadData()
  121. self.tipView?.km_add_left_constraint(constant: 8)
  122. self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  123. self.tipView?.km_add_right_constraint()
  124. self.tipView?.km_add_height_constraint(constant: 16+20+16)
  125. }
  126. override func initDefaultVlaue() {
  127. super.initDefaultVlaue()
  128. self.excelSettingTitleLabel.stringValue = NSLocalizedString("Excel Worksheet Settings", comment: "")
  129. self.excelSettingTitleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  130. self.allContentsBox.fillColor = .clear
  131. self.onlyTableBox.fillColor = .clear
  132. self.onlyTextBox.fillColor = .clear
  133. self.sheetBox.fillColor = .clear
  134. self.tableFormatBox.fillColor = .clear
  135. }
  136. override func viewDidMoveToWindow() {
  137. super.viewDidMoveToWindow()
  138. if (self.ocrItemView == nil) {
  139. self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  140. self.ocrBox.contentView = self.ocrItemView
  141. self.ocrItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  142. updateViewColor()
  143. }
  144. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  145. if (self.pageRangeItemView == nil) {
  146. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  147. self.pageRangeBox.contentView = self.pageRangeItemView
  148. self.pageRangeItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  149. self.pageRangeItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  150. updateViewColor()
  151. }
  152. self.pageRangeItemView?.isHidden = self.isBatch
  153. }
  154. override func updateViewColor() {
  155. super.updateViewColor()
  156. KMMainThreadExecute {
  157. self.excelSettingTitleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  158. }
  159. }
  160. @objc func radioAction(sender: Any) {
  161. for radio in [self.allContentRadio_, self.onlyTableRadio_, self.onlyTextRadio_] {
  162. if (radio.isEqual(to: sender)) {
  163. radio.properties.checkboxType = .selected
  164. radio.reloadData()
  165. } else {
  166. radio.properties.checkboxType = .normal
  167. radio.reloadData()
  168. }
  169. }
  170. if self.onlyTableRadio_.properties.checkboxType == .selected {
  171. self.tableFormatSelect_.properties.isDisabled = false
  172. self.tableFormatSelect_.reloadData()
  173. self.sheetSelect_.properties.isDisabled = true
  174. self.sheetSelect_.reloadData()
  175. self.ocrItemView?.checkVC?.state = .None
  176. self.ocrItemView?.checkVC?.enabled = false
  177. self.ocrItemView?.checkAction()
  178. self.selectedSettingIndex = 1
  179. } else {
  180. if self.allContentRadio_.properties.checkboxType == .selected {
  181. self.tableFormatSelect_.properties.isDisabled = true
  182. self.tableFormatSelect_.reloadData()
  183. self.sheetSelect_.properties.isDisabled = false
  184. self.sheetSelect_.reloadData()
  185. self.selectedSettingIndex = 0
  186. } else {
  187. self.tableFormatSelect_.properties.isDisabled = true
  188. self.tableFormatSelect_.reloadData()
  189. self.sheetSelect_.properties.isDisabled = true
  190. self.sheetSelect_.reloadData()
  191. self.selectedSettingIndex = 2
  192. }
  193. self.ocrItemView?.checkVC?.enabled = true
  194. self.ocrItemView?.checkAction()
  195. }
  196. }
  197. override func reloadData() {
  198. allContentRadio_.properties.isDisabled = self.isDisable
  199. sheetSelect_.properties.isDisabled = self.isDisable
  200. onlyTableRadio_.properties.isDisabled = self.isDisable
  201. tableFormatSelect_.properties.isDisabled = self.isDisable
  202. onlyTextRadio_.properties.isDisabled = self.isDisable
  203. }
  204. }
  205. extension KMConvertExcelSettingView: ComponentSelectDelegate {
  206. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  207. guard let index = view?.indexOfSelect(), index >= 0 else {
  208. return
  209. }
  210. if self.sheetSelect_.isEqual(to: view) {
  211. self.selectedSheetIndex = max(index, 0)
  212. } else if self.tableFormatSelect_.isEqual(to: view) {
  213. self.selectedTableFormatIndex = max(index, 0)
  214. }
  215. }
  216. }