AlertControllerVC.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // AlertControllerVC.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/9/11.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class AlertControllerVC: NSViewController {
  10. @IBOutlet weak var leftBox: NSBox!
  11. @IBOutlet weak var alertItem: ComponentAlert!
  12. @IBOutlet weak var typeBox: NSComboBox!
  13. @IBOutlet weak var showTitleBtn: NSButton!
  14. @IBOutlet weak var showCancelBtn: NSButton!
  15. @IBOutlet weak var titleField: NSTextField!
  16. @IBOutlet weak var subTitleField: NSTextField!
  17. @IBOutlet weak var tagItem: ComponentTag!
  18. @IBOutlet weak var tagSizeBox: NSComboBox!
  19. @IBOutlet weak var tagTextField: NSTextField!
  20. @IBOutlet weak var tagRoundSecondaryBtn: NSButton!
  21. @IBOutlet var tagTypeBox: NSComboBox!
  22. @IBOutlet weak var tagWidthConst: NSLayoutConstraint!
  23. @IBOutlet weak var tagHeightConst: NSLayoutConstraint!
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. // Do view setup here.
  27. self.typeBox.selectItem(at: 0)
  28. self.tagTypeBox.selectItem(at: 0)
  29. self.reloadData()
  30. }
  31. override func viewDidLayout() {
  32. super.viewDidLayout()
  33. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: titleField)
  34. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: titleField)
  35. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: titleField)
  36. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: subTitleField)
  37. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: subTitleField)
  38. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: subTitleField)
  39. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: tagTextField)
  40. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: tagTextField)
  41. NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: tagTextField)
  42. }
  43. func reloadData() {
  44. let type: ComponentMessageType = ComponentMessageType(rawValue: self.typeBox.indexOfSelectedItem)!
  45. var title: String = ""
  46. if self.showTitleBtn.state == .on {
  47. title = self.titleField.stringValue
  48. }
  49. let subTitle: String = self.subTitleField.stringValue
  50. let detailBtnString: String = "Detail"
  51. var cancelBtnString: String = ""
  52. if self.showCancelBtn.state == .on {
  53. cancelBtnString = "Cancel"
  54. }
  55. let property = ComponentAlertProperty(messageType: type,
  56. title: title, subTitle: subTitle, detailButtonString: detailBtnString, cancelButtonString: cancelBtnString)
  57. self.alertItem.properties = property
  58. self.alertItem.showInView(self.leftBox.contentView)
  59. //Tag
  60. var tagSize: ComponentSize = .m
  61. if self.tagSizeBox.indexOfSelectedItem == 1 {
  62. tagSize = .s
  63. }
  64. let tagText: String = self.tagTextField.stringValue
  65. let tagProperty = ComponentTagProperty(tagType: ComponentTagType(rawValue: self.tagTypeBox.indexOfSelectedItem)!,
  66. size: tagSize,
  67. state: .normal,
  68. isSelected: true,
  69. text: tagText)
  70. self.tagItem.properties = tagProperty
  71. self.tagWidthConst.constant = self.tagItem.properties.propertyInfo.viewWidth
  72. self.tagHeightConst.constant = self.tagItem.properties.propertyInfo.viewHeight
  73. }
  74. @IBAction func clickAction(_ sender: Any) {
  75. self.reloadData()
  76. }
  77. //MARK: - TextNotification
  78. @objc func textFieldDidBeginEditingNotification(_ notification: Notification) {
  79. }
  80. @objc func textFieldDidChangeNotification(_ notification: Notification) {
  81. self.reloadData()
  82. }
  83. @objc func textFieldDidEndEditingNotification(_ notification: Notification) {
  84. print("textFieldDidEndEditingNotification")
  85. self.reloadData()
  86. }
  87. }