diff options
Diffstat (limited to 'examples/example_12_file_dialogs.nim')
| -rw-r--r-- | examples/example_12_file_dialogs.nim | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/example_12_file_dialogs.nim b/examples/example_12_file_dialogs.nim new file mode 100644 index 0000000..b1647c3 --- /dev/null +++ b/examples/example_12_file_dialogs.nim @@ -0,0 +1,44 @@ +# This example shows how to use the Open File and Save File As dialogs. + +import nigui + +app.init() + +var window = newWindow() +var mainContainer = newLayoutContainer(Layout_Vertical) +window.add(mainContainer) + +var buttons = newLayoutContainer(Layout_Horizontal) +mainContainer.add(buttons) + +var textArea = newTextArea() +mainContainer.add(textArea) + +var button1 = newButton("Open ...") +buttons.add(button1) +button1.onClick = proc(event: ClickEvent) = + var dialog = newOpenFileDialog() + dialog.title = "Test Open" + dialog.multiple = true + dialog.directory = "/run/media/user/Data/Temp/Downloads/" + dialog.run() + textArea.addLine($dialog.files.len & " files selected") + if dialog.files.len > 0: + for file in dialog.files: + textArea.addLine(file) + +var button2 = newButton("Save as ...") +buttons.add(button2) +button2.onClick = proc(event: ClickEvent) = + var dialog = SaveFileDialog() + dialog.title = "Test Save" + dialog.directory = "/run/media/user/Data/Temp/Downloads/" + dialog.defaultName = "default.txt" + dialog.run() + if dialog.file == "": + textArea.addLine("No path selected") + else: + textArea.addLine(dialog.file) + +window.show() +app.run() |
