Allow customizing FileDialog's features

This commit is contained in:
kobewi
2025-05-21 16:41:18 +02:00
parent fc523ec5f6
commit 4b1d5b55c7
3 changed files with 171 additions and 18 deletions

View File

@ -96,6 +96,21 @@
[b]Note:[/b] This method does nothing on native file dialogs.
</description>
</method>
<method name="is_customization_flag_enabled" qualifiers="const">
<return type="bool" />
<param index="0" name="flag" type="int" enum="FileDialog.Customization" />
<description>
Returns [code]true[/code] if the provided [param flag] is enabled.
</description>
</method>
<method name="set_customization_flag_enabled">
<return type="void" />
<param index="0" name="flag" type="int" enum="FileDialog.Customization" />
<param index="1" name="enabled" type="bool" />
<description>
Toggles the specified customization [param flag], allowing to customize features available in this [FileDialog]. See [enum Customization] for options.
</description>
</method>
<method name="set_option_default">
<return type="void" />
<param index="0" name="option" type="int" />
@ -140,9 +155,18 @@
<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="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>
<member name="file_filter_toggle_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">
If [code]true[/code], shows the toggle file filter button.
</member>
<member name="file_mode" type="int" setter="set_file_mode" getter="get_file_mode" enum="FileDialog.FileMode" default="4">
The dialog's open or save mode, which affects the selection behavior.
</member>
<member name="file_sort_options_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">
If [code]true[/code], shows the file sorting options button.
</member>
<member name="filename_filter" type="String" setter="set_filename_filter" getter="get_filename_filter" default="&quot;&quot;">
The filter for file names (case-insensitive). When set to a non-empty string, only files that contains the substring will be shown. [member filename_filter] can be edited by the user with the filter button at the top of the file dialog.
See also [member filters], which should be used to restrict the file types that can be selected instead of [member filename_filter] which is meant to be set by the user.
@ -151,12 +175,24 @@
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 dialog and Windows file dialog support only file extensions, while Android, Linux, and macOS file dialogs also support MIME types.
</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]).
</member>
<member name="hidden_files_toggle_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">
If [code]true[/code], shows the toggle hidden files button.
</member>
<member name="layout_toggle_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">
If [code]true[/code], shows the layout switch buttons (list/thumbnails).
</member>
<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="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>
<member name="recent_list_enabled" type="bool" setter="set_customization_flag_enabled" getter="is_customization_flag_enabled" default="true">
If [code]true[/code], shows the recent directories list on the left side of the dialog.
</member>
<member name="root_subfolder" type="String" setter="set_root_subfolder" getter="get_root_subfolder" default="&quot;&quot;">
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.
[b]Note:[/b] This property is ignored by native file dialogs.
@ -232,6 +268,34 @@
<constant name="DISPLAY_LIST" value="1" enum="DisplayMode">
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.
Equivalent to [member hidden_files_toggle_enabled].
</constant>
<constant name="CUSTOMIZATION_CREATE_FOLDER" value="1" enum="Customization">
If enabled, 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]).
Equivalent to [member folder_creation_enabled].
</constant>
<constant name="CUSTOMIZATION_FILE_FILTER" value="2" enum="Customization">
If enabled, shows the toggle file filter button.
Equivalent to [member file_filter_toggle_enabled].
</constant>
<constant name="CUSTOMIZATION_FILE_SORT" value="3" enum="Customization">
If enabled, shows the file sorting options button.
Equivalent to [member file_sort_options_enabled].
</constant>
<constant name="CUSTOMIZATION_FAVORITES" value="4" enum="Customization">
If enabled, shows the toggle favorite button and favorite list on the left side of the dialog.
Equivalent to [member favorites_enabled].
</constant>
<constant name="CUSTOMIZATION_RECENT" value="5" enum="Customization">
If enabled, shows the recent directories list on the left side of the dialog.
Equivalent to [member recent_list_enabled].
</constant>
<constant name="CUSTOMIZATION_LAYOUT" value="6" enum="Customization">
If enabled, shows the layout switch buttons (list/thumbnails).
Equivalent to [member layout_toggle_enabled].
</constant>
</constants>
<theme_items>
<theme_item name="file_disabled_color" data_type="color" type="Color" default="Color(1, 1, 1, 0.25)">