Class FileDialog
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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 FileMode. If you want to use a custom title, disable this by setting ModeOverridesTitle to false.
public class FileDialog : ConfirmationDialog, IDisposable
- Inheritance
-
FileDialog
- Implements
- Inherited Members
Constructors
FileDialog()
public FileDialog()
Properties
Access
The file system access scope. See FileDialog.AccessEnum constants.
Warning: In Web builds, FileDialog cannot access the host file system. In sandboxed Linux and macOS environments, UseNativeDialog is automatically used to allow limited access to host file system.
public FileDialog.AccessEnum Access { get; set; }
Property Value
CurrentDir
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.
public string CurrentDir { get; set; }
Property Value
CurrentFile
The currently selected file of the file dialog.
public string CurrentFile { get; set; }
Property Value
CurrentPath
The currently selected file path of the file dialog.
public string CurrentPath { get; set; }
Property Value
FileMode
The dialog's open or save mode, which affects the selection behavior. See FileDialog.FileModeEnum.
public FileDialog.FileModeEnum FileMode { get; set; }
Property Value
Filters
The available file type filters. Each filter string in the array should be formatted like this: *.txt,*.doc;Text Files
. The description text of the filter is optional and can be omitted.
public string[] Filters { get; set; }
Property Value
- string[]
ModeOverridesTitle
If true, changing the FileMode property will set the window title accordingly (e.g. setting FileMode to OpenFile will change the window title to "Open a File").
public bool ModeOverridesTitle { get; set; }
Property Value
OptionCount
The number of additional OptionButtons and CheckBoxes in the dialog.
public int OptionCount { get; set; }
Property Value
RootSubfolder
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.
public string RootSubfolder { get; set; }
Property Value
ShowHiddenFiles
If true, the dialog will show hidden files.
Note: This property is ignored by native file dialogs on Linux.
public bool ShowHiddenFiles { get; set; }
Property Value
UseNativeDialog
If true, Access is set to Filesystem, and it is supported by the current DisplayServer, OS native dialog will be used instead of custom one.
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 GetGrantedPermissions() 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.
public bool UseNativeDialog { get; set; }
Property Value
Methods
AddFilter(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)".
public void AddFilter(string filter, string description = "")
Parameters
AddOption(string, string[], int)
Adds an additional OptionButton to the file dialog. If values
is empty, a CheckBox is added instead.
defaultValueIndex
should be an index of the value in the values
. If values
is empty it should be either 1
(checked), or 0
(unchecked).
public void AddOption(string name, string[] values, int defaultValueIndex)
Parameters
ClearFilters()
Clear all the added filters in the dialog.
public void ClearFilters()
DeselectAll()
Clear all currently selected items in the dialog.
public void DeselectAll()
GetLineEdit()
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.
public LineEdit GetLineEdit()
Returns
GetOptionDefault(int)
Returns the default value index of the OptionButton or CheckBox with index option
.
public int GetOptionDefault(int option)
Parameters
option
int
Returns
GetOptionName(int)
Returns the name of the OptionButton or CheckBox with index option
.
public string GetOptionName(int option)
Parameters
option
int
Returns
GetOptionValues(int)
Returns an array of values of the OptionButton with index option
.
public string[] GetOptionValues(int option)
Parameters
option
int
Returns
- string[]
GetSelectedOptions()
Returns a Dictionary with the selected values of the additional OptionButtons and/or CheckBoxes. Dictionary keys are names and values are selected value indices.
public Dictionary GetSelectedOptions()
Returns
GetVBox()
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 AddOption(string, string[], int) to add custom elements to the dialog instead.
public VBoxContainer GetVBox()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
Invalidate()
Invalidate and update the current dialog content list.
Note: This method does nothing on native file dialogs.
public void Invalidate()
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
SetOptionDefault(int, int)
Sets the default value index of the OptionButton or CheckBox with index option
.
public void SetOptionDefault(int option, int defaultValueIndex)
Parameters
SetOptionName(int, string)
Sets the name of the OptionButton or CheckBox with index option
.
public void SetOptionName(int option, string name)
Parameters
SetOptionValues(int, string[])
Sets the option values of the OptionButton with index option
.
public void SetOptionValues(int option, string[] values)
Parameters
Events
DirSelected
Emitted when the user selects a directory.
public event FileDialog.DirSelectedEventHandler DirSelected
Event Type
FileSelected
Emitted when the user selects a file by double-clicking it or pressing the OK button.
public event FileDialog.FileSelectedEventHandler FileSelected
Event Type
FilesSelected
Emitted when the user selects multiple files.
public event FileDialog.FilesSelectedEventHandler FilesSelected