Godot Engine – Multi-platform 2D and 3D game engine
Add more customization to FileDialog
kobewi1c32c24913f9
diff --git a/doc/classes/FileDialog.xml b/doc/classes/FileDialog.xmlindex ac562436f2b..27ed042ab47 100644--- a/doc/classes/FileDialog.xml+++ b/doc/classes/FileDialog.xml@@ -223,6 +223,9 @@<member name="display_mode" type="int" setter="set_display_mode" getter="get_display_mode" enum="FileDialog.DisplayMode" default="0">Display mode of the dialog's file list.</member>+ <member name="drive_selector_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">+ If [code]true[/code], shows the drive select dropdown next to the current path.+ </member><member name="favorites_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">If [code]true[/code], shows the toggle favorite button and favorite list on the left side of the dialog.</member>@@ -243,6 +246,9 @@The available file type filters. Each filter string in the array should be formatted like this: [code]*.png,*.jpg,*.jpeg;Image Files;image/png,image/jpeg[/code]. The description text of the filter is optional and can be omitted. Both file extensions and MIME type should be always set.[b]Note:[/b] Embedded file dialogs and Windows file dialogs support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types.</member>+ <member name="filters_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">+ If [code]true[/code], shows the file extension filter dropdown next to the file name.+ </member><member name="folder_creation_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">If [code]true[/code], shows the button for creating new directories (when using [constant FILE_MODE_OPEN_DIR], [constant FILE_MODE_OPEN_ANY], or [constant FILE_MODE_SAVE_FILE]), and the context menu will have the "New Folder..." option.</member>@@ -255,6 +261,9 @@<member name="mode_overrides_title" type="bool" setter="set_mode_overrides_title" getter="is_mode_overriding_title" default="true">If [code]true[/code], changing the [member file_mode] property will set the window title accordingly (e.g. setting [member file_mode] to [constant FILE_MODE_OPEN_FILE] will change the window title to "Open a File").</member>+ <member name="navigation_buttons_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">+ If [code]true[/code], shows the go back/forward buttons on the toolbar.+ </member><member name="option_count" type="int" setter="set_option_count" getter="get_option_count" default="0">The number of additional [OptionButton]s and [CheckBox]es in the dialog.</member>@@ -354,7 +363,7 @@The dialog displays files as a list of filenames.</constant><constant name="CUSTOMIZATION_HIDDEN_FILES" value="0" enum="Customization">- Toggles visibility of the favorite button, and the favorite list on the left side of the dialog.+ If enabled, shows the toggle hidden files button.Equivalent to [member hidden_files_toggle_enabled].</constant><constant name="CUSTOMIZATION_CREATE_FOLDER" value="1" enum="Customization">@@ -389,6 +398,18 @@If enabled, the context menu will show the "Delete" option, which allows moving files and folders to trash.Equivalent to [member deleting_enabled].</constant>+ <constant name="CUSTOMIZATION_NAVIGATION_BUTTONS" value="9" enum="Customization">+ If enabled, shows the go back/forward buttons on the toolbar.+ Equivalent to [member navigation_buttons_enabled].+ </constant>+ <constant name="CUSTOMIZATION_DRIVE_SELECTOR" value="10" enum="Customization">+ If enabled, shows the drive select dropdown next to the current path.+ Equivalent to [member drive_selector_enabled].+ </constant>+ <constant name="CUSTOMIZATION_FILTERS" value="11" enum="Customization">+ If enabled, shows the file extension filter dropdown next to the file name.+ Equivalent to [member filters_enabled].+ </constant></constants><theme_items><theme_item name="file_disabled_color" data_type="color" type="Color" default="Color(1, 1, 1, 0.25)">diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cppindex 3d15587cbde..d3b8f0a2cbd 100644--- a/scene/gui/file_dialog.cpp+++ b/scene/gui/file_dialog.cpp@@ -1238,6 +1238,10 @@ void FileDialog::update_customization() {favorite_button->set_visible(customization_flags[CUSTOMIZATION_FAVORITES]);favorite_vbox->set_visible(customization_flags[CUSTOMIZATION_FAVORITES]);recent_vbox->set_visible(customization_flags[CUSTOMIZATION_RECENT]);+ dir_prev->set_visible(customization_flags[CUSTOMIZATION_NAVIGATION_BUTTONS]);+ dir_next->set_visible(customization_flags[CUSTOMIZATION_NAVIGATION_BUTTONS]);+ drives->set_visible(customization_flags[CUSTOMIZATION_DRIVE_SELECTOR]);+ filter->set_visible(customization_flags[CUSTOMIZATION_FILTERS]);}void FileDialog::clear_filename_filter() {@@ -2190,6 +2194,9 @@ void FileDialog::_bind_methods() {ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "layout_toggle_enabled"), "set_customization_flag_enabled", "is_customization_flag_enabled", CUSTOMIZATION_LAYOUT);ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "overwrite_warning_enabled"), "set_customization_flag_enabled", "is_customization_flag_enabled", CUSTOMIZATION_OVERWRITE_WARNING);ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "deleting_enabled"), "set_customization_flag_enabled", "is_customization_flag_enabled", CUSTOMIZATION_DELETE);+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "navigation_buttons_enabled"), "set_customization_flag_enabled", "is_customization_flag_enabled", CUSTOMIZATION_NAVIGATION_BUTTONS);+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "drive_selector_enabled"), "set_customization_flag_enabled", "is_customization_flag_enabled", CUSTOMIZATION_DRIVE_SELECTOR);+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "filters_enabled"), "set_customization_flag_enabled", "is_customization_flag_enabled", CUSTOMIZATION_FILTERS);ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_dir", PROPERTY_HINT_DIR, "", PROPERTY_USAGE_NONE), "set_current_dir", "get_current_dir");ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file", PROPERTY_HINT_FILE_PATH, "*", PROPERTY_USAGE_NONE), "set_current_file", "get_current_file");@@ -2222,6 +2229,9 @@ void FileDialog::_bind_methods() {BIND_ENUM_CONSTANT(CUSTOMIZATION_LAYOUT);BIND_ENUM_CONSTANT(CUSTOMIZATION_OVERWRITE_WARNING);BIND_ENUM_CONSTANT(CUSTOMIZATION_DELETE);+ BIND_ENUM_CONSTANT(CUSTOMIZATION_NAVIGATION_BUTTONS);+ BIND_ENUM_CONSTANT(CUSTOMIZATION_DRIVE_SELECTOR);+ BIND_ENUM_CONSTANT(CUSTOMIZATION_FILTERS);BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, FileDialog, thumbnail_size);BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, FileDialog, parent_folder);diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.hindex 92ec8070884..2513126caa8 100644--- a/scene/gui/file_dialog.h+++ b/scene/gui/file_dialog.h@@ -154,6 +154,9 @@ public:CUSTOMIZATION_LAYOUT,CUSTOMIZATION_OVERWRITE_WARNING,CUSTOMIZATION_DELETE,+ CUSTOMIZATION_NAVIGATION_BUTTONS,+ CUSTOMIZATION_DRIVE_SELECTOR,+ CUSTOMIZATION_FILTERS,CUSTOMIZATION_MAX};