KMConvertExcelSettingView.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // KMConvertExcelSettingView.swift
  3. // PDF Master
  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(hex: "#616469")
  71. self.excelSettingTitleLabel.font = .SFProTextSemibold(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. self.ocrItemView?.checkVC?.state = .None
  106. self.ocrItemView?.checkVC?.enabled = false
  107. self.ocrItemView?.checkAction()
  108. } else {
  109. if let state = self.allContentsVC?.state, state == .Checked {
  110. self.tableFormatView?.enabled = false
  111. self.sheetView?.enabled = true
  112. } else {
  113. self.tableFormatView?.enabled = false
  114. self.sheetView?.enabled = false
  115. }
  116. self.ocrItemView?.checkVC?.enabled = true
  117. self.ocrItemView?.checkVC?.state = .Checked
  118. self.ocrItemView?.checkAction()
  119. }
  120. if let state = self.allContentsVC?.state, state == .Checked {
  121. self.selectedSettingIndex = 0
  122. } else if let state = self.onlyTableVC?.state, state == .Checked {
  123. self.selectedSettingIndex = 1
  124. } else if let state = self.onlyTextVC?.state, state == .Checked {
  125. self.selectedSettingIndex = 2
  126. }
  127. }
  128. }
  129. extension KMConvertExcelSettingView: KMSelectPopButtonDelegate {
  130. func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
  131. if (obj.isEqual(to: self.tableFormatView)) {
  132. if let index = self.tableFormatView?.indexOfSelectedItem, index >= 0 {
  133. self.selectedTableFormatIndex = index
  134. return
  135. }
  136. self.selectedTableFormatIndex = 0
  137. } else if (obj.isEqual(to: self.sheetView)) {
  138. if let view = self.sheetView {
  139. self.selectedSheetIndex = max(view.indexOfSelectedItem, 0)
  140. }
  141. }
  142. }
  143. }