// // AlertControllerVC.swift // PDF Reader Pro Edition // // Created by Niehaoyu on 2024/9/11. // import Cocoa import KMComponentLibrary class AlertControllerVC: NSViewController { @IBOutlet weak var leftBox: NSBox! @IBOutlet weak var alertItem: ComponentAlert! @IBOutlet weak var typeBox: NSComboBox! @IBOutlet weak var showTitleBtn: NSButton! @IBOutlet weak var showCancelBtn: NSButton! @IBOutlet weak var titleField: NSTextField! @IBOutlet weak var subTitleField: NSTextField! @IBOutlet weak var tagItem: ComponentTag! @IBOutlet weak var tagSizeBox: NSComboBox! @IBOutlet weak var tagTextField: NSTextField! @IBOutlet weak var tagRoundSecondaryBtn: NSButton! @IBOutlet var tagTypeBox: NSComboBox! @IBOutlet weak var tagWidthConst: NSLayoutConstraint! @IBOutlet weak var tagHeightConst: NSLayoutConstraint! override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.typeBox.selectItem(at: 0) self.tagTypeBox.selectItem(at: 0) self.reloadData() } override func viewDidLayout() { super.viewDidLayout() NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: titleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: titleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: titleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: subTitleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: subTitleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: subTitleField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: tagTextField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: tagTextField) NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: tagTextField) } func reloadData() { let type: ComponentMessageType = ComponentMessageType(rawValue: self.typeBox.indexOfSelectedItem)! var title: String = "" if self.showTitleBtn.state == .on { title = self.titleField.stringValue } let subTitle: String = self.subTitleField.stringValue let detailBtnString: String = "Detail" var cancelBtnString: String = "" if self.showCancelBtn.state == .on { cancelBtnString = "Cancel" } let property = ComponentAlertProperty(messageType: type, title: title, subTitle: subTitle, detailButtonString: detailBtnString, cancelButtonString: cancelBtnString) self.alertItem.properties = property self.alertItem.showInView(self.leftBox.contentView) //Tag var tagSize: ComponentSize = .m if self.tagSizeBox.indexOfSelectedItem == 1 { tagSize = .s } let tagText: String = self.tagTextField.stringValue let tagProperty = ComponentTagProperty(tagType: ComponentTagType(rawValue: self.tagTypeBox.indexOfSelectedItem)!, size: tagSize, state: .normal, isSelected: true, text: tagText) self.tagItem.properties = tagProperty self.tagWidthConst.constant = self.tagItem.properties.propertyInfo.viewWidth self.tagHeightConst.constant = self.tagItem.properties.propertyInfo.viewHeight } @IBAction func clickAction(_ sender: Any) { self.reloadData() } //MARK: - TextNotification @objc func textFieldDidBeginEditingNotification(_ notification: Notification) { } @objc func textFieldDidChangeNotification(_ notification: Notification) { self.reloadData() } @objc func textFieldDidEndEditingNotification(_ notification: Notification) { print("textFieldDidEndEditingNotification") self.reloadData() } }