KMConvertJsonSettingView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // KMConvertJsonSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/10/29.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMConvertJsonSettingView: KMConvertSettingView {
  10. @IBOutlet weak var setBox: NSBox!
  11. @IBOutlet weak var titleLabel: NSTextField!
  12. @IBOutlet weak var extractTextRadio: ComponentRadio!
  13. @IBOutlet weak var extactTableRadio: ComponentRadio!
  14. @IBOutlet weak var ocrBox: NSBox!
  15. @IBOutlet weak var pageRangeBox: NSBox!
  16. var extractIndex = 0
  17. var jsonSettingAction: ((_ selectedIndex: Int) -> Void)?
  18. override func draw(_ dirtyRect: NSRect) {
  19. super.draw(dirtyRect)
  20. // Drawing code here.
  21. }
  22. static func json_createFromNib(in bundle: Bundle = Bundle.main) -> Self? {
  23. let nibName = "KMConvertJsonSettingView"
  24. var topLevelArray: NSArray? = nil
  25. bundle.loadNibNamed(NSNib.Name(nibName), owner: nil, topLevelObjects: &topLevelArray)
  26. guard let results = topLevelArray else { return nil }
  27. let views = Array<Any>(results).filter { $0 is Self }
  28. return views.last as? Self
  29. }
  30. override func initSubViews() {
  31. super.initSubViews()
  32. extractTextRadio.properties = ComponentCheckBoxProperty(size: .s,
  33. state: .normal,
  34. isDisabled: false,
  35. showhelp: false,
  36. text: NSLocalizedString("Extract Text", comment: ""),
  37. checkboxType: .normal)
  38. extractTextRadio.setTarget(self, action: #selector(radioAction))
  39. extactTableRadio.properties = ComponentCheckBoxProperty(size: .s,
  40. state: .normal,
  41. isDisabled: false,
  42. showhelp: false,
  43. text: NSLocalizedString("Extract Tables", comment: ""),
  44. checkboxType: .normal)
  45. extactTableRadio.setTarget(self, action: #selector(radioAction))
  46. self.radioAction(sender: self.extractTextRadio)
  47. }
  48. override func initDefaultVlaue() {
  49. super.initDefaultVlaue()
  50. self.titleLabel.stringValue = NSLocalizedString("Json Worksheet Settings", comment: "")
  51. self.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  52. self.setBox.borderWidth = 0
  53. self.ocrBox.borderWidth = 0
  54. self.pageRangeBox.borderWidth = 0
  55. }
  56. override func updateViewColor() {
  57. super.updateViewColor()
  58. KMMainThreadExecute {
  59. self.titleLabel.textColor = KMNColorTools.colorText_2()
  60. }
  61. }
  62. override func viewDidMoveToWindow() {
  63. super.viewDidMoveToWindow()
  64. if (self.ocrItemView == nil) {
  65. self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  66. self.ocrBox.contentView = self.ocrItemView
  67. self.ocrItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  68. updateViewColor()
  69. }
  70. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  71. if (self.pageRangeItemView == nil) {
  72. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  73. self.pageRangeBox.contentView = self.pageRangeItemView
  74. self.pageRangeItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  75. updateViewColor()
  76. }
  77. self.pageRangeItemView?.isHidden = self.isBatch
  78. }
  79. @objc func radioAction(sender: ComponentRadio) {
  80. for radio in [self.extractTextRadio, self.extactTableRadio] {
  81. if sender.isEqual(to: radio) {
  82. radio?.properties.checkboxType = .selected
  83. } else {
  84. radio?.properties.checkboxType = .normal
  85. }
  86. radio?.reloadData()
  87. }
  88. if sender.isEqual(to: self.extractTextRadio) {
  89. self.extractIndex = 0
  90. } else if sender.isEqual(to: self.extactTableRadio) {
  91. self.extractIndex = 1
  92. }
  93. jsonSettingAction?(self.extractIndex)
  94. }
  95. override func reloadData() {
  96. extractTextRadio.properties.isDisabled = self.isDisable
  97. extactTableRadio.properties.isDisabled = self.isDisable
  98. }
  99. }