12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // KMTextFieldSheetController.swift
- // PDF Master
- //
- // Created by wanjun on 2023/10/7.
- //
- import Cocoa
- class KMTextFieldSheetController: NSWindowController {
-
- @IBOutlet weak var textField: NSTextField!
- @IBOutlet weak var okButton: NSButton!
- @IBOutlet weak var cancelButton: NSButton!
- @IBOutlet weak var pageBox: NSComboBox!
- @IBOutlet weak var pageLabel: NSTextField!
-
- var _stringValue: String?
- var callback: ((String) -> Void)?
-
- static var windowController: KMTextFieldSheetController?
-
- deinit {
- print(#function)
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- KMTextFieldSheetController.windowController = self
- pageLabel.stringValue = NSLocalizedString("Page:", comment: "")
- }
-
- var stringValue: String {
- get {
- return self.pageBox.stringValue
- }
- set {
- self.pageBox.stringValue = newValue
- }
- }
-
-
- @IBAction func okAction(_ sender: Any) {
- if let callback = callback, let sender = sender as? NSButton, sender == okButton {
- callback(stringValue)
- }
-
- if #available(macOS 10.13, *) {
- NSApp.endSheet(window!, returnCode: (sender as AnyObject).tag)
- } else {
- NSApp.endSheet(window!)
- }
- window!.orderOut(self)
- KMTextFieldSheetController.windowController = nil
- }
- }
|