diff --git a/examples/alertdialog.nim b/examples/alertdialog.nim new file mode 100644 index 0000000..fb40309 --- /dev/null +++ b/examples/alertdialog.nim @@ -0,0 +1,5 @@ +## Demonstrates windy alertDialog. +import windy + +alertDialog("Windy Alert", "macOS NSAlert is working.") +echo "alert closed" diff --git a/src/windy/platforms/macos/macdefs.nim b/src/windy/platforms/macos/macdefs.nim index dd951c0..c5518d4 100644 --- a/src/windy/platforms/macos/macdefs.nim +++ b/src/windy/platforms/macos/macdefs.nim @@ -74,6 +74,7 @@ type NSDictionary* = distinct NSObject NSOpenPanel* = distinct NSObject NSSavePanel* = distinct NSObject + NSAlert* = distinct NSObject NSURL* = distinct NSObject NSFileManager* = distinct NSObject @@ -186,6 +187,9 @@ objc: proc setAllowedFileTypes*(self: NSSavePanel, x: NSArray) proc runModal*(self: NSOpenPanel): int proc runModal*(self: NSSavePanel): int + proc setMessageText*(self: NSAlert, x: NSString) + proc setInformativeText*(self: NSAlert, x: NSString) + proc runModal*(self: NSAlert): int proc URLs*(self: NSOpenPanel): NSArray proc URL*(self: NSSavePanel): NSURL proc path*(self: NSURL): NSString diff --git a/src/windy/platforms/macos/platform.nim b/src/windy/platforms/macos/platform.nim index ce97b45..0940f80 100644 --- a/src/windy/platforms/macos/platform.nim +++ b/src/windy/platforms/macos/platform.nim @@ -1407,6 +1407,15 @@ proc allowedFileTypes(filters: seq[FileDialogFilter]): NSArray = return 0.NSArray result = (@(exts.join(","))).componentsSeparatedByString(@",") +proc alertDialog*(title, message: string) = + ## Pops a blocking alert dialog. + init() + autoreleasepool: + let alert = NSAlert.new() + alert.setMessageText(@title) + alert.setInformativeText(@message) + discard alert.runModal() + proc openFileDialog*( title = "Open File", filters: seq[FileDialogFilter] = @[],