From 7ffb4b96d606b2791293ed93453ace0e36e3889f Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 10 Jan 2023 20:19:58 +0800 Subject: [PATCH] CocoaExtension // Allow callAlert() to handle responses. --- .../CocoaExtension_NSWindowController.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift b/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift index 7f2d38cf..0b73e077 100644 --- a/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift +++ b/Packages/vChewing_CocoaExtension/Sources/CocoaExtension/CocoaExtension_NSWindowController.swift @@ -49,12 +49,16 @@ extension NSWindowController { } extension NSWindow { - public func callAlert(title: String, text: String? = nil) { + @discardableResult public func callAlert(title: String, text: String? = nil) -> NSApplication.ModalResponse { let alert = NSAlert() alert.messageText = title if let text = text { alert.informativeText = text } 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 } }