Dialogs

日本語

Window provides native message, error, file, folder, and save dialogs.

Appearance

File dialog on Ubuntu
Ubuntu
File dialog on Windows
Windows
File dialog on macOS
macOS

Runnable example

require "uing"

UIng.init

window = UIng::Window.new("File Dialog Example", 420, 180, margined: true)
window.on_closing do
  UIng.quit
  true
end

status = UIng::Label.new("Choose an operation")

open_file_button = UIng::Button.new("Open file")
open_file_button.on_clicked do
  status.text = if path = window.open_file
                  "Selected file: #{path}"
                else
                  "Open file canceled"
                end
end

open_folder_button = UIng::Button.new("Open folder")
open_folder_button.on_clicked do
  status.text = if path = window.open_folder
                  "Selected folder: #{path}"
                else
                  "Open folder canceled"
                end
end

save_file_button = UIng::Button.new("Save file")
save_file_button.on_clicked do
  status.text = if path = window.save_file
                  "Save to: #{path}"
                else
                  "Save file canceled"
                end
end

buttons = UIng::Box.new(:horizontal, padded: true)
buttons.append(open_file_button)
buttons.append(open_folder_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)

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.
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.

Usage notes

  • Call dialogs from their parent Window so the platform can keep modality and focus correct.
  • open_file, open_folder, and save_file return nil when canceled.
  • Appearance and detailed behavior follow the OS-native dialog.

API reference · Gallery source