| 1 | /**************************************************************************/ |
| 2 | /* filesystem_dock.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 FILESYSTEM_DOCK_H |
| 32 | #define FILESYSTEM_DOCK_H |
| 33 | |
| 34 | #include "editor/dependency_editor.h" |
| 35 | #include "editor/editor_file_system.h" |
| 36 | #include "editor/plugins/script_editor_plugin.h" |
| 37 | #include "editor/script_create_dialog.h" |
| 38 | #include "scene/gui/box_container.h" |
| 39 | #include "scene/gui/control.h" |
| 40 | #include "scene/gui/dialogs.h" |
| 41 | #include "scene/gui/menu_button.h" |
| 42 | #include "scene/gui/split_container.h" |
| 43 | #include "scene/gui/tree.h" |
| 44 | |
| 45 | class CreateDialog; |
| 46 | class EditorDirDialog; |
| 47 | class ItemList; |
| 48 | class LineEdit; |
| 49 | class ProgressBar; |
| 50 | class SceneCreateDialog; |
| 51 | class ShaderCreateDialog; |
| 52 | class DirectoryCreateDialog; |
| 53 | class EditorResourceTooltipPlugin; |
| 54 | |
| 55 | class FileSystemTree : public Tree { |
| 56 | virtual Control *make_custom_tooltip(const String &p_text) const; |
| 57 | }; |
| 58 | |
| 59 | class FileSystemList : public ItemList { |
| 60 | GDCLASS(FileSystemList, ItemList); |
| 61 | |
| 62 | VBoxContainer * = nullptr; |
| 63 | Popup * = nullptr; |
| 64 | LineEdit *line_editor = nullptr; |
| 65 | |
| 66 | virtual Control *make_custom_tooltip(const String &p_text) const override; |
| 67 | void _line_editor_submit(String p_text); |
| 68 | void (); |
| 69 | |
| 70 | protected: |
| 71 | static void _bind_methods(); |
| 72 | |
| 73 | public: |
| 74 | bool edit_selected(); |
| 75 | String get_edit_text(); |
| 76 | |
| 77 | FileSystemList(); |
| 78 | }; |
| 79 | |
| 80 | class FileSystemDock : public VBoxContainer { |
| 81 | GDCLASS(FileSystemDock, VBoxContainer); |
| 82 | |
| 83 | public: |
| 84 | enum FileListDisplayMode { |
| 85 | FILE_LIST_DISPLAY_THUMBNAILS, |
| 86 | FILE_LIST_DISPLAY_LIST |
| 87 | }; |
| 88 | |
| 89 | enum DisplayMode { |
| 90 | DISPLAY_MODE_TREE_ONLY, |
| 91 | DISPLAY_MODE_SPLIT, |
| 92 | }; |
| 93 | |
| 94 | enum FileSortOption { |
| 95 | FILE_SORT_NAME = 0, |
| 96 | FILE_SORT_NAME_REVERSE, |
| 97 | FILE_SORT_TYPE, |
| 98 | FILE_SORT_TYPE_REVERSE, |
| 99 | FILE_SORT_MODIFIED_TIME, |
| 100 | FILE_SORT_MODIFIED_TIME_REVERSE, |
| 101 | FILE_SORT_MAX, |
| 102 | }; |
| 103 | |
| 104 | private: |
| 105 | enum { |
| 106 | FILE_OPEN, |
| 107 | FILE_INHERIT, |
| 108 | FILE_MAIN_SCENE, |
| 109 | FILE_INSTANTIATE, |
| 110 | FILE_ADD_FAVORITE, |
| 111 | FILE_REMOVE_FAVORITE, |
| 112 | FILE_DEPENDENCIES, |
| 113 | FILE_OWNERS, |
| 114 | FILE_MOVE, |
| 115 | FILE_RENAME, |
| 116 | FILE_REMOVE, |
| 117 | FILE_DUPLICATE, |
| 118 | FILE_REIMPORT, |
| 119 | FILE_INFO, |
| 120 | FILE_NEW, |
| 121 | FILE_SHOW_IN_EXPLORER, |
| 122 | FILE_OPEN_EXTERNAL, |
| 123 | FILE_COPY_PATH, |
| 124 | FILE_COPY_UID, |
| 125 | FOLDER_EXPAND_ALL, |
| 126 | FOLDER_COLLAPSE_ALL, |
| 127 | FILE_NEW_RESOURCE, |
| 128 | FILE_NEW_TEXTFILE, |
| 129 | FILE_NEW_FOLDER, |
| 130 | FILE_NEW_SCRIPT, |
| 131 | FILE_NEW_SCENE, |
| 132 | }; |
| 133 | |
| 134 | enum Overwrite { |
| 135 | OVERWRITE_UNDECIDED, |
| 136 | OVERWRITE_REPLACE, |
| 137 | OVERWRITE_RENAME, |
| 138 | }; |
| 139 | |
| 140 | HashMap<String, Color> folder_colors; |
| 141 | Dictionary assigned_folder_colors; |
| 142 | |
| 143 | FileSortOption file_sort = FILE_SORT_NAME; |
| 144 | |
| 145 | VBoxContainer *scanning_vb = nullptr; |
| 146 | ProgressBar *scanning_progress = nullptr; |
| 147 | VSplitContainer *split_box = nullptr; |
| 148 | VBoxContainer *file_list_vb = nullptr; |
| 149 | |
| 150 | HashSet<String> favorites; |
| 151 | |
| 152 | Button *button_toggle_display_mode = nullptr; |
| 153 | Button *button_reload = nullptr; |
| 154 | Button *button_file_list_display_mode = nullptr; |
| 155 | Button *button_hist_next = nullptr; |
| 156 | Button *button_hist_prev = nullptr; |
| 157 | LineEdit *current_path_line_edit = nullptr; |
| 158 | |
| 159 | HBoxContainer *toolbar2_hbc = nullptr; |
| 160 | LineEdit *tree_search_box = nullptr; |
| 161 | MenuButton *tree_button_sort = nullptr; |
| 162 | |
| 163 | LineEdit *file_list_search_box = nullptr; |
| 164 | MenuButton *file_list_button_sort = nullptr; |
| 165 | |
| 166 | String searched_string; |
| 167 | Vector<String> uncollapsed_paths_before_search; |
| 168 | |
| 169 | TextureRect *search_icon = nullptr; |
| 170 | HBoxContainer *path_hb = nullptr; |
| 171 | |
| 172 | FileListDisplayMode file_list_display_mode; |
| 173 | DisplayMode display_mode; |
| 174 | DisplayMode old_display_mode; |
| 175 | |
| 176 | PopupMenu * = nullptr; |
| 177 | PopupMenu * = nullptr; |
| 178 | |
| 179 | DependencyEditor *deps_editor = nullptr; |
| 180 | DependencyEditorOwners *owners_editor = nullptr; |
| 181 | DependencyRemoveDialog *remove_dialog = nullptr; |
| 182 | |
| 183 | EditorDirDialog *move_dialog = nullptr; |
| 184 | ConfirmationDialog *duplicate_dialog = nullptr; |
| 185 | LineEdit *duplicate_dialog_text = nullptr; |
| 186 | DirectoryCreateDialog *make_dir_dialog = nullptr; |
| 187 | |
| 188 | ConfirmationDialog *overwrite_dialog = nullptr; |
| 189 | ScrollContainer *overwrite_dialog_scroll = nullptr; |
| 190 | Label * = nullptr; |
| 191 | Label * = nullptr; |
| 192 | Label *overwrite_dialog_file_list = nullptr; |
| 193 | |
| 194 | SceneCreateDialog *make_scene_dialog = nullptr; |
| 195 | ScriptCreateDialog *make_script_dialog = nullptr; |
| 196 | ShaderCreateDialog *make_shader_dialog = nullptr; |
| 197 | CreateDialog *new_resource_dialog = nullptr; |
| 198 | |
| 199 | bool always_show_folders = false; |
| 200 | |
| 201 | bool editor_is_dark_theme = false; |
| 202 | |
| 203 | class FileOrFolder { |
| 204 | public: |
| 205 | String path; |
| 206 | bool is_file = false; |
| 207 | |
| 208 | FileOrFolder() {} |
| 209 | FileOrFolder(const String &p_path, bool p_is_file) : |
| 210 | path(p_path), |
| 211 | is_file(p_is_file) {} |
| 212 | }; |
| 213 | FileOrFolder to_rename; |
| 214 | FileOrFolder to_duplicate; |
| 215 | Vector<FileOrFolder> to_move; |
| 216 | String to_move_path; |
| 217 | bool to_move_or_copy = false; |
| 218 | |
| 219 | Vector<String> history; |
| 220 | int history_pos; |
| 221 | int history_max_size; |
| 222 | |
| 223 | String current_path; |
| 224 | |
| 225 | bool initialized = false; |
| 226 | |
| 227 | bool updating_tree = false; |
| 228 | int tree_update_id; |
| 229 | FileSystemTree *tree = nullptr; |
| 230 | FileSystemList *files = nullptr; |
| 231 | bool import_dock_needs_update = false; |
| 232 | |
| 233 | bool holding_branch = false; |
| 234 | Vector<TreeItem *> tree_items_selected_on_drag_begin; |
| 235 | PackedInt32Array list_items_selected_on_drag_begin; |
| 236 | |
| 237 | LocalVector<Ref<EditorResourceTooltipPlugin>> tooltip_plugins; |
| 238 | |
| 239 | void _tree_mouse_exited(); |
| 240 | void _reselect_items_selected_on_drag_begin(bool reset = false); |
| 241 | |
| 242 | Ref<Texture2D> _get_tree_item_icon(bool p_is_valid, String p_file_type); |
| 243 | bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites, bool p_unfold_path = false); |
| 244 | void _update_tree(const Vector<String> &p_uncollapsed_paths = Vector<String>(), bool p_uncollapse_root = false, bool p_select_in_favorites = false, bool p_unfold_path = false); |
| 245 | void _navigate_to_path(const String &p_path, bool p_select_in_favorites = false); |
| 246 | |
| 247 | void _file_list_gui_input(Ref<InputEvent> p_event); |
| 248 | void _tree_gui_input(Ref<InputEvent> p_event); |
| 249 | |
| 250 | void _update_file_list(bool p_keep_selection); |
| 251 | void _toggle_file_display(); |
| 252 | void _set_file_display(bool p_active); |
| 253 | void _fs_changed(); |
| 254 | |
| 255 | void _select_file(const String &p_path, bool p_select_in_favorites = false); |
| 256 | void _tree_activate_file(); |
| 257 | void _file_list_activate_file(int p_idx); |
| 258 | void _file_multi_selected(int p_index, bool p_selected); |
| 259 | void _tree_multi_selected(Object *p_item, int p_column, bool p_selected); |
| 260 | |
| 261 | bool _get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const; |
| 262 | void _update_import_dock(); |
| 263 | |
| 264 | void _get_all_items_in_dir(EditorFileSystemDirectory *p_efsd, Vector<String> &r_files, Vector<String> &r_folders) const; |
| 265 | void _find_remaps(EditorFileSystemDirectory *p_efsd, const Vector<String> &r_renames, Vector<String> &r_to_remaps) const; |
| 266 | void _try_move_item(const FileOrFolder &p_item, const String &p_new_path, HashMap<String, String> &p_file_renames, HashMap<String, String> &p_folder_renames); |
| 267 | void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const; |
| 268 | void _before_move(Vector<String> &r_old_paths, HashMap<String, ResourceUID::ID> &r_uids, Vector<String> &r_remaps) const; |
| 269 | void _update_dependencies_after_move(const HashMap<String, String> &p_renames, const Vector<String> &p_remaps) const; |
| 270 | void _update_resource_paths_after_move(const HashMap<String, String> &p_renames, const HashMap<String, ResourceUID::ID> &p_uids) const; |
| 271 | void _update_favorites_list_after_move(const HashMap<String, String> &p_files_renames, const HashMap<String, String> &p_folders_renames) const; |
| 272 | void _update_project_settings_after_move(const HashMap<String, String> &p_renames, const HashMap<String, String> &p_folders_renames); |
| 273 | String _get_unique_name(const FileOrFolder &p_entry, const String &p_at_path); |
| 274 | |
| 275 | void _update_folder_colors_setting(); |
| 276 | |
| 277 | void _resource_removed(const Ref<Resource> &p_resource); |
| 278 | void _file_removed(String p_file); |
| 279 | void _folder_removed(String p_folder); |
| 280 | |
| 281 | void _resource_created(); |
| 282 | void _make_scene_confirm(); |
| 283 | void _rename_operation_confirm(); |
| 284 | void _duplicate_operation_confirm(); |
| 285 | void _overwrite_dialog_action(bool p_overwrite); |
| 286 | Vector<String> _check_existing(); |
| 287 | void _move_dialog_confirm(const String &p_path); |
| 288 | void _move_operation_confirm(const String &p_to_path, bool p_copy = false, Overwrite p_overwrite = OVERWRITE_UNDECIDED); |
| 289 | |
| 290 | void _tree_rmb_option(int p_option); |
| 291 | void _file_list_rmb_option(int p_option); |
| 292 | void _file_option(int p_option, const Vector<String> &p_selected); |
| 293 | |
| 294 | void _fw_history(); |
| 295 | void _bw_history(); |
| 296 | void _update_history(); |
| 297 | void _push_to_history(); |
| 298 | |
| 299 | void _set_scanning_mode(); |
| 300 | void _rescan(); |
| 301 | |
| 302 | void _toggle_split_mode(bool p_active); |
| 303 | |
| 304 | void _search_changed(const String &p_text, const Control *p_from); |
| 305 | |
| 306 | MenuButton *(); |
| 307 | void (int p_id); |
| 308 | |
| 309 | void (int p_index, PopupMenu *); |
| 310 | void _file_and_folders_fill_popup(PopupMenu *, Vector<String> p_paths, bool p_display_path_dependent_options = true); |
| 311 | void _tree_rmb_select(const Vector2 &p_pos, MouseButton p_button); |
| 312 | void _file_list_item_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 313 | void _file_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index); |
| 314 | void _tree_empty_click(const Vector2 &p_pos, MouseButton p_button); |
| 315 | void _tree_empty_selected(); |
| 316 | |
| 317 | struct FileInfo { |
| 318 | String name; |
| 319 | String path; |
| 320 | StringName type; |
| 321 | Vector<String> sources; |
| 322 | bool import_broken = false; |
| 323 | uint64_t modified_time = 0; |
| 324 | |
| 325 | bool operator<(const FileInfo &fi) const { |
| 326 | return NaturalNoCaseComparator()(name, fi.name); |
| 327 | } |
| 328 | }; |
| 329 | |
| 330 | struct FileInfoTypeComparator; |
| 331 | struct FileInfoModifiedTimeComparator; |
| 332 | |
| 333 | void _sort_file_info_list(List<FileSystemDock::FileInfo> &r_file_list); |
| 334 | |
| 335 | void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items); |
| 336 | |
| 337 | void _set_current_path_line_edit_text(const String &p_path); |
| 338 | |
| 339 | Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
| 340 | bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
| 341 | void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
| 342 | void _get_drag_target_folder(String &target, bool &target_favorites, const Point2 &p_point, Control *p_from) const; |
| 343 | |
| 344 | void _preview_invalidated(const String &p_path); |
| 345 | void _file_list_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata); |
| 346 | void _tree_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata); |
| 347 | |
| 348 | void _update_display_mode(bool p_force = false); |
| 349 | |
| 350 | Vector<String> _tree_get_selected(bool remove_self_inclusion = true) const; |
| 351 | |
| 352 | bool _is_file_type_disabled_by_feature_profile(const StringName &p_class); |
| 353 | |
| 354 | void _feature_profile_changed(); |
| 355 | static Vector<String> _remove_self_included_paths(Vector<String> selected_strings); |
| 356 | |
| 357 | private: |
| 358 | static FileSystemDock *singleton; |
| 359 | |
| 360 | public: |
| 361 | static FileSystemDock *get_singleton() { return singleton; } |
| 362 | |
| 363 | protected: |
| 364 | void _notification(int p_what); |
| 365 | static void _bind_methods(); |
| 366 | |
| 367 | public: |
| 368 | Vector<String> get_selected_paths() const; |
| 369 | Vector<String> get_uncollapsed_paths() const; |
| 370 | |
| 371 | String get_current_path() const; |
| 372 | String get_current_directory() const; |
| 373 | |
| 374 | void navigate_to_path(const String &p_path); |
| 375 | void focus_on_filter(); |
| 376 | |
| 377 | ScriptCreateDialog *get_script_create_dialog() const; |
| 378 | |
| 379 | void fix_dependencies(const String &p_for_file); |
| 380 | |
| 381 | int get_split_offset() { return split_box->get_split_offset(); } |
| 382 | void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); } |
| 383 | void select_file(const String &p_file); |
| 384 | |
| 385 | void set_display_mode(DisplayMode p_display_mode); |
| 386 | DisplayMode get_display_mode() { return display_mode; } |
| 387 | |
| 388 | void set_file_sort(FileSortOption p_file_sort); |
| 389 | FileSortOption get_file_sort() { return file_sort; } |
| 390 | |
| 391 | void set_file_list_display_mode(FileListDisplayMode p_mode); |
| 392 | FileListDisplayMode get_file_list_display_mode() { return file_list_display_mode; }; |
| 393 | |
| 394 | Tree *get_tree_control() { return tree; } |
| 395 | |
| 396 | void add_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin); |
| 397 | void remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin); |
| 398 | Control *create_tooltip_for_path(const String &p_path) const; |
| 399 | |
| 400 | FileSystemDock(); |
| 401 | ~FileSystemDock(); |
| 402 | }; |
| 403 | |
| 404 | #endif // FILESYSTEM_DOCK_H |
| 405 | |