Dialogs
日本語
Window provides native message, error, file, folder, and save dialogs.
Appearance
Runnable example
require "uing"
UIng.init
window = UIng::Window.new("File Dialog Example", 620, 360, margined: true)
window.on_closing do
UIng.quit
true
end
status = UIng::Label.new("Choose an operation")
paths_display = UIng::MultilineEntry.new(wrapping: false, read_only: true)
open_file_button = UIng::Button.new("Open file")
open_file_button.on_clicked do
status.text = if path = window.open_file
paths_display.text = path
"Selected 1 file"
else
paths_display.text = ""
"Open file canceled"
end
end
open_files_button = UIng::Button.new("Open files")
open_files_button.on_clicked do
status.text = if paths = window.open_files
paths_display.text = paths.join("\n")
"Selected #{paths.size} files"
else
paths_display.text = ""
"Open files canceled"
end
end
open_folder_button = UIng::Button.new("Open folder")
open_folder_button.on_clicked do
status.text = if path = window.open_folder
paths_display.text = path
"Selected 1 folder"
else
paths_display.text = ""
"Open folder canceled"
end
end
open_folders_button = UIng::Button.new("Open folders")
open_folders_button.on_clicked do
status.text = if paths = window.open_folders
paths_display.text = paths.join("\n")
"Selected #{paths.size} folders"
else
paths_display.text = ""
"Open folders canceled"
end
end
save_file_button = UIng::Button.new("Save file")
save_file_button.on_clicked do
status.text = if path = window.save_file
paths_display.text = path
"Selected save path"
else
paths_display.text = ""
"Save file canceled"
end
end
buttons = UIng::Box.new(:horizontal, padded: true)
buttons.append(open_file_button)
buttons.append(open_files_button)
buttons.append(open_folder_button)
buttons.append(open_folders_button)
buttons.append(save_file_button)
box = UIng::Box.new(:vertical, padded: true)
box.append(UIng::Label.new("Native file and folder dialogs"))
box.append(buttons)
box.append(status)
box.append(paths_display, stretchy: true)
window.child = box
window.show
UIng.main
UIng.uninit
Types
Messages
| Method |
Purpose |
Return value |
msg_box(title, description) |
Shows information or a notice. |
Nil |
msg_box_error(title, description) |
Shows an error. |
Nil |
Files and folders
| Method |
Purpose |
Return value |
open_file |
Selects a file to open. |
The selected path, or nil if canceled. |
open_files |
Selects one or more files. |
An array of paths, or nil if canceled. |
save_file |
Selects a file to save. |
The selected path, or nil if canceled. |
open_folder |
Selects a folder to open. |
The selected path, or nil if canceled. |
open_folders |
Selects one or more folders. |
An array of paths, or nil if canceled. |
Usage notes
- Call dialogs from their parent Window so the platform can keep modality and focus correct.
- File and folder dialogs return
nil when canceled or if the dialog fails. The multiple-selection methods return one or more paths on success; selection order is unspecified.
- Appearance and detailed behavior follow the OS-native dialog.
API reference · Gallery source