Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
FileDialog¶
继承: ConfirmationDialog < AcceptDialog < Window < Viewport < Node < Object
用于选择文件系统中的文件或目录的对话框。
描述¶
FileDialog 是用来选择文件系统中文件和目录的预设对话框。支持过滤器掩码。FileDialog 会根据 file_mode 自动设置窗口的标题。如果你想使用自定义标题,请将 mode_overrides_title 设置为 false
,禁用此功能。
属性¶
|
||
dialog_hide_on_ok |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
title |
|
|
|
方法¶
void |
add_filter(filter: String, description: String = "") |
void |
add_option(name: String, values: PackedStringArray, default_value_index: int) |
void |
|
void |
|
get_option_default(option: int) const |
|
get_option_name(option: int) const |
|
get_option_values(option: int) const |
|
get_selected_options() const |
|
get_vbox() |
|
void |
|
void |
set_option_default(option: int, default_value_index: int) |
void |
set_option_name(option: int, name: String) |
void |
set_option_values(option: int, values: PackedStringArray) |
主题属性¶
|
||
|
||
|
||
信号¶
当用户选择一个目录时触发的。
当用户通过双击文件或按确定按钮选择一个文件时触发。
files_selected(paths: PackedStringArray) 🔗
当用户选择多个文件时触发。
枚举¶
enum FileMode: 🔗
FileMode FILE_MODE_OPEN_FILE = 0
该对话框只允许选择一个文件。
FileMode FILE_MODE_OPEN_FILES = 1
该对话框允许选择多个文件。
FileMode FILE_MODE_OPEN_DIR = 2
该对话框只允许选择一个目录,不允许选择任何文件。
FileMode FILE_MODE_OPEN_ANY = 3
该对话框允许选择一个文件或目录。
FileMode FILE_MODE_SAVE_FILE = 4
当文件存在时,对话框会发出警告。
enum Access: 🔗
Access ACCESS_RESOURCES = 0
该对话框只允许访问 Resource 路径下的文件(res://
)。
Access ACCESS_USERDATA = 1
该对话框只允许访问用户数据路径(user://
)下的文件。
Access ACCESS_FILESYSTEM = 2
该对话框允许访问文件系统上的文件。
属性说明¶
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.
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.
文件对话框的当前选定的文件。
当前选择的文件对话框的文件路径。
对话框的打开或保存模式,会影响选择行为。见 FileMode。
PackedStringArray filters = PackedStringArray()
🔗
void set_filters(value: PackedStringArray)
PackedStringArray get_filters()
可用文件类型过滤器。数组中的每个过滤器都应该使用类似 *.txt,*.doc;文本文件
的格式。过滤器的描述文本不是必填项,可以省略。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedStringArray for more details.
bool mode_overrides_title = true
🔗
如果为 true
,更改 file_mode 属性将相应地设置窗口标题(例如,将 file_mode 设置为 FILE_MODE_OPEN_FILE,会将窗口标题更改为“打开文件”)。
对话框中附加的 OptionButton 和 CheckBox 的数量。
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.
If true
, the dialog will show hidden files.
Note: This property is ignored by native file dialogs on Linux.
bool use_native_dialog = false
🔗
If true
, access is set to ACCESS_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 OS.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.
方法说明¶
void add_filter(filter: String, description: String = "") 🔗
将一个逗号分隔的文件名 filter
且带有可选 description
的选项添加到的 FileDialog,这限制了可以选择的文件。
filter
的格式应为 "文件名.扩展名"
,其中文件名和扩展名可以是 *
,以匹配任意字符串。不允许使用以 .
开头的过滤器(即空文件名)。
例如,"*.png, *.jpg"
的 filter
和 "图像"
的 description
会产生过滤器文本“图像 (* .png, *.jpg)”。
void add_option(name: String, values: PackedStringArray, default_value_index: int) 🔗
向文件对话框添加额外的 OptionButton。如果 values
为空,则添加的是 CheckBox。
default_value_index
应该是 values
的索引号。如果 values
为空,则应该是 1
(选中)或 0
(未选中)。
void clear_filters() 🔗
清除对话框中所有添加的过滤器。
void deselect_all() 🔗
清除对话框中所有当前选定的项目。
返回所选文件的 LineEdit。
警告:这是一个必需的内部节点,删除和释放它可能会导致崩溃。如果你希望隐藏它或其任何子项,请使用它们的 CanvasItem.visible 属性。
int get_option_default(option: int) const 🔗
返回索引为 option
的 OptionButton 或 CheckBox 的默认值索引。
String get_option_name(option: int) const 🔗
返回索引为 option
的 OptionButton 或 CheckBox 的名称。
PackedStringArray get_option_values(option: int) const 🔗
返回索引为 option
的 OptionButton 值的数组。
Dictionary get_selected_options() const 🔗
返回一个 Dictionary,其中包含附加 OptionButton 和/或 CheckBox 的选定值。Dictionary 的键是名称,而值是选定的值索引。
VBoxContainer 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 CanvasItem.visible property.
Note: Changes to this node are ignored by native file dialogs, use add_option to add custom elements to the dialog instead.
void invalidate() 🔗
Invalidate and update the current dialog content list.
Note: This method does nothing on native file dialogs.
void set_option_default(option: int, default_value_index: int) 🔗
设置索引为 option
的 OptionButton 或 CheckBox 的默认值索引。
void set_option_name(option: int, name: String) 🔗
设置索引为 option
的 OptionButton 或 CheckBox 的名称。
void set_option_values(option: int, values: PackedStringArray) 🔗
设置索引为 option
的 OptionButton 的选项值。
主题属性说明¶
Color file_disabled_color = Color(1, 1, 1, 0.25)
🔗
禁用文件的色调(当 FileDialog 在打开文件夹模式下使用时)。
Color file_icon_color = Color(1, 1, 1, 1)
🔗
应用于文件图标的颜色调制。
Color folder_icon_color = Color(1, 1, 1, 1)
🔗
应用于文件夹图标的颜色调制。
向后箭头的自定义图标。
用于创建文件夹按钮的自定义图标。
文件的自定义图标。
文件夹的自定义图标。
向前箭头的自定义图标。
父文件夹箭头的自定义图标。
重新加载按钮的自定义图标。
切换隐藏按钮的自定义图标。