123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // 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()
- }
- }
|