123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // KMNSearchReplaceItemView.swift
- // PDF Reader Pro
- //
- // Created by User-Tangchao on 2024/12/2.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNSearchReplacePopItemView: KMNSearchReplaceItemView {
- override func initSubviews() {
- addSubview(input)
- addSubview(replaceAllButton)
- addSubview(replaceButton)
-
- input.km_add_leading_constraint(constant: 12)
- input.km_add_top_constraint(constant: 0)
- input.km_add_trailing_constraint(constant: -12)
- input.km_add_height_constraint(constant: 32)
-
- replaceButton.km_add_height_constraint(constant: 32)
- replaceButton.km_add_trailing_constraint(constant: -12)
- replaceButton.km_add_bottom_constraint()
- replaceButton.km_add_width_constraint(constant: replaceButton.properties.propertyInfo.viewWidth)
-
- replaceAllButton.km_add_height_constraint(constant: 32)
- replaceAllButton.km_add_trailing_constraint(equalTo: replaceButton, attribute: .leading, constant: -8)
- replaceAllButton.km_add_bottom_constraint()
- replaceAllButton.km_add_width_constraint(constant: replaceAllButton.properties.propertyInfo.viewWidth)
- }
- }
- class KMNSearchReplaceItemView: NSView {
- private lazy var input_: ComponentInput = {
- let view = ComponentInput()
- let prop = ComponentInputProperty()
- prop.size = .s
- prop.showPrefix = true
- prop.placeholder = KMLocalizedString("Replace with...")
- // KMImagenameBotaSearchInputPrefiex
- view.properties = prop
- view.delegate = self
- return view
- }()
-
- private lazy var replaceAllButton_: ComponentButton = {
- let view = ComponentButton()
- let prop = ComponentButtonProperty()
- prop.type = .default_tertiary
- prop.size = .xxs
- prop.buttonText = KMLocalizedString("Replace All")
- view.properties = prop
- view.setTarget(self, action: #selector(replaceAllAction))
- return view
- }()
-
- private lazy var replaceButton_: ComponentButton = {
- let view = ComponentButton()
- let prop = ComponentButtonProperty()
- prop.type = .primary
- prop.size = .xxs
- prop.buttonText = KMLocalizedString("Replace")
- view.properties = prop
- view.setTarget(self, action: #selector(replaceAction))
- return view
- }()
-
- var input: ComponentInput {
- get {
- return input_
- }
- }
-
- var replaceAllButton: ComponentButton {
- get {
- return replaceAllButton_
- }
- }
-
- var replaceButton: ComponentButton {
- get {
- return replaceButton_
- }
- }
-
- var inputValue: String {
- get {
- return input.properties.text
- }
- set {
- input.properties.text = newValue
- input.reloadData()
- }
- }
-
- var itemClick: KMCommonClickBlock?
- var valueDidChange: KMValueDidChangeBlock?
- var inputDidEditBlock: KMEmptyBlock?
-
- convenience init() {
- self.init(frame: .init(x: 0, y: 0, width: 300, height: 60))
-
- initSubviews()
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- initSubviews()
- }
-
- func initSubviews() {
- addSubview(input_)
- addSubview(replaceAllButton_)
- addSubview(replaceButton_)
-
- input_.km_add_leading_constraint(constant: 12)
- input_.km_add_top_constraint(constant: 8)
- input_.km_add_trailing_constraint(constant: -12)
- input_.km_add_height_constraint(constant: 32)
-
- replaceButton_.km_add_height_constraint(constant: 24)
- replaceButton_.km_add_trailing_constraint(constant: -12)
- replaceButton_.km_add_bottom_constraint()
- replaceButton_.km_add_width_constraint(constant: replaceButton_.properties.propertyInfo.viewWidth)
-
- replaceAllButton_.km_add_height_constraint(constant: 24)
- replaceAllButton_.km_add_trailing_constraint(equalTo: replaceButton_, attribute: .leading, constant: -8)
- replaceAllButton_.km_add_bottom_constraint()
- replaceAllButton_.km_add_width_constraint(constant: replaceAllButton_.properties.propertyInfo.viewWidth)
- }
-
- @objc func replaceAllAction() {
- itemClick?(1)
- }
-
- @objc func replaceAction() {
- itemClick?(2)
- }
- }
- extension KMNSearchReplaceItemView: ComponentInputDelegate {
- func componentInputDidChanged(inputView: ComponentInput) {
- valueDidChange?(inputView.properties.text, nil)
- }
-
- func componentInputDidEndEditing(inputView: ComponentInput) {
- inputDidEditBlock?()
- }
- }
|