2015-05-31 01:59:42 -03:00
/**************************************************************************/
2016-06-18 14:46:12 +02:00
/* editor_file_dialog.h */
2015-05-31 01:59:42 -03:00
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2018-01-05 00:50:27 +01:00
2022-05-02 16:28:25 +02:00
# pragma once
2015-05-31 01:59:42 -03:00
2021-06-11 14:51:48 +02:00
# include "core/io/dir_access.h"
2025-06-10 16:47:26 +02:00
# include "editor/file_system/file_info.h"
2015-05-31 01:59:42 -03:00
# include "scene/gui/dialogs.h"
2024-03-21 10:42:38 +02:00
# include "scene/property_list_helper.h"
2017-12-02 01:37:32 +01:00
class DependencyRemoveDialog ;
2024-09-22 20:47:20 -03:00
class GridContainer ;
2022-11-19 12:45:49 +01:00
class HSplitContainer ;
2024-11-13 18:52:39 +01:00
class HFlowContainer ;
2022-11-19 12:45:49 +01:00
class ItemList ;
2024-09-22 20:47:20 -03:00
class MenuButton ;
2022-11-19 12:45:49 +01:00
class OptionButton ;
class PopupMenu ;
class TextureRect ;
2024-12-03 09:43:12 +08:00
class VSeparator ;
2017-12-02 01:37:32 +01:00
2015-05-31 01:59:42 -03:00
class EditorFileDialog : public ConfirmationDialog {
2017-01-02 23:03:46 -03:00
GDCLASS ( EditorFileDialog , ConfirmationDialog ) ;
2015-05-31 01:59:42 -03:00
public :
2015-06-06 09:44:38 -03:00
enum DisplayMode {
DISPLAY_THUMBNAILS ,
DISPLAY_LIST
} ;
2015-05-31 01:59:42 -03:00
enum Access {
ACCESS_RESOURCES ,
ACCESS_USERDATA ,
ACCESS_FILESYSTEM
} ;
2020-03-06 14:00:16 -03:00
enum FileMode {
FILE_MODE_OPEN_FILE ,
FILE_MODE_OPEN_FILES ,
FILE_MODE_OPEN_DIR ,
FILE_MODE_OPEN_ANY ,
FILE_MODE_SAVE_FILE
2015-05-31 01:59:42 -03:00
} ;
2019-06-11 15:43:37 -03:00
typedef Ref < Texture2D > ( * GetIconFunc ) ( const String & ) ;
2015-05-31 01:59:42 -03:00
typedef void ( * RegisterFunc ) ( EditorFileDialog * ) ;
2025-04-28 20:27:50 +02:00
static inline GetIconFunc get_icon_func = nullptr ;
static inline GetIconFunc get_thumbnail_func = nullptr ;
static inline RegisterFunc register_func = nullptr ;
static inline RegisterFunc unregister_func = nullptr ;
2015-05-31 01:59:42 -03:00
private :
2017-12-02 01:37:32 +01:00
enum ItemMenu {
ITEM_MENU_COPY_PATH ,
ITEM_MENU_DELETE ,
ITEM_MENU_REFRESH ,
ITEM_MENU_NEW_FOLDER ,
2024-11-04 11:50:42 +02:00
ITEM_MENU_SHOW_IN_EXPLORER ,
ITEM_MENU_SHOW_BUNDLE_CONTENT ,
2017-12-02 01:37:32 +01:00
} ;
2022-04-04 15:06:57 +02:00
ConfirmationDialog * makedialog = nullptr ;
LineEdit * makedirname = nullptr ;
2015-05-31 01:59:42 -03:00
2024-12-03 09:43:12 +08:00
VSeparator * makedir_sep = nullptr ;
2022-04-04 15:06:57 +02:00
Button * makedir = nullptr ;
2022-05-02 16:28:25 +02:00
Access access = ACCESS_RESOURCES ;
2022-02-03 01:21:52 +01:00
2024-11-13 18:52:39 +01:00
HFlowContainer * flow_checkbox_options = nullptr ;
GridContainer * grid_select_options = nullptr ;
2022-04-04 15:06:57 +02:00
VBoxContainer * vbox = nullptr ;
2022-05-02 16:28:25 +02:00
FileMode mode = FILE_MODE_SAVE_FILE ;
bool can_create_dir = false ;
2022-04-04 15:06:57 +02:00
LineEdit * dir = nullptr ;
Button * dir_prev = nullptr ;
Button * dir_next = nullptr ;
Button * dir_up = nullptr ;
HBoxContainer * drives_container = nullptr ;
HBoxContainer * shortcuts_container = nullptr ;
OptionButton * drives = nullptr ;
ItemList * item_list = nullptr ;
PopupMenu * item_menu = nullptr ;
TextureRect * preview = nullptr ;
VBoxContainer * preview_vb = nullptr ;
2023-09-11 18:05:18 -05:00
HSplitContainer * body_hsplit = nullptr ;
2022-04-04 15:06:57 +02:00
HSplitContainer * list_hb = nullptr ;
HBoxContainer * file_box = nullptr ;
LineEdit * file = nullptr ;
OptionButton * filter = nullptr ;
AcceptDialog * error_dialog = nullptr ;
2022-03-23 11:08:58 +02:00
Ref < DirAccess > dir_access ;
2022-04-04 15:06:57 +02:00
ConfirmationDialog * confirm_save = nullptr ;
DependencyRemoveDialog * dep_remove_dialog = nullptr ;
ConfirmationDialog * global_remove_dialog = nullptr ;
2024-03-21 10:42:38 +02:00
VBoxContainer * vbc = nullptr ;
HBoxContainer * pathhb = nullptr ;
2022-04-04 15:06:57 +02:00
Button * mode_thumbnails = nullptr ;
Button * mode_list = nullptr ;
Button * refresh = nullptr ;
Button * favorite = nullptr ;
Button * show_hidden = nullptr ;
2024-10-09 15:57:30 +02:00
Button * show_search_filter_button = nullptr ;
2022-04-04 15:06:57 +02:00
2024-09-22 20:47:20 -03:00
String search_string ;
2024-10-09 15:57:30 +02:00
bool show_search_filter = false ;
HBoxContainer * filter_hb = nullptr ;
2024-09-22 20:47:20 -03:00
LineEdit * filter_box = nullptr ;
FileSortOption file_sort = FileSortOption : : FILE_SORT_NAME ;
MenuButton * file_sort_button = nullptr ;
2022-04-04 15:06:57 +02:00
Button * fav_up = nullptr ;
Button * fav_down = nullptr ;
ItemList * favorites = nullptr ;
ItemList * recent = nullptr ;
2015-06-06 09:44:38 -03:00
Vector < String > local_history ;
2022-05-02 16:28:25 +02:00
int local_history_pos = 0 ;
2015-06-06 09:44:38 -03:00
void _push_history ( ) ;
2015-05-31 01:59:42 -03:00
Vector < String > filters ;
2024-11-15 08:43:07 +02:00
Vector < String > processed_filters ;
2015-05-31 01:59:42 -03:00
2022-02-15 08:56:58 -06:00
bool previews_enabled = true ;
bool preview_waiting = false ;
2022-05-02 16:28:25 +02:00
int preview_wheel_index = 0 ;
float preview_wheel_timeout = 0.0f ;
2022-02-03 01:21:52 +01:00
2025-04-28 20:27:50 +02:00
static inline bool default_show_hidden_files = false ;
static inline DisplayMode default_display_mode = DISPLAY_THUMBNAILS ;
2015-05-31 01:59:42 -03:00
bool show_hidden_files ;
2015-06-06 09:44:38 -03:00
DisplayMode display_mode ;
2015-05-31 01:59:42 -03:00
2022-02-15 08:56:58 -06:00
bool disable_overwrite_warning = false ;
2023-01-22 14:26:32 -03:00
bool is_invalidating = false ;
2015-05-31 01:59:42 -03:00
2022-09-01 18:52:49 +03:00
struct ThemeCache {
Ref < Texture2D > parent_folder ;
Ref < Texture2D > forward_folder ;
Ref < Texture2D > back_folder ;
2024-11-04 11:50:42 +02:00
Ref < Texture2D > open_folder ;
2022-09-01 18:52:49 +03:00
Ref < Texture2D > reload ;
Ref < Texture2D > toggle_hidden ;
2024-10-09 15:57:30 +02:00
Ref < Texture2D > toggle_filename_filter ;
2022-09-01 18:52:49 +03:00
Ref < Texture2D > favorite ;
Ref < Texture2D > mode_thumbnails ;
Ref < Texture2D > mode_list ;
2024-02-25 11:51:50 -05:00
Ref < Texture2D > create_folder ;
2022-09-01 18:52:49 +03:00
Ref < Texture2D > favorites_up ;
Ref < Texture2D > favorites_down ;
2024-09-22 20:47:20 -03:00
Ref < Texture2D > filter_box ;
Ref < Texture2D > file_sort_button ;
2025-07-20 20:44:33 +03:00
Ref < Texture2D > file ;
2022-09-01 18:52:49 +03:00
Ref < Texture2D > folder ;
2022-09-06 20:09:32 +03:00
Color folder_icon_color ;
2022-09-01 18:52:49 +03:00
Ref < Texture2D > action_copy ;
Ref < Texture2D > action_delete ;
Ref < Texture2D > filesystem ;
Ref < Texture2D > folder_medium_thumbnail ;
Ref < Texture2D > file_medium_thumbnail ;
Ref < Texture2D > folder_big_thumbnail ;
Ref < Texture2D > file_big_thumbnail ;
Ref < Texture2D > progress [ 8 ] { } ;
} theme_cache ;
2024-03-21 10:42:38 +02:00
struct Option {
String name ;
Vector < String > values ;
int default_idx = 0 ;
} ;
static inline PropertyListHelper base_property_helper ;
PropertyListHelper property_helper ;
Vector < Option > options ;
Dictionary selected_options ;
bool options_dirty = false ;
2024-11-24 23:49:46 +02:00
String full_dir ;
2024-03-21 10:42:38 +02:00
2015-05-31 01:59:42 -03:00
void update_dir ( ) ;
2019-06-28 10:29:50 +03:00
void update_file_name ( ) ;
2015-05-31 01:59:42 -03:00
void update_file_list ( ) ;
2024-10-09 15:57:30 +02:00
void update_search_filter_gui ( ) ;
2015-05-31 01:59:42 -03:00
void update_filters ( ) ;
2022-01-03 17:08:03 +08:00
void _focus_file_text ( ) ;
2015-06-06 09:44:38 -03:00
void _update_favorites ( ) ;
2019-06-10 00:27:28 +09:00
void _favorite_pressed ( ) ;
2015-06-06 09:44:38 -03:00
void _favorite_selected ( int p_idx ) ;
void _favorite_move_up ( ) ;
void _favorite_move_down ( ) ;
2022-09-01 18:52:49 +03:00
void _update_recent ( ) ;
2015-06-06 09:44:38 -03:00
void _recent_selected ( int p_idx ) ;
void _item_selected ( int p_item ) ;
2018-01-31 16:25:42 -02:00
void _multi_selected ( int p_item , bool p_selected ) ;
2022-05-09 21:17:04 +03:00
void _items_clear_selection ( const Vector2 & p_pos , MouseButton p_mouse_button_index ) ;
2015-06-06 09:44:38 -03:00
void _item_dc_selected ( int p_item ) ;
2015-05-31 01:59:42 -03:00
2021-11-26 00:53:27 +01:00
void _item_list_item_rmb_clicked ( int p_item , const Vector2 & p_pos , MouseButton p_mouse_button_index ) ;
void _item_list_empty_clicked ( const Vector2 & p_pos , MouseButton p_mouse_button_index ) ;
2017-12-02 01:37:32 +01:00
void _item_menu_id_pressed ( int p_option ) ;
2015-05-31 01:59:42 -03:00
void _select_drive ( int p_idx ) ;
2024-02-15 13:25:58 -03:00
void _dir_submitted ( const String & p_dir ) ;
2015-05-31 01:59:42 -03:00
void _action_pressed ( ) ;
void _save_confirm_pressed ( ) ;
void _cancel_pressed ( ) ;
void _filter_selected ( int ) ;
void _make_dir ( ) ;
void _make_dir_confirm ( ) ;
2024-09-22 20:47:20 -03:00
void _focus_filter_box ( ) ;
void _filter_changed ( const String & p_text ) ;
2024-10-09 15:57:30 +02:00
void _search_filter_selected ( ) ;
2024-09-22 20:47:20 -03:00
void _file_sort_popup ( int p_id ) ;
2017-12-02 01:37:32 +01:00
void _delete_items ( ) ;
2022-02-03 01:21:52 +01:00
void _delete_files_global ( ) ;
2017-12-02 01:37:32 +01:00
2022-01-24 13:12:46 +02:00
void _update_drives ( bool p_select = true ) ;
2022-02-03 01:21:52 +01:00
void _update_icons ( ) ;
2015-05-31 01:59:42 -03:00
2015-06-06 09:44:38 -03:00
void _go_up ( ) ;
void _go_back ( ) ;
void _go_forward ( ) ;
2015-05-31 01:59:42 -03:00
2023-01-22 14:26:32 -03:00
void _invalidate ( ) ;
2020-07-10 11:34:39 +01:00
virtual void _post_popup ( ) override ;
2015-05-31 01:59:42 -03:00
2015-06-06 09:44:38 -03:00
void _save_to_recent ( ) ;
2022-02-03 01:21:52 +01:00
// Callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load.
2015-05-31 01:59:42 -03:00
2025-07-01 01:04:59 +02:00
void _thumbnail_result ( const String & p_path , const Ref < Texture2D > & p_preview , const Ref < Texture2D > & p_small_preview ) ;
void _thumbnail_done ( const String & p_path , const Ref < Texture2D > & p_preview , const Ref < Texture2D > & p_small_preview ) ;
2015-05-31 01:59:42 -03:00
void _request_single_thumbnail ( const String & p_path ) ;
2022-01-11 15:59:52 +02:00
virtual void shortcut_input ( const Ref < InputEvent > & p_event ) override ;
2015-12-29 00:36:48 +01:00
2017-11-24 21:12:18 +03:00
bool _is_open_should_be_disabled ( ) ;
2024-03-21 10:42:38 +02:00
void _native_popup ( ) ;
void _native_dialog_cb ( bool p_ok , const Vector < String > & p_files , int p_filter , const Dictionary & p_selected_options ) ;
TypedArray < Dictionary > _get_options ( ) const ;
void _update_option_controls ( ) ;
void _option_changed_checkbox_toggled ( bool p_pressed , const String & p_name ) ;
void _option_changed_item_selected ( int p_idx , const String & p_name ) ;
2015-05-31 01:59:42 -03:00
protected :
2022-09-01 18:52:49 +03:00
virtual void _update_theme_item_cache ( ) override ;
2015-05-31 01:59:42 -03:00
void _notification ( int p_what ) ;
2024-03-21 10:42:38 +02:00
bool _set ( const StringName & p_name , const Variant & p_value ) { return property_helper . property_set_value ( p_name , p_value ) ; }
bool _get ( const StringName & p_name , Variant & r_ret ) const { return property_helper . property_get_value ( p_name , r_ret ) ; }
2024-05-23 17:10:55 +02:00
void _get_property_list ( List < PropertyInfo > * p_list ) const { property_helper . get_property_list ( p_list ) ; }
2024-03-21 10:42:38 +02:00
bool _property_can_revert ( const StringName & p_name ) const { return property_helper . property_can_revert ( p_name ) ; }
bool _property_get_revert ( const StringName & p_name , Variant & r_property ) const { return property_helper . property_get_revert ( p_name , r_property ) ; }
2015-05-31 01:59:42 -03:00
static void _bind_methods ( ) ;
2022-02-03 01:21:52 +01:00
2015-05-31 01:59:42 -03:00
public :
2024-03-21 10:42:38 +02:00
virtual void set_visible ( bool p_visible ) override ;
virtual void popup ( const Rect2i & p_rect = Rect2i ( ) ) override ;
2020-12-06 16:09:18 +01:00
// Public for use with callable_mp.
void _file_submitted ( const String & p_file ) ;
2020-07-11 18:45:19 +02:00
void popup_file_dialog ( ) ;
2015-05-31 01:59:42 -03:00
void clear_filters ( ) ;
2022-07-04 16:26:26 -05:00
void add_filter ( const String & p_filter , const String & p_description = " " ) ;
2023-02-22 11:55:08 +02:00
void set_filters ( const Vector < String > & p_filters ) ;
Vector < String > get_filters ( ) const ;
2024-10-09 15:57:30 +02:00
void clear_search_filter ( ) ;
void set_search_filter ( const String & p_search_filter ) ;
String get_search_filter ( ) const ;
2015-05-31 01:59:42 -03:00
void set_enable_multiple_selection ( bool p_enable ) ;
Vector < String > get_selected_files ( ) const ;
String get_current_dir ( ) const ;
String get_current_file ( ) const ;
String get_current_path ( ) const ;
void set_current_dir ( const String & p_dir ) ;
void set_current_file ( const String & p_file ) ;
void set_current_path ( const String & p_path ) ;
2024-03-21 10:42:38 +02:00
String get_option_name ( int p_option ) const ;
Vector < String > get_option_values ( int p_option ) const ;
int get_option_default ( int p_option ) const ;
void set_option_name ( int p_option , const String & p_name ) ;
void set_option_values ( int p_option , const Vector < String > & p_values ) ;
void set_option_default ( int p_option , int p_index ) ;
void add_option ( const String & p_name , const Vector < String > & p_values , int p_index ) ;
void set_option_count ( int p_count ) ;
int get_option_count ( ) const ;
Dictionary get_selected_options ( ) const ;
2015-06-06 09:44:38 -03:00
void set_display_mode ( DisplayMode p_mode ) ;
DisplayMode get_display_mode ( ) const ;
2020-03-06 14:00:16 -03:00
void set_file_mode ( FileMode p_mode ) ;
FileMode get_file_mode ( ) const ;
2015-05-31 01:59:42 -03:00
VBoxContainer * get_vbox ( ) ;
LineEdit * get_line_edit ( ) { return file ; }
void set_access ( Access p_access ) ;
Access get_access ( ) const ;
static void set_default_show_hidden_files ( bool p_show ) ;
2015-12-15 13:39:13 -03:00
static void set_default_display_mode ( DisplayMode p_mode ) ;
2022-02-03 01:21:52 +01:00
void set_show_hidden_files ( bool p_show ) ;
2024-10-09 15:57:30 +02:00
void set_show_search_filter ( bool p_show ) ;
2022-02-03 01:21:52 +01:00
bool is_showing_hidden_files ( ) const ;
2015-05-31 01:59:42 -03:00
void invalidate ( ) ;
2016-06-20 00:38:13 -03:00
void set_disable_overwrite_warning ( bool p_disable ) ;
bool is_overwrite_warning_disabled ( ) const ;
2022-02-03 01:21:52 +01:00
void set_previews_enabled ( bool p_enabled ) ;
bool are_previews_enabled ( ) ;
2025-10-02 14:02:16 +02:00
# ifndef DISABLE_DEPRECATED
void add_side_menu ( Control * p_menu , const String & p_title = " " ) { ERR_FAIL_MSG ( " add_side_menu() is kept for compatibility and does nothing. For similar functionality, you can show another dialog after file dialog. " ) ; }
# endif
2023-09-11 18:05:18 -05:00
2015-05-31 01:59:42 -03:00
EditorFileDialog ( ) ;
~ EditorFileDialog ( ) ;
} ;
2020-03-06 14:00:16 -03:00
VARIANT_ENUM_CAST ( EditorFileDialog : : FileMode ) ;
2015-05-31 01:59:42 -03:00
VARIANT_ENUM_CAST ( EditorFileDialog : : Access ) ;
2015-06-06 09:44:38 -03:00
VARIANT_ENUM_CAST ( EditorFileDialog : : DisplayMode ) ;