KMTextFieldSheetController.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // KMTextFieldSheetController.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2023/10/7.
  6. //
  7. import Cocoa
  8. class KMTextFieldSheetController: NSWindowController {
  9. @IBOutlet weak var textField: NSTextField!
  10. @IBOutlet weak var okButton: NSButton!
  11. @IBOutlet weak var cancelButton: NSButton!
  12. @IBOutlet weak var pageBox: NSComboBox!
  13. @IBOutlet weak var pageLabel: NSTextField!
  14. var _stringValue: String?
  15. var callback: ((String) -> Void)?
  16. static var windowController: KMTextFieldSheetController?
  17. deinit {
  18. print(#function)
  19. }
  20. override func windowDidLoad() {
  21. super.windowDidLoad()
  22. KMTextFieldSheetController.windowController = self
  23. pageLabel.stringValue = NSLocalizedString("Page:", comment: "")
  24. }
  25. var stringValue: String {
  26. get {
  27. return self.pageBox.stringValue
  28. }
  29. set {
  30. self.pageBox.stringValue = newValue
  31. }
  32. }
  33. @IBAction func okAction(_ sender: Any) {
  34. if let callback = callback, let sender = sender as? NSButton, sender == okButton {
  35. callback(stringValue)
  36. }
  37. if #available(macOS 10.13, *) {
  38. NSApp.endSheet(window!, returnCode: (sender as AnyObject).tag)
  39. } else {
  40. NSApp.endSheet(window!)
  41. }
  42. window!.orderOut(self)
  43. KMTextFieldSheetController.windowController = nil
  44. }
  45. }