123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //
- // KMNSearchReplaceSearchItemView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/12/3.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNSearchReplaceSearchItemView: NSView {
- private lazy var previousButton_: ComponentButton = {
- let view = ComponentButton()
- view.properties = ComponentButtonProperty(type: .gray, size: .s, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaSearchPreviousDisable"))
- view.setTarget(self, action: #selector(previousAction))
- return view
- }()
-
- private lazy var nextButton_: ComponentButton = {
- let view = ComponentButton()
- view.properties = ComponentButtonProperty(type: .gray, size: .s, state: .normal, onlyIcon: true, icon: NSImage(named: "KMImageNameBotaSearchNext"))
- view.setTarget(self, action: #selector(nextActon))
- return view
- }()
-
- private lazy var input_: ComponentInput = {
- let view = ComponentInput()
- let prop = ComponentInputProperty()
- prop.size = .s
- prop.showPrefix = true
- prop.showSuffix = true
- view.properties = prop
- view.delegate = self
- return view
- }()
-
- var inputValue: String {
- set {
- input_.properties.text = newValue
- input_.reloadData()
- }
- get {
- return input_.properties.text
- }
- }
-
- var previousButton: ComponentButton {
- get {
- return previousButton_
- }
- }
-
- var nextButton: ComponentButton {
- get {
- return nextButton_
- }
- }
-
- var itemClick: KMCommonClickBlock?
- var valueDidChange: KMValueDidChangeBlock?
- var inputDidEditBlock: KMEmptyBlock?
-
- convenience init() {
- self.init(frame: .init(x: 0, y: 0, width: 300, height: 44))
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- initSubviews()
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- initSubviews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- initSubviews()
- }
-
- func initSubviews() {
- addSubview(nextButton_)
- addSubview(previousButton_)
- addSubview(input_)
-
- nextButton_.km_add_size_constraint(size: .init(width: 32, height: 32))
- nextButton_.km_add_top_constraint(constant: 0)
- nextButton_.km_add_trailing_constraint(constant: -24)
-
- previousButton_.km_add_size_constraint(size: .init(width: 32, height: 32))
- previousButton_.km_add_top_constraint(constant: 0)
- previousButton_.km_add_trailing_constraint(equalTo: nextButton_, attribute: .leading, constant: -8)
-
- input_.km_add_top_constraint(constant: 0)
- input_.km_add_leading_constraint(constant: 24)
- input_.km_add_height_constraint(constant: 32)
- input_.km_add_trailing_constraint(equalTo: previousButton_, attribute: .leading, constant: -8)
- }
-
- @objc func previousAction() {
- itemClick?(1)
- }
-
- @objc func nextActon() {
- itemClick?(2)
- }
- }
- extension KMNSearchReplaceSearchItemView: ComponentInputDelegate {
- func componentInputDidChanged(inputView: ComponentInput) {
- valueDidChange?(inputView.properties.text, nil)
- }
-
- func componentInputDidEndEditing(inputView: ComponentInput) {
- inputDidEditBlock?()
- }
- }
|