123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // NotiVC.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2024/9/14.
- //
- import Cocoa
- import KMComponentLibrary
- class NotiVC: NSViewController {
- @IBOutlet var notificationView: ComponentNotification!
-
- @IBOutlet var typeBox: NSComboBox!
- @IBOutlet var titleField: NSTextField!
- @IBOutlet var subTitleField: NSTextField!
- @IBOutlet weak var showImageAction: NSButton!
-
- @IBOutlet weak var viewHeightConst: NSLayoutConstraint!
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- self.typeBox.selectItem(at: 0)
- self.reloadData()
-
-
- 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)
-
-
- }
-
- func reloadData() {
-
- var image: NSImage? = ComponentLibrary.shared.image(forResource: "test")
-
- self.showImageAction.isEnabled = false
-
- var type: ComponentMessageType = .info
- if self.typeBox.indexOfSelectedItem == 1 {
- type = .success
- } else if self.typeBox.indexOfSelectedItem == 2 {
- type = .warning
- } else if self.typeBox.indexOfSelectedItem == 3 {
- type = .error
- } else if self.typeBox.indexOfSelectedItem == 4 {
- type = .normal_custom
- self.showImageAction.isEnabled = true
- if self.showImageAction.state == .off {
- image = nil
- }
- }
-
- let text = self.titleField.stringValue
- let subText = self.subTitleField.stringValue
-
- let firstBtnProperty = ComponentButtonProperty(type: .text_primary, size: .s, state: .normal, onlyIcon: false, showLeftIcon: false, showRightIcon: false, buttonText: "Later")
- let secondBtnProperty = ComponentButtonProperty(type: .primary, size: .s, state: .normal, onlyIcon: false, showLeftIcon: false, showRightIcon: false, buttonText: "View")
-
- let property: ComponentNotificationProperty = ComponentNotificationProperty(messageType: type,
- image: image,
- text: text,
- subText: subText,
- firstButtonProperty: firstBtnProperty,
- secondButtonProperty: secondBtnProperty)
-
- self.notificationView.properties = property
-
- self.viewHeightConst.constant = self.notificationView.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()
- }
- }
|