CocoaExtension // Allow callAlert() to handle responses.

This commit is contained in:
ShikiSuen 2023-01-10 20:19:58 +08:00
parent a3310be0e3
commit 7ffb4b96d6
1 changed files with 6 additions and 2 deletions

View File

@ -49,12 +49,16 @@ extension NSWindowController {
} }
extension NSWindow { extension NSWindow {
public func callAlert(title: String, text: String? = nil) { @discardableResult public func callAlert(title: String, text: String? = nil) -> NSApplication.ModalResponse {
let alert = NSAlert() let alert = NSAlert()
alert.messageText = title alert.messageText = title
if let text = text { alert.informativeText = text } if let text = text { alert.informativeText = text }
alert.addButton(withTitle: NSLocalizedString("OK", comment: "")) alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
alert.beginSheetModal(for: self) var result: NSApplication.ModalResponse = .alertFirstButtonReturn
alert.beginSheetModal(for: self) { theResponce in
result = theResponce
}
return result
} }
} }