KMConvertExcelSettingView.swift 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // KMConvertExcelSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. class KMConvertExcelSettingView: KMConvertSettingView {
  8. @IBOutlet weak var excelSettingTitleLabel: NSTextField!
  9. @IBOutlet weak var tableFormatComboBox: NSComboBox!
  10. @IBOutlet weak var allContentsBox: NSBox!
  11. @IBOutlet weak var sheetBox: NSBox!
  12. @IBOutlet weak var onlyTableBox: NSBox!
  13. @IBOutlet weak var tableFormatBox: NSBox!
  14. @IBOutlet weak var onlyTextBox: NSBox!
  15. @IBOutlet weak var ocrBox: NSBox!
  16. @IBOutlet weak var pageRangeBox: NSBox!
  17. var sheetView: KMDesignSelect?
  18. var tableFormatView: KMDesignSelect?
  19. var allContentsVC: KMDesignButton?
  20. var onlyTableVC: KMDesignButton?
  21. var onlyTextVC: KMDesignButton?
  22. var selectedSettingIndex: Int = 0
  23. var selectedTableFormatIndex: Int = 0
  24. var selectedSheetIndex: Int = 0
  25. override func awakeFromNib() {
  26. super.awakeFromNib()
  27. self.radioAction(sender: self.allContentsVC!.button as Any)
  28. }
  29. override func initSubViews() {
  30. super.initSubViews()
  31. self.allContentsVC = KMDesignButton.init(withType: .RadioButton)
  32. self.allContentsBox.contentView = self.allContentsVC!.view
  33. self.onlyTableVC = KMDesignButton.init(withType: .RadioButton)
  34. self.onlyTableBox.contentView = self.onlyTableVC!.view
  35. self.onlyTextVC = KMDesignButton.init(withType: .RadioButton)
  36. self.onlyTextBox.contentView = self.onlyTextVC!.view
  37. let titles = ["All Content", "Only Table", "Only Text"]
  38. var i: Int = 0
  39. for radio in [self.allContentsVC, self.onlyTableVC, self.onlyTextVC] {
  40. radio?.stringValue = NSLocalizedString(titles[i], comment: "")
  41. radio?.target = self
  42. radio?.action = #selector(self.radioAction(sender:))
  43. radio?.checkbox_radio()
  44. i += 1
  45. }
  46. self.sheetView = KMDesignSelect.init(withType: .Combox)
  47. self.sheetBox.contentView = self.sheetView!.view
  48. self.sheetView?.removeAllItems()
  49. self.sheetView?.addItems(withObjectValues: [NSLocalizedString("Create Sheet for each Page", comment: ""),NSLocalizedString("Create single Sheet for File", comment: "")])
  50. self.sheetView?.selectItem(at: 0)
  51. self.sheetView?.editable = false //默认属性,初始化可不设置
  52. self.sheetView?.delete = self
  53. self.sheetView?.updateUI()
  54. self.tableFormatView = KMDesignSelect.init(withType: .Combox)
  55. self.tableFormatBox.contentView = self.tableFormatView!.view
  56. self.tableFormatView?.removeAllItems()
  57. 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: "")])
  58. self.tableFormatView?.selectItem(at: 0)
  59. self.tableFormatView?.editable = false //默认属性,初始化可不设置
  60. self.tableFormatView?.delete = self
  61. self.tableFormatView?.updateUI()
  62. self.tipView?.km_add_left_constraint(constant: 8)
  63. self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  64. self.tipView?.km_add_right_constraint()
  65. self.tipView?.km_add_height_constraint(constant: 16+20+16)
  66. }
  67. override func initDefaultVlaue() {
  68. super.initDefaultVlaue()
  69. self.excelSettingTitleLabel.stringValue = NSLocalizedString("Excel Worksheet Settings", comment: "")
  70. self.excelSettingTitleLabel.textColor = NSColor.km_init(hex: "#616469")
  71. self.excelSettingTitleLabel.font = .SFProTextSemiboldFont(12)
  72. self.allContentsBox.fillColor = .clear
  73. self.onlyTableBox.fillColor = .clear
  74. self.onlyTextBox.fillColor = .clear
  75. self.sheetBox.fillColor = .clear
  76. self.tableFormatBox.fillColor = .clear
  77. }
  78. override func viewDidMoveToWindow() {
  79. super.viewDidMoveToWindow()
  80. if (self.ocrItemView == nil) {
  81. self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  82. self.ocrBox.contentView = self.ocrItemView
  83. }
  84. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  85. if (self.pageRangeItemView == nil) {
  86. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  87. self.pageRangeBox.contentView = self.pageRangeItemView
  88. // self.tipView?.km_add_left_constraint(constant: 8)
  89. // self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  90. // self.tipView?.km_add_right_constraint()
  91. // self.tipView?.km_add_height_constraint(constant: 16+20+16)
  92. }
  93. }
  94. @objc func radioAction(sender: Any) {
  95. for radio in [self.allContentsVC, self.onlyTableVC, self.onlyTextVC] {
  96. if ((radio?.button.isEqual(to: sender))!) {
  97. radio?.state = .Checked
  98. } else {
  99. radio?.state = .Norm
  100. }
  101. }
  102. if let state = self.onlyTableVC?.state, state == .Checked {
  103. self.tableFormatView?.enabled = true
  104. self.sheetView?.enabled = false
  105. //#if VERSION_DMG
  106. // let isExist = KMResourceDownload.manager().documentAIBundleIsExist()
  107. // if isExist {
  108. // self.ocrItemView?.checkVC?.state = .None
  109. // self.ocrItemView?.checkVC?.enabled = false
  110. // self.ocrItemView?.checkAction()
  111. // }
  112. //#else
  113. self.ocrItemView?.checkVC?.state = .None
  114. self.ocrItemView?.checkVC?.enabled = false
  115. self.ocrItemView?.checkAction()
  116. //#endif
  117. } else {
  118. if let state = self.allContentsVC?.state, state == .Checked {
  119. self.tableFormatView?.enabled = false
  120. self.sheetView?.enabled = true
  121. } else {
  122. self.tableFormatView?.enabled = false
  123. self.sheetView?.enabled = false
  124. }
  125. //#if VERSION_DMG
  126. // let isExist = KMResourceDownload.manager().documentAIBundleIsExist()
  127. // if isExist {
  128. // self.ocrItemView?.checkVC?.enabled = true
  129. // self.ocrItemView?.checkVC?.state = .Checked
  130. // self.ocrItemView?.checkAction()
  131. // }
  132. //#else
  133. self.ocrItemView?.checkVC?.enabled = true
  134. // self.ocrItemView?.checkVC?.state = .Checked
  135. self.ocrItemView?.checkAction()
  136. //#endif
  137. }
  138. if let state = self.allContentsVC?.state, state == .Checked {
  139. self.selectedSettingIndex = 0
  140. } else if let state = self.onlyTableVC?.state, state == .Checked {
  141. self.selectedSettingIndex = 1
  142. } else if let state = self.onlyTextVC?.state, state == .Checked {
  143. self.selectedSettingIndex = 2
  144. }
  145. }
  146. }
  147. extension KMConvertExcelSettingView: KMSelectPopButtonDelegate {
  148. func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
  149. if (obj.isEqual(to: self.tableFormatView)) {
  150. if let index = self.tableFormatView?.indexOfSelectedItem, index >= 0 {
  151. self.selectedTableFormatIndex = index
  152. return
  153. }
  154. self.selectedTableFormatIndex = 0
  155. } else if (obj.isEqual(to: self.sheetView)) {
  156. if let view = self.sheetView {
  157. self.selectedSheetIndex = max(view.indexOfSelectedItem, 0)
  158. }
  159. }
  160. }
  161. }