// // KMRedactToolbarController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/12/18. // import Cocoa import KMComponentLibrary @objc protocol KMRedactToolbarControllerDelegate: AnyObject { @objc optional func redactToolbarControllerDidButtonClick(controller: KMRedactToolbarController, buttonIndex: Int) } class KMRedactToolbarController: NSViewController { @IBOutlet var contendView: NSView! @IBOutlet var titleLabel: NSTextField! @IBOutlet var redactButton: ComponentButton! @IBOutlet var propertyButton: ComponentButton! @IBOutlet var applyButton: ComponentButton! @IBOutlet var exitButton: ComponentButton! weak open var delegate: KMRedactToolbarControllerDelegate? override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.setupProperty() self.updateUI() self.reloadData() } func setupProperty() { titleLabel.stringValue = KMLocalizedString("Redact") titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1") titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium") redactButton.properties = ComponentButtonProperty(type: .text_gray_opacity, size: .xs, state: .pressed, showLeftIcon: true, buttonText: KMLocalizedString("Redact"), icon: NSImage(named: "redact_sec_Toolbar"), keepPressState: true, identifier: "") propertyButton.properties = ComponentButtonProperty(type: .text_gray_opacity, size: .xs, state: .normal, showLeftIcon: true, buttonText: KMLocalizedString("Properties"), icon: NSImage(named: "redact_Properties"), keepPressState: false, identifier: "") applyButton.properties = ComponentButtonProperty(type: .primary, size: .xs, state: .normal, buttonText: KMLocalizedString("Apply"), keepPressState: false, identifier: "") exitButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .xs, state: .normal, buttonText: KMLocalizedString("Exit"), keepPressState: false, identifier: "") redactButton.setTarget(self, action: #selector(buttonClicked(_:))) propertyButton.setTarget(self, action: #selector(buttonClicked(_:))) applyButton.setTarget(self, action: #selector(buttonClicked(_:))) exitButton.setTarget(self, action: #selector(buttonClicked(_:))) } func updateUI() { self.contendView.wantsLayer = true self.contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor } func reloadData() { redactButton.reloadData() propertyButton.reloadData() applyButton.reloadData() exitButton.reloadData() } @objc func buttonClicked(_ sender: ComponentButton) { if sender == redactButton { } else if sender == propertyButton { delegate?.redactToolbarControllerDidButtonClick?(controller: self, buttonIndex: 1) } else if sender == applyButton { delegate?.redactToolbarControllerDidButtonClick?(controller: self, buttonIndex: 2) } else if sender == exitButton { delegate?.redactToolbarControllerDidButtonClick?(controller: self, buttonIndex: 3) } } }