// // KMWatermarkSaveWindow.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/11/5. // import Cocoa import KMComponentLibrary class KMWatermarkSaveWindow: KMNBaseWindowController { @IBOutlet var contendView: NSView! @IBOutlet var titleLabel: NSTextField! @IBOutlet var nameLabel: NSTextField! @IBOutlet var nameInputView: ComponentInput! @IBOutlet var cancelButton: ComponentButton! @IBOutlet var saveButton: ComponentButton! public var saveHandler: ((String?) -> Void)! public var nameValue: String = "" override func windowDidLoad() { super.windowDidLoad() // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. setupProperty() } override func beginSheetFinish() { super.beginSheetFinish() reloadData() window?.makeFirstResponder(nil) nameInputView.beginEditing() } func setupProperty() { contendView.wantsLayer = true contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup").cgColor titleLabel.stringValue = KMLocalizedString("Add Watermark") titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1") titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium") nameLabel.stringValue = KMLocalizedString("Name:") nameLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor") nameLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-regular") nameInputView.properties = ComponentInputProperty(size: .m, state:.normal, showClear: true, placeholder: "", text: "") nameInputView.delegate = self cancelButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, buttonText: KMLocalizedString("Cancel"), keepPressState: false) cancelButton.setTarget(self, action: #selector(buttonClicked(_:))) saveButton.properties = ComponentButtonProperty(type: .primary, size: .s, buttonText: KMLocalizedString("Save"), keepPressState: false) saveButton.setTarget(self, action: #selector(buttonClicked(_:))) } func reloadData() { nameInputView.properties.text = nameValue nameInputView.reloadData() if nameValue.isEmpty == true { saveButton.properties.isDisabled = true } else { saveButton.properties.isDisabled = false } saveButton.reloadData() } //MARK: - action @objc func buttonClicked(_ sender: ComponentButton) { if sender == saveButton { guard let callback = self.saveHandler else { return } callback(nameInputView.properties.text) } self.own_closeEndSheet() } //MARK: - MouseEvent override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) window?.makeFirstResponder(nil) } } //MARK: - ComponentInputDelegate extension KMWatermarkSaveWindow: ComponentInputDelegate { func componentInputDidChanged(inputView: ComponentInput) { nameValue = inputView.properties.text reloadData() } func componentInputDidEndEditing(inputView: ComponentInput) { nameValue = inputView.properties.text reloadData() } }