KMConvertHtmlSettingView.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // KMConvertHtmlSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/10/29.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMConvertHtmlSettingView: KMConvertSettingView {
  10. @IBOutlet weak var box: NSBox!
  11. @IBOutlet weak var titleLabel: NSTextField!
  12. @IBOutlet weak var pageBox: NSBox!
  13. @IBOutlet weak var ocrBox: NSBox!
  14. @IBOutlet weak var pageRangeBox: NSBox!
  15. var pageIndex = 0
  16. private lazy var pageSelect_: ComponentSelect = {
  17. let view = ComponentSelect()
  18. view.properties = ComponentSelectProperties(size: .s,
  19. state: .normal,
  20. isDisabled: false,
  21. isError: false,
  22. leftIcon: false,
  23. placeholder: nil,
  24. errorText: nil,
  25. creatable: false,
  26. text: "")
  27. view.delegate = self
  28. return view
  29. }()
  30. static func html_createFromNib(in bundle: Bundle = Bundle.main) -> Self? {
  31. let nibName = "KMConvertHtmlSettingView"
  32. var topLevelArray: NSArray? = nil
  33. bundle.loadNibNamed(NSNib.Name(nibName), owner: nil, topLevelObjects: &topLevelArray)
  34. guard let results = topLevelArray else { return nil }
  35. let views = Array<Any>(results).filter { $0 is Self }
  36. return views.last as? Self
  37. }
  38. override func draw(_ dirtyRect: NSRect) {
  39. super.draw(dirtyRect)
  40. // Drawing code here.
  41. }
  42. override func initSubViews() {
  43. super.initSubViews()
  44. self.pageBox.contentView = self.pageSelect_
  45. var menuItemArr: [ComponentMenuitemProperty] = []
  46. let strings: [String] = [NSLocalizedString("Single Page", comment: ""), NSLocalizedString("Single Page with Outlines", comment: ""),
  47. NSLocalizedString("Multiple Pages", comment: ""), NSLocalizedString("Multiple Pages with Outlines", comment: "")]
  48. for string in strings {
  49. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  50. itemSelected: false,
  51. isDisabled: false,
  52. keyEquivalent: nil,
  53. text: string)
  54. menuItemArr.append(itemProperty)
  55. }
  56. pageSelect_.updateMenuItemsArr(menuItemArr)
  57. pageSelect_.selectItemAtIndex(0)
  58. pageSelect_.properties.text = NSLocalizedString("Single Page", comment: "")
  59. pageSelect_.properties.creatable = false
  60. pageSelect_.reloadData()
  61. }
  62. override func initDefaultVlaue() {
  63. super.initDefaultVlaue()
  64. self.titleLabel.stringValue = NSLocalizedString("Page Options", comment: "")
  65. self.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  66. self.box.borderWidth = 0
  67. self.pageBox.borderWidth = 0
  68. self.ocrBox.borderWidth = 0
  69. self.pageRangeBox.borderWidth = 0
  70. }
  71. override func viewDidMoveToWindow() {
  72. super.viewDidMoveToWindow()
  73. if (ocrItemView == nil) {
  74. ocrItemView = KMConvertOCRSettingItemView.createFromNib()
  75. ocrBox.contentView = self.ocrItemView
  76. ocrItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  77. updateViewColor()
  78. }
  79. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  80. if (self.pageRangeItemView == nil) {
  81. self.pageRangeItemView = KMConvertPageRangeSettingItemView.createFromNib()
  82. self.pageRangeBox.contentView = self.pageRangeItemView
  83. pageRangeItemView?.titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  84. }
  85. }
  86. override func updateViewColor() {
  87. super.updateViewColor()
  88. KMMainThreadExecute {
  89. self.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  90. }
  91. }
  92. }
  93. extension KMConvertHtmlSettingView: ComponentSelectDelegate {
  94. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  95. guard let index = view?.indexOfSelect(), index >= 0 else {
  96. return
  97. }
  98. self.pageIndex = max(0, index)
  99. }
  100. }