KMConvertJsonSettingView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. override func draw(_ dirtyRect: NSRect) {
  18. super.draw(dirtyRect)
  19. // Drawing code here.
  20. }
  21. static func json_createFromNib(in bundle: Bundle = Bundle.main) -> Self? {
  22. let nibName = "KMConvertJsonSettingView"
  23. var topLevelArray: NSArray? = nil
  24. bundle.loadNibNamed(NSNib.Name(nibName), owner: nil, topLevelObjects: &topLevelArray)
  25. guard let results = topLevelArray else { return nil }
  26. let views = Array<Any>(results).filter { $0 is Self }
  27. return views.last as? Self
  28. }
  29. override func initSubViews() {
  30. super.initSubViews()
  31. extractTextRadio.properties = ComponentCheckBoxProperty(size: .s,
  32. state: .normal,
  33. isDisabled: false,
  34. showhelp: false,
  35. text: NSLocalizedString("Extract Text", comment: ""),
  36. checkboxType: .normal)
  37. extractTextRadio.setTarget(self, action: #selector(radioAction))
  38. extactTableRadio.properties = ComponentCheckBoxProperty(size: .s,
  39. state: .normal,
  40. isDisabled: false,
  41. showhelp: false,
  42. text: NSLocalizedString("Extract Tables", comment: ""),
  43. checkboxType: .normal)
  44. extactTableRadio.setTarget(self, action: #selector(radioAction))
  45. self.radioAction(sender: self.extractTextRadio)
  46. }
  47. override func initDefaultVlaue() {
  48. super.initDefaultVlaue()
  49. self.titleLabel.stringValue = NSLocalizedString("Json Worksheet Settings", comment: "")
  50. self.titleLabel.textColor = NSColor.km_init(hex: "#616469")
  51. self.titleLabel.font = .SFProTextRegularFont(12)
  52. self.setBox.borderWidth = 0
  53. self.ocrBox.borderWidth = 0
  54. self.pageRangeBox.borderWidth = 0
  55. }
  56. override func viewDidMoveToWindow() {
  57. super.viewDidMoveToWindow()
  58. if (self.ocrItemView == nil) {
  59. self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  60. self.ocrBox.contentView = self.ocrItemView
  61. }
  62. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  63. if (self.pageRangeItemView == nil) {
  64. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  65. self.pageRangeBox.contentView = self.pageRangeItemView
  66. }
  67. }
  68. @objc func radioAction(sender: ComponentRadio) {
  69. for radio in [self.extractTextRadio, self.extactTableRadio] {
  70. if sender.isEqual(to: radio) {
  71. radio?.properties.checkboxType = .selected
  72. } else {
  73. radio?.properties.checkboxType = .normal
  74. }
  75. radio?.reloadData()
  76. }
  77. if sender.isEqual(to: self.extractTextRadio) {
  78. self.extractIndex = 0
  79. } else if sender.isEqual(to: self.extactTableRadio) {
  80. self.extractIndex = 1
  81. }
  82. }
  83. }