KMNSearchReplaceSearchItemView.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // KMNSearchReplaceSearchItemView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/12/3.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNSearchReplaceSearchItemView: NSView {
  10. private lazy var previousButton_: ComponentButton = {
  11. let view = ComponentButton()
  12. view.properties = ComponentButtonProperty(type: .gray, size: .s, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaSearchPreviousDisable"))
  13. view.setTarget(self, action: #selector(previousAction))
  14. return view
  15. }()
  16. private lazy var nextButton_: ComponentButton = {
  17. let view = ComponentButton()
  18. view.properties = ComponentButtonProperty(type: .gray, size: .s, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaSearchNext"))
  19. view.setTarget(self, action: #selector(nextActon))
  20. return view
  21. }()
  22. private lazy var input_: ComponentInput = {
  23. let view = ComponentInput()
  24. let prop = ComponentInputProperty()
  25. prop.size = .s
  26. prop.showPrefix = true
  27. prop.showSuffix = true
  28. view.properties = prop
  29. view.delegate = self
  30. return view
  31. }()
  32. var inputValue: String {
  33. set {
  34. input_.properties.text = newValue
  35. input_.reloadData()
  36. }
  37. get {
  38. return input_.properties.text
  39. }
  40. }
  41. var previousButton: ComponentButton {
  42. get {
  43. return previousButton_
  44. }
  45. }
  46. var nextButton: ComponentButton {
  47. get {
  48. return nextButton_
  49. }
  50. }
  51. var itemClick: KMCommonClickBlock?
  52. var valueDidChange: KMValueDidChangeBlock?
  53. var inputDidEditBlock: KMEmptyBlock?
  54. convenience init() {
  55. self.init(frame: .init(x: 0, y: 0, width: 300, height: 44))
  56. }
  57. override func awakeFromNib() {
  58. super.awakeFromNib()
  59. initSubviews()
  60. }
  61. override init(frame frameRect: NSRect) {
  62. super.init(frame: frameRect)
  63. initSubviews()
  64. }
  65. required init?(coder: NSCoder) {
  66. super.init(coder: coder)
  67. initSubviews()
  68. }
  69. func initSubviews() {
  70. addSubview(nextButton_)
  71. addSubview(previousButton_)
  72. addSubview(input_)
  73. nextButton_.km_add_size_constraint(size: .init(width: 32, height: 32))
  74. nextButton_.km_add_top_constraint(constant: 0)
  75. nextButton_.km_add_trailing_constraint(constant: -24)
  76. previousButton_.km_add_size_constraint(size: .init(width: 32, height: 32))
  77. previousButton_.km_add_top_constraint(constant: 0)
  78. previousButton_.km_add_trailing_constraint(equalTo: nextButton_, attribute: .leading, constant: -8)
  79. input_.km_add_top_constraint(constant: 0)
  80. input_.km_add_leading_constraint(constant: 24)
  81. input_.km_add_height_constraint(constant: 32)
  82. input_.km_add_trailing_constraint(equalTo: previousButton_, attribute: .leading, constant: -8)
  83. }
  84. @objc func previousAction() {
  85. itemClick?(1)
  86. }
  87. @objc func nextActon() {
  88. itemClick?(2)
  89. }
  90. }
  91. extension KMNSearchReplaceSearchItemView: ComponentInputDelegate {
  92. func componentInputDidChanged(inputView: ComponentInput) {
  93. valueDidChange?(inputView.properties.text, nil)
  94. }
  95. func componentInputDidEndEditing(inputView: ComponentInput) {
  96. inputDidEditBlock?()
  97. }
  98. }