diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 309 |
1 files changed, 161 insertions, 148 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 3c010112ad..1a518f7d03 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -44,6 +44,7 @@ #include "editor/editor_resource_preview.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" +#include "editor/editor_string_names.h" #include "editor/gui/editor_dir_dialog.h" #include "editor/gui/editor_scene_tabs.h" #include "editor/import/resource_importer_scene.h" @@ -170,9 +171,9 @@ FileSystemDock *FileSystemDock::singleton = nullptr; Ref<Texture2D> FileSystemDock::_get_tree_item_icon(bool p_is_valid, String p_file_type) { Ref<Texture2D> file_icon; if (!p_is_valid) { - file_icon = get_theme_icon(SNAME("ImportFail"), SNAME("EditorIcons")); + file_icon = get_editor_theme_icon(SNAME("ImportFail")); } else { - file_icon = (has_theme_icon(p_file_type, SNAME("EditorIcons"))) ? get_theme_icon(p_file_type, SNAME("EditorIcons")) : get_theme_icon(SNAME("File"), SNAME("EditorIcons")); + file_icon = (has_theme_icon(p_file_type, EditorStringName(EditorIcons))) ? get_editor_theme_icon(p_file_type) : get_editor_theme_icon(SNAME("File")); } return file_icon; } @@ -212,7 +213,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->set_text(0, dname); subdirectory_item->set_structured_text_bidi_override(0, TextServer::STRUCTURED_TEXT_FILE); - subdirectory_item->set_icon(0, get_theme_icon(SNAME("Folder"), SNAME("EditorIcons"))); + subdirectory_item->set_icon(0, get_editor_theme_icon(SNAME("Folder"))); subdirectory_item->set_selectable(0, true); subdirectory_item->set_metadata(0, lpath); if (!p_select_in_favorites && (current_path == lpath || ((display_mode == DISPLAY_MODE_SPLIT) && current_path.get_base_dir() == lpath))) { @@ -294,7 +295,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory file_item->set_as_cursor(0); } if (main_scene == file_metadata) { - file_item->set_custom_color(0, get_theme_color(SNAME("accent_color"), SNAME("Editor"))); + file_item->set_custom_color(0, get_theme_color(SNAME("accent_color"), EditorStringName(Editor))); } Array udata; udata.push_back(tree_update_id); @@ -362,7 +363,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo // Handles the favorites. TreeItem *favorites_item = tree->create_item(root); - favorites_item->set_icon(0, get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons"))); + favorites_item->set_icon(0, get_editor_theme_icon(SNAME("Favorites"))); favorites_item->set_text(0, TTR("Favorites:")); favorites_item->set_metadata(0, "Favorites"); favorites_item->set_collapsed(p_uncollapsed_paths.find("Favorites") < 0); @@ -382,7 +383,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo EditorSettings::get_singleton()->set_favorites(favorite_paths); } - Ref<Texture2D> folder_icon = get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")); + Ref<Texture2D> folder_icon = get_editor_theme_icon(SNAME("Folder")); const Color default_folder_color = get_theme_color(SNAME("folder_icon_color"), SNAME("FileDialog")); for (int i = 0; i < favorite_paths.size(); i++) { @@ -409,7 +410,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo if (dir) { icon = _get_tree_item_icon(dir->get_file_import_is_valid(index), dir->get_file_type(index)); } else { - icon = get_theme_icon(SNAME("File"), SNAME("EditorIcons")); + icon = get_editor_theme_icon(SNAME("File")); } color = Color(1, 1, 1); } @@ -498,28 +499,28 @@ void FileSystemDock::_notification(int p_what) { EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &FileSystemDock::_fs_changed)); EditorResourcePreview::get_singleton()->connect("preview_invalidated", callable_mp(this, &FileSystemDock::_preview_invalidated)); - button_reload->set_icon(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); - button_toggle_display_mode->set_icon(get_theme_icon(SNAME("Panels2"), SNAME("EditorIcons"))); + button_reload->set_icon(get_editor_theme_icon(SNAME("Reload"))); + button_toggle_display_mode->set_icon(get_editor_theme_icon(SNAME("Panels2"))); button_file_list_display_mode->connect("pressed", callable_mp(this, &FileSystemDock::_toggle_file_display)); files->connect("item_activated", callable_mp(this, &FileSystemDock::_file_list_activate_file)); button_hist_next->connect("pressed", callable_mp(this, &FileSystemDock::_fw_history)); button_hist_prev->connect("pressed", callable_mp(this, &FileSystemDock::_bw_history)); - tree_search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + tree_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); tree_search_box->set_clear_button_enabled(true); - tree_button_sort->set_icon(get_theme_icon(SNAME("Sort"), SNAME("EditorIcons"))); + tree_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); - file_list_search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + file_list_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); file_list_search_box->set_clear_button_enabled(true); - file_list_button_sort->set_icon(get_theme_icon(SNAME("Sort"), SNAME("EditorIcons"))); + file_list_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); if (is_layout_rtl()) { - button_hist_next->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); - button_hist_prev->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); + button_hist_next->set_icon(get_editor_theme_icon(SNAME("Back"))); + button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Forward"))); } else { - button_hist_next->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); - button_hist_prev->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); + button_hist_next->set_icon(get_editor_theme_icon(SNAME("Forward"))); + button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Back"))); } file_list_popup->connect("id_pressed", callable_mp(this, &FileSystemDock::_file_list_rmb_option)); tree_popup->connect("id_pressed", callable_mp(this, &FileSystemDock::_tree_rmb_option)); @@ -585,28 +586,28 @@ void FileSystemDock::_notification(int p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { // Update icons. - button_reload->set_icon(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); - button_toggle_display_mode->set_icon(get_theme_icon(SNAME("Panels2"), SNAME("EditorIcons"))); + button_reload->set_icon(get_editor_theme_icon(SNAME("Reload"))); + button_toggle_display_mode->set_icon(get_editor_theme_icon(SNAME("Panels2"))); if (is_layout_rtl()) { - button_hist_next->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); - button_hist_prev->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); + button_hist_next->set_icon(get_editor_theme_icon(SNAME("Back"))); + button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Forward"))); } else { - button_hist_next->set_icon(get_theme_icon(SNAME("Forward"), SNAME("EditorIcons"))); - button_hist_prev->set_icon(get_theme_icon(SNAME("Back"), SNAME("EditorIcons"))); + button_hist_next->set_icon(get_editor_theme_icon(SNAME("Forward"))); + button_hist_prev->set_icon(get_editor_theme_icon(SNAME("Back"))); } if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { - button_file_list_display_mode->set_icon(get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons"))); + button_file_list_display_mode->set_icon(get_editor_theme_icon(SNAME("FileThumbnail"))); } else { - button_file_list_display_mode->set_icon(get_theme_icon(SNAME("FileList"), SNAME("EditorIcons"))); + button_file_list_display_mode->set_icon(get_editor_theme_icon(SNAME("FileList"))); } - tree_search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + tree_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); tree_search_box->set_clear_button_enabled(true); - tree_button_sort->set_icon(get_theme_icon(SNAME("Sort"), SNAME("EditorIcons"))); + tree_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); - file_list_search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + file_list_search_box->set_right_icon(get_editor_theme_icon(SNAME("Search"))); file_list_search_box->set_clear_button_enabled(true); - file_list_button_sort->set_icon(get_theme_icon(SNAME("Sort"), SNAME("EditorIcons"))); + file_list_button_sort->set_icon(get_editor_theme_icon(SNAME("Sort"))); // Update editor dark theme & always show folders states from editor settings, redraw if needed. bool do_redraw = false; @@ -775,11 +776,11 @@ void FileSystemDock::_toggle_file_display() { void FileSystemDock::_set_file_display(bool p_active) { if (p_active) { file_list_display_mode = FILE_LIST_DISPLAY_LIST; - button_file_list_display_mode->set_icon(get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons"))); + button_file_list_display_mode->set_icon(get_editor_theme_icon(SNAME("FileThumbnail"))); button_file_list_display_mode->set_tooltip_text(TTR("View items as a grid of thumbnails.")); } else { file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS; - button_file_list_display_mode->set_icon(get_theme_icon(SNAME("FileList"), SNAME("EditorIcons"))); + button_file_list_display_mode->set_icon(get_editor_theme_icon(SNAME("FileList"))); button_file_list_display_mode->set_tooltip_text(TTR("View items as a list.")); } @@ -922,13 +923,13 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); if (thumbnail_size < 64) { - folder_thumbnail = get_theme_icon(SNAME("FolderMediumThumb"), SNAME("EditorIcons")); - file_thumbnail = get_theme_icon(SNAME("FileMediumThumb"), SNAME("EditorIcons")); - file_thumbnail_broken = get_theme_icon(SNAME("FileDeadMediumThumb"), SNAME("EditorIcons")); + folder_thumbnail = get_editor_theme_icon(SNAME("FolderMediumThumb")); + file_thumbnail = get_editor_theme_icon(SNAME("FileMediumThumb")); + file_thumbnail_broken = get_editor_theme_icon(SNAME("FileDeadMediumThumb")); } else { - folder_thumbnail = get_theme_icon(SNAME("FolderBigThumb"), SNAME("EditorIcons")); - file_thumbnail = get_theme_icon(SNAME("FileBigThumb"), SNAME("EditorIcons")); - file_thumbnail_broken = get_theme_icon(SNAME("FileDeadBigThumb"), SNAME("EditorIcons")); + folder_thumbnail = get_editor_theme_icon(SNAME("FolderBigThumb")); + file_thumbnail = get_editor_theme_icon(SNAME("FileBigThumb")); + file_thumbnail_broken = get_editor_theme_icon(SNAME("FileDeadBigThumb")); } } else { // No thumbnails. @@ -1087,10 +1088,10 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { // Select the icons. if (!finfo->import_broken) { - type_icon = (has_theme_icon(ftype, SNAME("EditorIcons"))) ? get_theme_icon(ftype, SNAME("EditorIcons")) : get_theme_icon(SNAME("Object"), SNAME("EditorIcons")); + type_icon = (has_theme_icon(ftype, EditorStringName(EditorIcons))) ? get_editor_theme_icon(ftype) : get_editor_theme_icon(SNAME("Object")); big_icon = file_thumbnail; } else { - type_icon = get_theme_icon(SNAME("ImportFail"), SNAME("EditorIcons")); + type_icon = get_editor_theme_icon(SNAME("ImportFail")); big_icon = file_thumbnail_broken; tooltip += "\n" + TTR("Status: Import of file failed. Please fix file and reimport manually."); } @@ -1110,7 +1111,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } if (fpath == main_scene) { - files->set_item_custom_fg_color(item_index, get_theme_color(SNAME("accent_color"), SNAME("Editor"))); + files->set_item_custom_fg_color(item_index, get_theme_color(SNAME("accent_color"), EditorStringName(Editor))); } // Generate the preview. @@ -1362,7 +1363,7 @@ void FileSystemDock::_get_all_items_in_dir(EditorFileSystemDirectory *p_efsd, Ve } } -void FileSystemDock::_find_remaps(EditorFileSystemDirectory *p_efsd, const HashMap<String, String> &r_renames, Vector<String> &r_to_remaps) const { +void FileSystemDock::_find_remaps(EditorFileSystemDirectory *p_efsd, const Vector<String> &r_renames, Vector<String> &r_to_remaps) const { for (int i = 0; i < p_efsd->get_subdir_count(); i++) { _find_remaps(p_efsd->get_subdir(i), r_renames, r_to_remaps); } @@ -1532,7 +1533,12 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin } } -void FileSystemDock::_update_resource_paths_after_move(const HashMap<String, String> &p_renames) const { +void FileSystemDock::_update_resource_paths_after_move(const HashMap<String, String> &p_renames, const HashMap<String, ResourceUID::ID> &p_uids) const { + // Update the paths in ResourceUID, so that UIDs remain valid. + for (const KeyValue<String, ResourceUID::ID> &pair : p_uids) { + ResourceUID::get_singleton()->set_id(pair.value, p_renames[pair.key]); + } + // Rename all resources loaded, be it subresources or actual resources. List<Ref<Resource>> cached; ResourceCache::get_cached_resources(&cached); @@ -1552,53 +1558,33 @@ void FileSystemDock::_update_resource_paths_after_move(const HashMap<String, Str r->set_path(base_path + extra_path); } - - for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) { - String file_path; - if (i == EditorNode::get_editor_data().get_edited_scene()) { - if (!get_tree()->get_edited_scene_root()) { - continue; - } - - file_path = get_tree()->get_edited_scene_root()->get_scene_file_path(); - } else { - file_path = EditorNode::get_editor_data().get_scene_path(i); - } - - if (p_renames.has(file_path)) { - file_path = p_renames[file_path]; - } - - if (i == EditorNode::get_editor_data().get_edited_scene()) { - get_tree()->get_edited_scene_root()->set_scene_file_path(file_path); - } else { - EditorNode::get_editor_data().set_scene_path(i, file_path); - } - } } -void FileSystemDock::_update_dependencies_after_move(const HashMap<String, String> &p_renames) const { +void FileSystemDock::_update_dependencies_after_move(const HashMap<String, String> &p_renames, const Vector<String> &p_remaps) const { // The following code assumes that the following holds: // 1) EditorFileSystem contains the old paths/folder structure from before the rename/move. // 2) ResourceLoader can use the new paths without needing to call rescan. - Vector<String> remaps; - _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps); - for (int i = 0; i < remaps.size(); ++i) { + List<String> scenes_to_reload; + for (int i = 0; i < p_remaps.size(); ++i) { // Because we haven't called a rescan yet the found remap might still be an old path itself. - String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i]; + String file = p_renames.has(p_remaps[i]) ? p_renames[p_remaps[i]] : p_remaps[i]; print_verbose("Remapping dependencies for: " + file); Error err = ResourceLoader::rename_dependencies(file, p_renames); if (err == OK) { if (ResourceLoader::get_resource_type(file) == "PackedScene") { - callable_mp(EditorNode::get_singleton(), &EditorNode::reload_scene).bind(file).call_deferred(); + scenes_to_reload.push_back(file); } } else { - EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n"); + EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + p_remaps[i] + "\n"); } } + + for (const String &E : scenes_to_reload) { + EditorNode::get_singleton()->reload_scene(E); + } } -void FileSystemDock::_update_project_settings_after_move(const HashMap<String, String> &p_renames) const { +void FileSystemDock::_update_project_settings_after_move(const HashMap<String, String> &p_renames, const HashMap<String, String> &p_folders_renames) { // Find all project settings of type FILE and replace them if needed. const HashMap<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info(); for (const KeyValue<StringName, PropertyInfo> &E : prop_info) { @@ -1626,6 +1612,14 @@ void FileSystemDock::_update_project_settings_after_move(const HashMap<String, S } } } + + // Update folder colors. + for (const KeyValue<String, String> &rename : p_folders_renames) { + if (assigned_folder_colors.has(rename.key)) { + assigned_folder_colors[rename.value] = assigned_folder_colors[rename.key]; + assigned_folder_colors.erase(rename.key); + } + } ProjectSettings::get_singleton()->save(); } @@ -1669,21 +1663,6 @@ void FileSystemDock::_update_favorites_list_after_move(const HashMap<String, Str EditorSettings::get_singleton()->set_favorites(new_favorites); } -void FileSystemDock::_save_scenes_after_move(const HashMap<String, String> &p_renames) const { - Vector<String> remaps; - _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps); - Vector<String> new_filenames; - - for (int i = 0; i < remaps.size(); ++i) { - String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i]; - if (ResourceLoader::get_resource_type(file) == "PackedScene") { - new_filenames.push_back(file); - } - } - - EditorNode::get_singleton()->save_scene_list(new_filenames); -} - void FileSystemDock::_make_scene_confirm() { const String scene_path = make_scene_dialog->get_scene_path(); @@ -1720,6 +1699,11 @@ void FileSystemDock::_folder_removed(String p_folder) { current_path = current_path.get_base_dir(); } + if (assigned_folder_colors.has(p_folder)) { + assigned_folder_colors.erase(p_folder); + _update_folder_colors_setting(); + } + current_path_line_edit->set_text(current_path); EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_filesystem_path(current_path); if (efd) { @@ -1746,7 +1730,7 @@ void FileSystemDock::_rename_operation_confirm() { } else if (new_name.contains("/") || new_name.contains("\\") || new_name.contains(":")) { EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters.")); rename_error = true; - } else if (new_name.begins_with(".")) { + } else if (new_name[0] == '.') { EditorNode::get_singleton()->show_warning(TTR("This filename begins with a dot rendering the file invisible to the editor.\nIf you want to rename it anyway, use your operating system's file manager.")); rename_error = true; } else if (to_rename.is_file && to_rename.path.get_extension() != new_name.get_extension()) { @@ -1776,7 +1760,7 @@ void FileSystemDock::_rename_operation_confirm() { // Present a more user friendly warning for name conflict. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); -#if defined(WINDOWS_ENABLED) || defined(UWP_ENABLED) +#if defined(WINDOWS_ENABLED) // Workaround case insensitivity on Windows. if ((da->file_exists(new_path) || da->dir_exists(new_path)) && new_path.to_lower() != old_path.to_lower()) { #else @@ -1787,15 +1771,19 @@ void FileSystemDock::_rename_operation_confirm() { return; } + Vector<String> old_paths; + HashMap<String, ResourceUID::ID> uids; + Vector<String> remaps; + _before_move(old_paths, uids, remaps); + HashMap<String, String> file_renames; HashMap<String, String> folder_renames; _try_move_item(to_rename, new_path, file_renames, folder_renames); int current_tab = EditorSceneTabs::get_singleton()->get_current_tab(); - _save_scenes_after_move(file_renames); // save scenes before updating - _update_dependencies_after_move(file_renames); - _update_resource_paths_after_move(file_renames); - _update_project_settings_after_move(file_renames); + _update_resource_paths_after_move(file_renames, uids); + _update_dependencies_after_move(file_renames, remaps); + _update_project_settings_after_move(file_renames, folder_renames); _update_favorites_list_after_move(file_renames, folder_renames); EditorSceneTabs::get_singleton()->set_current_tab(current_tab); @@ -1803,9 +1791,6 @@ void FileSystemDock::_rename_operation_confirm() { print_verbose("FileSystem: calling rescan."); _rescan(); - print_verbose("FileSystem: saving moved scenes."); - _save_scenes_after_move(file_renames); - current_path = new_path; current_path_line_edit->set_text(current_path); } @@ -1818,6 +1803,9 @@ void FileSystemDock::_duplicate_operation_confirm() { } else if (new_name.contains("/") || new_name.contains("\\") || new_name.contains(":")) { EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters.")); return; + } else if (new_name[0] == '.') { + EditorNode::get_singleton()->show_warning(TTR("Name begins with a dot.")); + return; } String base_dir = to_duplicate.path.get_base_dir(); @@ -1920,6 +1908,11 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop } } + Vector<String> old_paths; + HashMap<String, ResourceUID::ID> uids; + Vector<String> remaps; + _before_move(old_paths, uids, remaps); + bool is_moved = false; HashMap<String, String> file_renames; HashMap<String, String> folder_renames; @@ -1930,7 +1923,6 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop if (!to_move[i].is_file) { new_path = new_path.path_join(old_path.trim_suffix("/").get_file()); - print_line(new_path); } if (old_path != new_path) { @@ -1941,10 +1933,9 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop if (is_moved) { int current_tab = EditorSceneTabs::get_singleton()->get_current_tab(); - _save_scenes_after_move(file_renames); // Save scenes before updating. - _update_dependencies_after_move(file_renames); - _update_resource_paths_after_move(file_renames); - _update_project_settings_after_move(file_renames); + _update_resource_paths_after_move(file_renames, uids); + _update_dependencies_after_move(file_renames, remaps); + _update_project_settings_after_move(file_renames, folder_renames); _update_favorites_list_after_move(file_renames, folder_renames); EditorSceneTabs::get_singleton()->set_current_tab(current_tab); @@ -1952,15 +1943,28 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop print_verbose("FileSystem: calling rescan."); _rescan(); - print_verbose("FileSystem: saving moved scenes."); - _save_scenes_after_move(file_renames); - current_path = p_to_path; current_path_line_edit->set_text(current_path); } } } +void FileSystemDock::_before_move(Vector<String> &r_old_paths, HashMap<String, ResourceUID::ID> &r_uids, Vector<String> &r_remaps) const { + for (int i = 0; i < to_move.size(); i++) { + r_old_paths.push_back(to_move[i].path); + ResourceUID::ID uid = ResourceLoader::get_resource_uid(to_move[i].path); + if (uid != ResourceUID::INVALID_ID) { + r_uids[to_move[i].path] = uid; + } + } + + _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), r_old_paths, r_remaps); + + // Open scenes with dependencies on the ones about to be moved will be reloaded, + // so save them first to prevent losing unsaved changes. + EditorNode::get_singleton()->save_scene_list(r_remaps); +} + Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) const { // Build a list of selected items with the active one at the first position. Vector<String> selected_strings; @@ -2345,7 +2349,7 @@ void FileSystemDock::_resource_created() { ERR_FAIL_COND(!c); Resource *r = Object::cast_to<Resource>(c); - ERR_FAIL_COND(!r); + ERR_FAIL_NULL(r); PackedScene *scene = Object::cast_to<PackedScene>(r); if (scene) { @@ -2764,6 +2768,15 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori } } +void FileSystemDock::_update_folder_colors_setting() { + if (!ProjectSettings::get_singleton()->has_setting("file_customization/folder_colors")) { + ProjectSettings::get_singleton()->set_setting("file_customization/folder_colors", assigned_folder_colors); + } else if (assigned_folder_colors.is_empty()) { + ProjectSettings::get_singleton()->set_setting("file_customization/folder_colors", Variant()); + } + ProjectSettings::get_singleton()->save(); +} + void FileSystemDock::_folder_color_index_pressed(int p_index, PopupMenu *p_menu) { Variant chosen_color_name = p_menu->get_item_metadata(p_index); Vector<String> selected; @@ -2794,7 +2807,7 @@ void FileSystemDock::_folder_color_index_pressed(int p_index, PopupMenu *p_menu) } } - ProjectSettings::get_singleton()->save(); + _update_folder_colors_setting(); _update_tree(get_uncollapsed_paths()); _update_file_list(true); @@ -2844,18 +2857,18 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str if (all_files) { if (all_files_scenes) { if (filenames.size() == 1) { - p_popup->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Open Scene"), FILE_OPEN); - p_popup->add_icon_item(get_theme_icon(SNAME("CreateNewSceneFrom"), SNAME("EditorIcons")), TTR("New Inherited Scene"), FILE_INHERIT); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTR("Open Scene"), FILE_OPEN); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("CreateNewSceneFrom")), TTR("New Inherited Scene"), FILE_INHERIT); if (GLOBAL_GET("application/run/main_scene") != filenames[0]) { - p_popup->add_icon_item(get_theme_icon(SNAME("PlayScene"), SNAME("EditorIcons")), TTR("Set As Main Scene"), FILE_MAIN_SCENE); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("PlayScene")), TTR("Set As Main Scene"), FILE_MAIN_SCENE); } } else { - p_popup->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Open Scenes"), FILE_OPEN); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTR("Open Scenes"), FILE_OPEN); } - p_popup->add_icon_item(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), TTR("Instantiate"), FILE_INSTANTIATE); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Instance")), TTR("Instantiate"), FILE_INSTANTIATE); p_popup->add_separator(); } else if (filenames.size() == 1) { - p_popup->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Open"), FILE_OPEN); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTR("Open"), FILE_OPEN); p_popup->add_separator(); } @@ -2873,22 +2886,22 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str p_popup->add_child(new_menu); p_popup->add_submenu_item(TTR("Create New"), "New", FILE_NEW); - p_popup->set_item_icon(p_popup->get_item_index(FILE_NEW), get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + p_popup->set_item_icon(p_popup->get_item_index(FILE_NEW), get_editor_theme_icon(SNAME("Add"))); - new_menu->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR("Folder..."), FILE_NEW_FOLDER); - new_menu->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("Scene..."), FILE_NEW_SCENE); - new_menu->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("Script..."), FILE_NEW_SCRIPT); - new_menu->add_icon_item(get_theme_icon(SNAME("Object"), SNAME("EditorIcons")), TTR("Resource..."), FILE_NEW_RESOURCE); - new_menu->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("TextFile..."), FILE_NEW_TEXTFILE); + new_menu->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTR("Folder..."), FILE_NEW_FOLDER); + new_menu->add_icon_item(get_editor_theme_icon(SNAME("PackedScene")), TTR("Scene..."), FILE_NEW_SCENE); + new_menu->add_icon_item(get_editor_theme_icon(SNAME("Script")), TTR("Script..."), FILE_NEW_SCRIPT); + new_menu->add_icon_item(get_editor_theme_icon(SNAME("Object")), TTR("Resource..."), FILE_NEW_RESOURCE); + new_menu->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTR("TextFile..."), FILE_NEW_TEXTFILE); p_popup->add_separator(); } if (all_folders && foldernames.size() > 0) { - p_popup->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Expand Folder"), FILE_OPEN); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTR("Expand Folder"), FILE_OPEN); if (foldernames.size() == 1) { - p_popup->add_icon_item(get_theme_icon(SNAME("GuiTreeArrowDown"), SNAME("EditorIcons")), TTR("Expand Hierarchy"), FOLDER_EXPAND_ALL); - p_popup->add_icon_item(get_theme_icon(SNAME("GuiTreeArrowRight"), SNAME("EditorIcons")), TTR("Collapse Hierarchy"), FOLDER_COLLAPSE_ALL); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("GuiTreeArrowDown")), TTR("Expand Hierarchy"), FOLDER_EXPAND_ALL); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("GuiTreeArrowRight")), TTR("Collapse Hierarchy"), FOLDER_COLLAPSE_ALL); } p_popup->add_separator(); @@ -2900,14 +2913,14 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str p_popup->add_child(folder_colors_menu); p_popup->add_submenu_item(TTR("Set Folder Color..."), "FolderColor"); - p_popup->set_item_icon(-1, get_theme_icon(SNAME("CanvasItem"), SNAME("EditorIcons"))); + p_popup->set_item_icon(-1, get_editor_theme_icon(SNAME("Paint"))); - folder_colors_menu->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR("Default (Reset)")); + folder_colors_menu->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTR("Default (Reset)")); folder_colors_menu->set_item_icon_modulate(0, get_theme_color(SNAME("folder_icon_color"), SNAME("FileDialog"))); folder_colors_menu->add_separator(); for (const KeyValue<String, Color> &E : folder_colors) { - folder_colors_menu->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR(E.key.capitalize())); + folder_colors_menu->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTR(E.key.capitalize())); folder_colors_menu->set_item_icon_modulate(-1, editor_is_dark_theme ? E.value : E.value * 2); folder_colors_menu->set_item_metadata(-1, E.key); @@ -2916,29 +2929,29 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } if (p_paths.size() == 1) { - p_popup->add_icon_shortcut(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/copy_path"), FILE_COPY_PATH); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionCopy")), ED_GET_SHORTCUT("filesystem_dock/copy_path"), FILE_COPY_PATH); if (ResourceLoader::get_resource_uid(p_paths[0]) != ResourceUID::INVALID_ID) { - p_popup->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/copy_uid"), FILE_COPY_UID); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Instance")), ED_GET_SHORTCUT("filesystem_dock/copy_uid"), FILE_COPY_UID); } if (p_paths[0] != "res://") { - p_popup->add_icon_shortcut(get_theme_icon(SNAME("Rename"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/rename"), FILE_RENAME); - p_popup->add_icon_shortcut(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/duplicate"), FILE_DUPLICATE); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Rename")), ED_GET_SHORTCUT("filesystem_dock/rename"), FILE_RENAME); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Duplicate")), ED_GET_SHORTCUT("filesystem_dock/duplicate"), FILE_DUPLICATE); } } if (p_paths.size() > 1 || p_paths[0] != "res://") { - p_popup->add_icon_item(get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons")), TTR("Move/Duplicate To..."), FILE_MOVE); - p_popup->add_icon_shortcut(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/delete"), FILE_REMOVE); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Move/Duplicate To..."), FILE_MOVE); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Remove")), ED_GET_SHORTCUT("filesystem_dock/delete"), FILE_REMOVE); } p_popup->add_separator(); if (p_paths.size() >= 1) { if (!all_favorites) { - p_popup->add_icon_item(get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons")), TTR("Add to Favorites"), FILE_ADD_FAVORITE); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Favorites")), TTR("Add to Favorites"), FILE_ADD_FAVORITE); } if (!all_not_favorites) { - p_popup->add_icon_item(get_theme_icon(SNAME("NonFavorite"), SNAME("EditorIcons")), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("NonFavorite")), TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE); } { @@ -2968,7 +2981,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } if (resource_valid) { - p_popup->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Reimport"), FILE_REIMPORT); + p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTR("Reimport"), FILE_REIMPORT); } } } @@ -2982,10 +2995,10 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str // Opening the system file manager is not supported on the Android and web editors. const bool is_directory = fpath.ends_with("/"); const String item_text = is_directory ? TTR("Open in File Manager") : TTR("Show in File Manager"); - p_popup->add_icon_shortcut(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Filesystem")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); p_popup->set_item_text(p_popup->get_item_index(FILE_SHOW_IN_EXPLORER), item_text); if (!is_directory) { - p_popup->add_icon_shortcut(get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/open_in_external_program"), FILE_OPEN_EXTERNAL); + p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("ExternalLink")), ED_GET_SHORTCUT("filesystem_dock/open_in_external_program"), FILE_OPEN_EXTERNAL); } #endif @@ -3022,15 +3035,15 @@ void FileSystemDock::_tree_empty_click(const Vector2 &p_pos, MouseButton p_butto current_path = "res://"; tree_popup->clear(); tree_popup->reset_size(); - tree_popup->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR("New Folder..."), FILE_NEW_FOLDER); - tree_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE); - tree_popup->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("New Script..."), FILE_NEW_SCRIPT); - tree_popup->add_icon_item(get_theme_icon(SNAME("Object"), SNAME("EditorIcons")), TTR("New Resource..."), FILE_NEW_RESOURCE); - tree_popup->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("New TextFile..."), FILE_NEW_TEXTFILE); + tree_popup->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTR("New Folder..."), FILE_NEW_FOLDER); + tree_popup->add_icon_item(get_editor_theme_icon(SNAME("PackedScene")), TTR("New Scene..."), FILE_NEW_SCENE); + tree_popup->add_icon_item(get_editor_theme_icon(SNAME("Script")), TTR("New Script..."), FILE_NEW_SCRIPT); + tree_popup->add_icon_item(get_editor_theme_icon(SNAME("Object")), TTR("New Resource..."), FILE_NEW_RESOURCE); + tree_popup->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTR("New TextFile..."), FILE_NEW_TEXTFILE); #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED) // Opening the system file manager is not supported on the Android and web editors. tree_popup->add_separator(); - tree_popup->add_icon_shortcut(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); + tree_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Filesystem")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); #endif tree_popup->set_position(tree->get_screen_position() + p_pos); @@ -3086,13 +3099,13 @@ void FileSystemDock::_file_list_empty_clicked(const Vector2 &p_pos, MouseButton file_list_popup->clear(); file_list_popup->reset_size(); - file_list_popup->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR("New Folder..."), FILE_NEW_FOLDER); - file_list_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE); - file_list_popup->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("New Script..."), FILE_NEW_SCRIPT); - file_list_popup->add_icon_item(get_theme_icon(SNAME("Object"), SNAME("EditorIcons")), TTR("New Resource..."), FILE_NEW_RESOURCE); - file_list_popup->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("New TextFile..."), FILE_NEW_TEXTFILE); + file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTR("New Folder..."), FILE_NEW_FOLDER); + file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("PackedScene")), TTR("New Scene..."), FILE_NEW_SCENE); + file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("Script")), TTR("New Script..."), FILE_NEW_SCRIPT); + file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("Object")), TTR("New Resource..."), FILE_NEW_RESOURCE); + file_list_popup->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), TTR("New TextFile..."), FILE_NEW_TEXTFILE); file_list_popup->add_separator(); - file_list_popup->add_icon_shortcut(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); + file_list_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Filesystem")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER); file_list_popup->set_position(files->get_screen_position() + p_pos); file_list_popup->reset_size(); |