ダイアログ

English

Windowはメッセージ、エラー、ファイル選択、フォルダ選択、保存のネイティブダイアログを提供します。

表示例

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

実行例

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

種類

メッセージ

メソッド 用途 戻り値
msg_box(title, description) 情報や確認事項を表示します。 Nil
msg_box_error(title, description) エラーを表示します。 Nil

ファイルとフォルダ

メソッド 用途 戻り値
open_file 開くファイルを選択します。 選択したパス、またはキャンセル時はnil
save_file 保存先のファイルを選択します。 選択したパス、またはキャンセル時はnil
open_folder 開くフォルダを選択します。 選択したパス、またはキャンセル時はnil

使い方

  • モーダル状態とフォーカスを正しく保つため、親となるWindowからダイアログを呼び出します。
  • open_file、open_folder、save_fileはキャンセル時にnilを返します。
  • 表示や細部の操作はOSのネイティブダイアログに従います。

APIリファレンス · Galleryソース