123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- //
- // KMTextFieldSheetController.swift
- // PDF Reader Pro
- //
- // 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: "") + ":"
- self.cancelButton.title = NSLocalizedString("Cancel", comment: "")
- self.okButton.title = NSLocalizedString("OK", 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
- }
- }
|