KMNBotaHeaderSearchView.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // KMNBotaHeaderSearchView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/11/13.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNBotaHeaderSearchView: NSView, NibLoadable {
  10. @IBOutlet weak var leftBox: NSBox!
  11. @IBOutlet weak var searchBox: NSBox!
  12. @IBOutlet weak var rightBox: NSBox!
  13. @IBOutlet weak var bottomLine: NSView!
  14. var itemClick: KMCommonClickBlock?
  15. var valueDidChange: KMValueDidChangeBlock?
  16. var ignoreCase = false
  17. private var groupView_: ComponentGroup?
  18. private lazy var searchButton_: ComponentButton = {
  19. let view = ComponentButton()
  20. view.properties = ComponentButtonProperty(type: .text_gray, size: .xxxs, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaSearch"))
  21. return view
  22. }()
  23. private lazy var input_: ComponentInput = {
  24. let view = ComponentInput()
  25. view.properties = ComponentInputProperty(size: .s, placeholder: KMLocalizedString("Search"), text: "")
  26. return view
  27. }()
  28. private lazy var closeButton_: ComponentButton = {
  29. let view = ComponentButton()
  30. view.properties = ComponentButtonProperty(type: .text_gray_low, size: .xxs, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaClose"))
  31. return view
  32. }()
  33. override func draw(_ dirtyRect: NSRect) {
  34. super.draw(dirtyRect)
  35. // Drawing code here.
  36. }
  37. override func awakeFromNib() {
  38. super.awakeFromNib()
  39. leftBox.borderWidth = 0
  40. leftBox.contentView = searchButton_
  41. searchButton_.setTarget(self, action: #selector(_searchAction))
  42. searchBox.borderWidth = 0
  43. searchBox.contentView = input_
  44. input_.delegate = self
  45. rightBox.borderWidth = 0
  46. rightBox.contentView = closeButton_
  47. closeButton_.setTarget(self, action: #selector(_closeAction))
  48. }
  49. func clearInputData() {
  50. input_.properties.text = ""
  51. input_.reloadData()
  52. }
  53. @objc private func _searchAction() {
  54. itemClick?(1, searchButton_)
  55. }
  56. @objc private func _closeAction() {
  57. itemClick?(2)
  58. }
  59. }
  60. extension KMNBotaHeaderSearchView: ComponentInputDelegate {
  61. func componentInputDidChanged(inputView: ComponentInput) {
  62. valueDidChange?(inputView, [.newKey : inputView.properties.text])
  63. }
  64. }
  65. extension KMNBotaHeaderSearchView: ComponentGroupDelegate {
  66. func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
  67. ignoreCase = !ignoreCase
  68. KMPrint("componentGroupDidSelect \(ignoreCase)")
  69. itemClick?(1)
  70. }
  71. func componentGroupDidDismiss(group: ComponentGroup?) {
  72. searchButton_.properties.state = .normal
  73. searchButton_.reloadData()
  74. }
  75. }