KMConvertWordSettingView.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // KMConvertWordSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/6.
  6. //
  7. import KMComponentLibrary
  8. typealias KMConvertWordSettingViewLayoutSettingAction = (_ selectedIndex: Int) -> Void
  9. class KMConvertWordSettingView: KMConvertSettingView {
  10. @IBOutlet weak var pageSettingTitleLabel: NSTextField!
  11. @IBOutlet weak var saveFlowTextRadio: ComponentRadio!
  12. @IBOutlet weak var savePageLayoutRadio: ComponentRadio!
  13. @IBOutlet weak var textOCRBox: NSBox!
  14. @IBOutlet weak var pageRangeBox: NSBox!
  15. var layoutSettingAction: KMConvertWordSettingViewLayoutSettingAction?
  16. // 流排 0 框排 1
  17. var pageSettingSelectedIndex: Int = 0
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. saveFlowTextRadio.properties = ComponentCheckBoxProperty(size: .s,
  21. state: .normal,
  22. isDisabled: false,
  23. showhelp: false,
  24. text: NSLocalizedString("Retain Flowing Text", comment: ""),
  25. checkboxType: .normal)
  26. saveFlowTextRadio.setTarget(self, action: #selector(saveFlowTextRadioAction))
  27. savePageLayoutRadio.properties = ComponentCheckBoxProperty(size: .s,
  28. state: .normal,
  29. isDisabled: false,
  30. showhelp: false,
  31. text: NSLocalizedString("Retain Page Layout", comment: ""),
  32. checkboxType: .normal)
  33. savePageLayoutRadio.setTarget(self, action: #selector(savePageLayoutRadioAction))
  34. self._flowTextAction()
  35. }
  36. override func initSubViews() {
  37. super.initSubViews()
  38. self.tipView?.km_add_left_constraint(constant: 8)
  39. self.tipView?.km_add_top_constraint(equalTo: self.pageRangeBox, attribute: .bottom, constant: -5)
  40. self.tipView?.km_add_right_constraint()
  41. self.tipView?.km_add_height_constraint(constant: 16+20+16)
  42. }
  43. override func initDefaultVlaue() {
  44. super.initDefaultVlaue()
  45. self.pageSettingTitleLabel.stringValue = NSLocalizedString("Layout Settings", comment: "")
  46. self.pageSettingTitleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  47. }
  48. override func viewDidMoveToWindow() {
  49. super.viewDidMoveToWindow()
  50. if (self.ocrItemView == nil) {
  51. self.ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  52. self.textOCRBox.contentView = self.ocrItemView
  53. self.ocrItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  54. self.ocrItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  55. }
  56. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  57. if (self.pageRangeItemView == nil) {
  58. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  59. self.pageRangeBox.contentView = self.pageRangeItemView
  60. self.pageRangeItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  61. self.pageRangeItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  62. }
  63. self.pageRangeItemView?.isHidden = self.isBatch
  64. }
  65. @objc func saveFlowTextRadioAction(sender: AnyObject) {
  66. self._flowTextAction()
  67. }
  68. @objc func savePageLayoutRadioAction(sender: AnyObject) {
  69. self._pageLayoutAction()
  70. }
  71. // MARK: - Private Methods
  72. private func _flowTextAction() {
  73. self.saveFlowTextRadio.properties.checkboxType = .selected
  74. self.saveFlowTextRadio.reloadData()
  75. self.savePageLayoutRadio.properties.checkboxType = .normal
  76. self.savePageLayoutRadio.reloadData()
  77. self.pageSettingSelectedIndex = 0
  78. layoutSettingAction?(0)
  79. }
  80. private func _pageLayoutAction() {
  81. self.savePageLayoutRadio.properties.checkboxType = .selected
  82. self.savePageLayoutRadio.reloadData()
  83. self.saveFlowTextRadio.properties.checkboxType = .normal
  84. self.saveFlowTextRadio.reloadData()
  85. self.pageSettingSelectedIndex = 1
  86. layoutSettingAction?(1)
  87. }
  88. override func reloadData() {
  89. saveFlowTextRadio.properties.isDisabled = self.isDisable
  90. saveFlowTextRadio.reloadData()
  91. savePageLayoutRadio.properties.isDisabled = self.isDisable
  92. savePageLayoutRadio.reloadData()
  93. self.ocrItemView?.isDisable = self.isDisable
  94. }
  95. }