KMPageEditSettingBaseWindowController.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // KMPageEditSettingBaseWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/12.
  6. //
  7. import Cocoa
  8. typealias KMPageEditSettingItemClick = (_ index: Int, _ value: Any) -> ()
  9. class KMPageEditSettingBaseWindowController: NSWindowController {
  10. @IBOutlet weak var contentWidthConst: NSLayoutConstraint!
  11. @IBOutlet weak var contentHeightConst: NSLayoutConstraint!
  12. @IBOutlet weak var titleLabel: NSTextField!
  13. @IBOutlet weak var contentBox: NSBox!
  14. @IBOutlet weak var funcButton: NSButton!
  15. @IBOutlet weak var cancelButton: NSButton!
  16. var settingView: KMPageEditSettingBaseView?
  17. private var myModel: KMPageEditSettingBaseModel?
  18. var model: KMPageEditSettingBaseModel? {
  19. get {
  20. return self.myModel
  21. }
  22. set {
  23. self.myModel = newValue
  24. }
  25. }
  26. var itemClick: KMPageEditSettingItemClick!
  27. convenience init(_ model: KMPageEditSettingBaseModel?) {
  28. self.init(windowNibName: "KMPageEditSettingBaseWindowController")
  29. self.model = model
  30. }
  31. override func windowDidLoad() {
  32. super.windowDidLoad()
  33. cancelButton.title = NSLocalizedString("Cancel", comment: "")
  34. cancelButton.isBordered = false
  35. cancelButton.wantsLayer = true
  36. cancelButton.layer?.borderWidth = 1
  37. cancelButton.layer?.borderColor = NSColor.black.cgColor
  38. cancelButton.layer?.cornerRadius = 4
  39. cancelButton.target = self
  40. cancelButton.action = #selector(cancelButtonAction)
  41. funcButton.isBordered = false
  42. funcButton.wantsLayer = true
  43. funcButton.layer?.cornerRadius = 4
  44. funcButton.target = self
  45. funcButton.action = #selector(funcButtonAction)
  46. }
  47. public func setWindowSize(_ size: NSSize) {
  48. self.contentWidthConst.constant = size.width
  49. self.contentHeightConst.constant = size.height-44-60
  50. }
  51. @objc func cancelButtonAction() {
  52. guard let callback = self.itemClick else {
  53. return
  54. }
  55. callback(1, "")
  56. }
  57. @objc func funcButtonAction() {
  58. guard let callback = self.itemClick else {
  59. return
  60. }
  61. callback(2, "")
  62. }
  63. }