KMHeaderFooterDateInfoView.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // KMHeaderFooterDateInfoView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/12/27.
  6. //
  7. import Cocoa
  8. class KMHeaderFooterDateInfoView: KMHeaderFooterAdjectiveInfoBaseView {
  9. var comboBox = NSComboBox()
  10. override func initSubviews() {
  11. super.initSubviews()
  12. self.addSubview(self.comboBox)
  13. self.titleLabel.stringValue = NSLocalizedString("Date:", comment: "")
  14. self.comboBox.addItems(withObjectValues: KMWatermarkAdjectiveTools.getDateFormats())
  15. self.comboBox.isEditable = false
  16. self.comboBox.delegate = self
  17. }
  18. override func layout() {
  19. super.layout()
  20. self.comboBox.frame = NSMakeRect(self.contentInset.left, self.titleLabel.frame.maxY+10, NSWidth(self.bounds)-self.contentInset.left-self.contentInset.right, 22)
  21. }
  22. override var model: KMHeaderFooterAdjectiveModel {
  23. get {
  24. return super.model
  25. }
  26. set {
  27. super.model = newValue
  28. let myModel: KMHeaderFooterObject = newValue as! KMHeaderFooterObject
  29. if (myModel.dateFormatString.isEmpty) {
  30. self.comboBox.stringValue = KMWatermarkAdjectiveTools.getDateFormats().first!
  31. } else {
  32. self.comboBox.stringValue = myModel.dateFormatString
  33. }
  34. }
  35. }
  36. }
  37. extension KMHeaderFooterDateInfoView: NSComboBoxDelegate {
  38. func comboBoxSelectionDidChange(_ notification: Notification) {
  39. if (self.comboBox.isEqual(to: notification.object)) {
  40. guard let callback = self.itemClick else {
  41. return
  42. }
  43. var index: Int = self.comboBox.indexOfSelectedItem
  44. if (index < 0) {
  45. index = 0
  46. }
  47. callback(1, KMWatermarkAdjectiveTools.getDateFormats()[index])
  48. }
  49. }
  50. }