123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // KMNBotaHeaderSearchView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/11/13.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNBotaHeaderSearchView: NSView, NibLoadable {
- @IBOutlet weak var leftBox: NSBox!
- @IBOutlet weak var searchBox: NSBox!
- @IBOutlet weak var rightBox: NSBox!
-
- @IBOutlet weak var bottomLine: NSView!
-
- var itemClick: KMCommonClickBlock?
- var valueDidChange: KMValueDidChangeBlock?
-
- var ignoreCase = false
-
- private var groupView_: ComponentGroup?
-
- private lazy var searchButton_: ComponentButton = {
- let view = ComponentButton()
- view.properties = ComponentButtonProperty(type: .text_gray, size: .xxxs, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaSearch"))
- return view
- }()
-
- private lazy var input_: ComponentInput = {
- let view = ComponentInput()
- view.properties = ComponentInputProperty(size: .s, placeholder: KMLocalizedString("Search"), text: "")
- return view
- }()
-
- private lazy var closeButton_: ComponentButton = {
- let view = ComponentButton()
- view.properties = ComponentButtonProperty(type: .text_gray_low, size: .xxs, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaClose"))
- return view
- }()
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- leftBox.borderWidth = 0
- leftBox.contentView = searchButton_
- searchButton_.setTarget(self, action: #selector(_searchAction))
-
- searchBox.borderWidth = 0
- searchBox.contentView = input_
- input_.delegate = self
-
- rightBox.borderWidth = 0
- rightBox.contentView = closeButton_
- closeButton_.setTarget(self, action: #selector(_closeAction))
- }
-
- func clearInputData() {
- input_.properties.text = ""
- input_.reloadData()
- }
-
- @objc private func _searchAction() {
- itemClick?(1, searchButton_)
- }
-
- @objc private func _closeAction() {
- itemClick?(2)
- }
- }
- extension KMNBotaHeaderSearchView: ComponentInputDelegate {
- func componentInputDidChanged(inputView: ComponentInput) {
- valueDidChange?(inputView, [.newKey : inputView.properties.text])
- }
- }
- extension KMNBotaHeaderSearchView: ComponentGroupDelegate {
- func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
- ignoreCase = !ignoreCase
- KMPrint("componentGroupDidSelect \(ignoreCase)")
- itemClick?(1)
- }
-
- func componentGroupDidDismiss(group: ComponentGroup?) {
- searchButton_.properties.state = .normal
- searchButton_.reloadData()
- }
- }
|