// // KMTextFieldSheetController.swift // Cisdem PDFMaster // // 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 } }