| 1 | /**************************************************************************/ |
| 2 | /* editor_file_dialog.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef EDITOR_FILE_DIALOG_H |
| 32 | #define EDITOR_FILE_DIALOG_H |
| 33 | |
| 34 | #include "core/io/dir_access.h" |
| 35 | #include "scene/gui/dialogs.h" |
| 36 | |
| 37 | class DependencyRemoveDialog; |
| 38 | class HSplitContainer; |
| 39 | class ItemList; |
| 40 | class OptionButton; |
| 41 | class ; |
| 42 | class TextureRect; |
| 43 | |
| 44 | class EditorFileDialog : public ConfirmationDialog { |
| 45 | GDCLASS(EditorFileDialog, ConfirmationDialog); |
| 46 | |
| 47 | public: |
| 48 | enum DisplayMode { |
| 49 | DISPLAY_THUMBNAILS, |
| 50 | DISPLAY_LIST |
| 51 | }; |
| 52 | |
| 53 | enum Access { |
| 54 | ACCESS_RESOURCES, |
| 55 | ACCESS_USERDATA, |
| 56 | ACCESS_FILESYSTEM |
| 57 | }; |
| 58 | |
| 59 | enum FileMode { |
| 60 | FILE_MODE_OPEN_FILE, |
| 61 | FILE_MODE_OPEN_FILES, |
| 62 | FILE_MODE_OPEN_DIR, |
| 63 | FILE_MODE_OPEN_ANY, |
| 64 | FILE_MODE_SAVE_FILE |
| 65 | }; |
| 66 | |
| 67 | typedef Ref<Texture2D> (*GetIconFunc)(const String &); |
| 68 | typedef void (*RegisterFunc)(EditorFileDialog *); |
| 69 | |
| 70 | static GetIconFunc get_icon_func; |
| 71 | static GetIconFunc get_thumbnail_func; |
| 72 | static RegisterFunc register_func; |
| 73 | static RegisterFunc unregister_func; |
| 74 | |
| 75 | private: |
| 76 | enum { |
| 77 | , |
| 78 | , |
| 79 | , |
| 80 | , |
| 81 | |
| 82 | }; |
| 83 | |
| 84 | ConfirmationDialog *makedialog = nullptr; |
| 85 | LineEdit *makedirname = nullptr; |
| 86 | |
| 87 | Button *makedir = nullptr; |
| 88 | Access access = ACCESS_RESOURCES; |
| 89 | |
| 90 | VBoxContainer *vbox = nullptr; |
| 91 | FileMode mode = FILE_MODE_SAVE_FILE; |
| 92 | bool can_create_dir = false; |
| 93 | LineEdit *dir = nullptr; |
| 94 | |
| 95 | Button *dir_prev = nullptr; |
| 96 | Button *dir_next = nullptr; |
| 97 | Button *dir_up = nullptr; |
| 98 | |
| 99 | HBoxContainer *drives_container = nullptr; |
| 100 | HBoxContainer *shortcuts_container = nullptr; |
| 101 | OptionButton *drives = nullptr; |
| 102 | ItemList *item_list = nullptr; |
| 103 | PopupMenu * = nullptr; |
| 104 | TextureRect *preview = nullptr; |
| 105 | VBoxContainer *preview_vb = nullptr; |
| 106 | HSplitContainer *list_hb = nullptr; |
| 107 | HBoxContainer *file_box = nullptr; |
| 108 | LineEdit *file = nullptr; |
| 109 | OptionButton *filter = nullptr; |
| 110 | AcceptDialog *error_dialog = nullptr; |
| 111 | Ref<DirAccess> dir_access; |
| 112 | ConfirmationDialog *confirm_save = nullptr; |
| 113 | DependencyRemoveDialog *dep_remove_dialog = nullptr; |
| 114 | ConfirmationDialog *global_remove_dialog = nullptr; |
| 115 | |
| 116 | Button *mode_thumbnails = nullptr; |
| 117 | Button *mode_list = nullptr; |
| 118 | |
| 119 | Button *refresh = nullptr; |
| 120 | Button *favorite = nullptr; |
| 121 | Button *show_hidden = nullptr; |
| 122 | |
| 123 | Button *fav_up = nullptr; |
| 124 | Button *fav_down = nullptr; |
| 125 | |
| 126 | ItemList *favorites = nullptr; |
| 127 | ItemList *recent = nullptr; |
| 128 | |
| 129 | Vector<String> local_history; |
| 130 | int local_history_pos = 0; |
| 131 | void _push_history(); |
| 132 | |
| 133 | Vector<String> filters; |
| 134 | |
| 135 | bool previews_enabled = true; |
| 136 | bool preview_waiting = false; |
| 137 | int preview_wheel_index = 0; |
| 138 | float preview_wheel_timeout = 0.0f; |
| 139 | |
| 140 | static bool default_show_hidden_files; |
| 141 | static DisplayMode default_display_mode; |
| 142 | bool show_hidden_files; |
| 143 | DisplayMode display_mode; |
| 144 | |
| 145 | bool disable_overwrite_warning = false; |
| 146 | bool is_invalidating = false; |
| 147 | |
| 148 | struct ThemeCache { |
| 149 | Ref<Texture2D> parent_folder; |
| 150 | Ref<Texture2D> forward_folder; |
| 151 | Ref<Texture2D> back_folder; |
| 152 | Ref<Texture2D> reload; |
| 153 | Ref<Texture2D> toggle_hidden; |
| 154 | Ref<Texture2D> favorite; |
| 155 | Ref<Texture2D> mode_thumbnails; |
| 156 | Ref<Texture2D> mode_list; |
| 157 | Ref<Texture2D> favorites_up; |
| 158 | Ref<Texture2D> favorites_down; |
| 159 | |
| 160 | Ref<Texture2D> folder; |
| 161 | Color folder_icon_color; |
| 162 | |
| 163 | Ref<Texture2D> action_copy; |
| 164 | Ref<Texture2D> action_delete; |
| 165 | Ref<Texture2D> filesystem; |
| 166 | |
| 167 | Ref<Texture2D> folder_medium_thumbnail; |
| 168 | Ref<Texture2D> file_medium_thumbnail; |
| 169 | Ref<Texture2D> folder_big_thumbnail; |
| 170 | Ref<Texture2D> file_big_thumbnail; |
| 171 | |
| 172 | Ref<Texture2D> progress[8]{}; |
| 173 | } theme_cache; |
| 174 | |
| 175 | void update_dir(); |
| 176 | void update_file_name(); |
| 177 | void update_file_list(); |
| 178 | void update_filters(); |
| 179 | |
| 180 | void _focus_file_text(); |
| 181 | |
| 182 | void _update_favorites(); |
| 183 | void _favorite_pressed(); |
| 184 | void _favorite_selected(int p_idx); |
| 185 | void _favorite_move_up(); |
| 186 | void _favorite_move_down(); |
| 187 | |
| 188 | void _update_recent(); |
| 189 | void _recent_selected(int p_idx); |
| 190 | |
| 191 | void _item_selected(int p_item); |
| 192 | void _multi_selected(int p_item, bool p_selected); |
| 193 | void _items_clear_selection(const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 194 | void _item_dc_selected(int p_item); |
| 195 | |
| 196 | void _item_list_item_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 197 | void _item_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 198 | void (int p_option); |
| 199 | |
| 200 | void _select_drive(int p_idx); |
| 201 | void _dir_submitted(String p_dir); |
| 202 | void _action_pressed(); |
| 203 | void _save_confirm_pressed(); |
| 204 | void _cancel_pressed(); |
| 205 | void _filter_selected(int); |
| 206 | void _make_dir(); |
| 207 | void _make_dir_confirm(); |
| 208 | |
| 209 | void _delete_items(); |
| 210 | void _delete_files_global(); |
| 211 | |
| 212 | void _update_drives(bool p_select = true); |
| 213 | void _update_icons(); |
| 214 | |
| 215 | void _go_up(); |
| 216 | void _go_back(); |
| 217 | void _go_forward(); |
| 218 | |
| 219 | void _invalidate(); |
| 220 | |
| 221 | virtual void () override; |
| 222 | |
| 223 | void _save_to_recent(); |
| 224 | // Callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load. |
| 225 | |
| 226 | void _thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata); |
| 227 | void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata); |
| 228 | void _request_single_thumbnail(const String &p_path); |
| 229 | |
| 230 | virtual void shortcut_input(const Ref<InputEvent> &p_event) override; |
| 231 | |
| 232 | bool _is_open_should_be_disabled(); |
| 233 | |
| 234 | protected: |
| 235 | virtual void _update_theme_item_cache() override; |
| 236 | |
| 237 | void _notification(int p_what); |
| 238 | static void _bind_methods(); |
| 239 | |
| 240 | public: |
| 241 | // Public for use with callable_mp. |
| 242 | void _file_submitted(const String &p_file); |
| 243 | |
| 244 | void (); |
| 245 | void clear_filters(); |
| 246 | void add_filter(const String &p_filter, const String &p_description = "" ); |
| 247 | void set_filters(const Vector<String> &p_filters); |
| 248 | Vector<String> get_filters() const; |
| 249 | |
| 250 | void set_enable_multiple_selection(bool p_enable); |
| 251 | Vector<String> get_selected_files() const; |
| 252 | |
| 253 | String get_current_dir() const; |
| 254 | String get_current_file() const; |
| 255 | String get_current_path() const; |
| 256 | void set_current_dir(const String &p_dir); |
| 257 | void set_current_file(const String &p_file); |
| 258 | void set_current_path(const String &p_path); |
| 259 | |
| 260 | void set_display_mode(DisplayMode p_mode); |
| 261 | DisplayMode get_display_mode() const; |
| 262 | |
| 263 | void set_file_mode(FileMode p_mode); |
| 264 | FileMode get_file_mode() const; |
| 265 | |
| 266 | VBoxContainer *get_vbox(); |
| 267 | LineEdit *get_line_edit() { return file; } |
| 268 | |
| 269 | void set_access(Access p_access); |
| 270 | Access get_access() const; |
| 271 | |
| 272 | static void set_default_show_hidden_files(bool p_show); |
| 273 | static void set_default_display_mode(DisplayMode p_mode); |
| 274 | void set_show_hidden_files(bool p_show); |
| 275 | bool is_showing_hidden_files() const; |
| 276 | |
| 277 | void invalidate(); |
| 278 | |
| 279 | void set_disable_overwrite_warning(bool p_disable); |
| 280 | bool is_overwrite_warning_disabled() const; |
| 281 | |
| 282 | void set_previews_enabled(bool p_enabled); |
| 283 | bool are_previews_enabled(); |
| 284 | |
| 285 | EditorFileDialog(); |
| 286 | ~EditorFileDialog(); |
| 287 | }; |
| 288 | |
| 289 | VARIANT_ENUM_CAST(EditorFileDialog::FileMode); |
| 290 | VARIANT_ENUM_CAST(EditorFileDialog::Access); |
| 291 | VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode); |
| 292 | |
| 293 | #endif // EDITOR_FILE_DIALOG_H |
| 294 | |