Class FileDialog
A dialog for selecting files or directories in the filesystem.
- Inheritance
-
FileDialog
Remarks
FileDialog is a preset dialog used to choose files and directories in the filesystem. It supports filter masks. FileDialog automatically sets its window title according to the file_mode. If you want to use a custom title, disable this by setting mode_overrides_title to false
.
Properties
access
The file system access scope. See Access constants.
Warning: In Web builds, FileDialog cannot access the host file system. In sandboxed Linux and macOS environments, use_native_dialog is automatically used to allow limited access to host file system.
var access : int = 0
Property Value
Remarks
current_dir
The current working directory of the file dialog.
Note: For native file dialogs, this property is only treated as a hint and may not be respected by specific OS implementations.
var current_dir : String
Property Value
Remarks
current_file
The currently selected file of the file dialog.
var current_file : String
Property Value
Remarks
current_path
The currently selected file path of the file dialog.
var current_path : String
Property Value
Remarks
file_mode
The dialog's open or save mode, which affects the selection behavior. See FileMode.
var file_mode : int = 4
Property Value
Remarks
filename_filter
The filter for file names (case-insensitive). When set to a non-empty string, only files that contains the substring will be shown. filename_filter can be edited by the user with the filter button at the top of the file dialog.
See also filters, which should be used to restrict the file types that can be selected instead of filename_filter which is meant to be set by the user.
var filename_filter : String = ""
Property Value
Remarks
filters
The available file type filters. Each filter string in the array should be formatted like this: *.png,*.jpg,*.jpeg;Image Files;image/png,image/jpeg
. The description text of the filter is optional and can be omitted. Both file extensions and MIME type should be always set.
Note: Embedded file dialog and Windows file dialog support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types.
var filters : PackedStringArray = PackedStringArray()
Property Value
Remarks
- void set_filters(PackedStringArray value)
- PackedStringArray get_filters
mode_overrides_title
If true
, changing the file_mode property will set the window title accordingly (e.g. setting file_mode to FileDialog.FILE_MODE_OPEN_FILE will change the window title to "Open a File").
var mode_overrides_title : bool = true
Property Value
Remarks
option_count
The number of additional OptionButtons and CheckBoxes in the dialog.
var option_count : int = 0
Property Value
Remarks
root_subfolder
If non-empty, the given sub-folder will be "root" of this FileDialog, i.e. user won't be able to go to its parent directory.
Note: This property is ignored by native file dialogs.
var root_subfolder : String = ""
Property Value
Remarks
show_hidden_files
If true
, the dialog will show hidden files.
Note: This property is ignored by native file dialogs on Android and Linux.
var show_hidden_files : bool = false
Property Value
Remarks
use_native_dialog
If true
, and if supported by the current DisplayServer, OS native dialog will be used instead of custom one.
Note: On Android, it is only supported when using FileDialog.ACCESS_FILESYSTEM. For access mode FileDialog.ACCESS_RESOURCES and FileDialog.ACCESS_USERDATA, the system will fall back to custom FileDialog.
Note: On Linux and macOS, sandboxed apps always use native dialogs to access the host file system.
Note: On macOS, sandboxed apps will save security-scoped bookmarks to retain access to the opened folders across multiple sessions. Use get_granted_permissions to get a list of saved bookmarks.
Note: Native dialogs are isolated from the base process, file dialog properties can't be modified once the dialog is shown.
var use_native_dialog : bool = false
Property Value
Remarks
file_disabled_color
Theme Property
The color tint for disabled files (when the FileDialog is used in open folder mode).
= ``Color(1, 1, 1, 0.25)``
Property Value
file_icon_color
Theme Property
The color modulation applied to the file icon.
= ``Color(1, 1, 1, 1)``
Property Value
folder_icon_color
Theme Property
The color modulation applied to the folder icon.
= ``Color(1, 1, 1, 1)``
Property Value
back_folder
Theme Property
Custom icon for the back arrow.
Texture2D back_folder
Property Value
create_folder
Theme Property
Custom icon for the create folder button.
Texture2D create_folder
Property Value
file
Theme Property
Custom icon for files.
Texture2D file
Property Value
folder
Theme Property
Custom icon for folders.
Texture2D folder
Property Value
forward_folder
Theme Property
Custom icon for the forward arrow.
Texture2D forward_folder
Property Value
parent_folder
Theme Property
Custom icon for the parent folder arrow.
Texture2D parent_folder
Property Value
reload
Theme Property
Custom icon for the reload button.
Texture2D reload
Property Value
toggle_filename_filter
Theme Property
Custom icon for the toggle button for the filter for file names.
Texture2D toggle_filename_filter
Property Value
toggle_hidden
Theme Property
Custom icon for the toggle hidden button.
Texture2D toggle_hidden
Property Value
Methods
add_filter(String, String)
Adds a comma-delimited file name filter
option to the FileDialog with an optional description
, which restricts what files can be picked.
A filter
should be of the form "filename.extension"
, where filename and extension can be *
to match any string. Filters starting with .
(i.e. empty filenames) are not allowed.
For example, a filter
of "*.png, *.jpg"
and a description
of "Images"
results in filter text "Images (*.png, *.jpg)".
void add_filter(String filter, String description)
Parameters
add_option(String, PackedStringArray, int)
Adds an additional OptionButton to the file dialog. If values
is empty, a CheckBox is added instead.
default_value_index
should be an index of the value in the values
. If values
is empty it should be either 1
(checked), or 0
(unchecked).
void add_option(String name, PackedStringArray values, int default_value_index)
Parameters
name
Stringvalues
PackedStringArraydefault_value_index
int
clear_filename_filter
Clear the filter for file names.
void clear_filename_filter
clear_filters
Clear all the added filters in the dialog.
void clear_filters
deselect_all
Clear all currently selected items in the dialog.
void deselect_all
get_line_edit
Returns the LineEdit for the selected file.
Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their visible property.
LineEdit get_line_edit
get_option_default(int)
Qualifiers: const
Returns the default value index of the OptionButton or CheckBox with index option
.
int get_option_default(int option)
Parameters
option
int
get_option_name(int)
Qualifiers: const
Returns the name of the OptionButton or CheckBox with index option
.
String get_option_name(int option)
Parameters
option
int
get_option_values(int)
Qualifiers: const
Returns an array of values of the OptionButton with index option
.
PackedStringArray get_option_values(int option)
Parameters
option
int
get_selected_options
Qualifiers: const
Returns a Dictionary with the selected values of the additional OptionButtons and/or CheckBoxes. Dictionary keys are names and values are selected value indices.
Dictionary get_selected_options
get_vbox
Returns the vertical box container of the dialog, custom controls can be added to it.
Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their visible property.
Note: Changes to this node are ignored by native file dialogs, use FileDialog.add_option to add custom elements to the dialog instead.
VBoxContainer get_vbox
invalidate
Invalidate and update the current dialog content list.
Note: This method does nothing on native file dialogs.
void invalidate
set_option_default(int, int)
Sets the default value index of the OptionButton or CheckBox with index option
.
void set_option_default(int option, int default_value_index)
Parameters
set_option_name(int, String)
Sets the name of the OptionButton or CheckBox with index option
.
void set_option_name(int option, String name)
Parameters
set_option_values(int, PackedStringArray)
Sets the option values of the OptionButton with index option
.
void set_option_values(int option, PackedStringArray values)
Parameters
option
intvalues
PackedStringArray
Events
dir_selected(String)
Emitted when the user selects a directory.
signal dir_selected(String dir)
Parameters
dir
String
file_selected(String)
Emitted when the user selects a file by double-clicking it or pressing the OK button.
signal file_selected(String path)
Parameters
path
String
filename_filter_changed(String)
Emitted when the filter for file names changes.
signal filename_filter_changed(String filter)
Parameters
filter
String
files_selected(PackedStringArray)
Emitted when the user selects multiple files.
signal files_selected(PackedStringArray paths)
Parameters
paths
PackedStringArray