From 0f026193b2505584a18ac56b1b92cf202696398f Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:41:33 +0200 Subject: [PATCH] Update folder colors when moving or renaming --- editor/filesystem_dock.cpp | 36 ++++++++++++++++++++++++++---------- editor/filesystem_dock.h | 4 +++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index ae26075efac..09f5190eff6 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1599,7 +1599,7 @@ void FileSystemDock::_update_dependencies_after_move(const HashMap &p_renames) const { +void FileSystemDock::_update_project_settings_after_move(const HashMap &p_renames, const HashMap &p_folders_renames) { // Find all project settings of type FILE and replace them if needed. const HashMap prop_info = ProjectSettings::get_singleton()->get_custom_property_info(); for (const KeyValue &E : prop_info) { @@ -1627,6 +1627,14 @@ void FileSystemDock::_update_project_settings_after_move(const HashMap &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(); } @@ -1721,6 +1729,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) { @@ -1796,7 +1809,7 @@ void FileSystemDock::_rename_operation_confirm() { _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_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); @@ -1944,7 +1957,7 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool p_cop _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_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); @@ -2764,6 +2777,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 selected; @@ -2794,13 +2816,7 @@ void FileSystemDock::_folder_color_index_pressed(int p_index, PopupMenu *p_menu) } } - 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(); + _update_folder_colors_setting(); _update_tree(get_uncollapsed_paths()); _update_file_list(true); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 95b78f14c9d..93720692fb5 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -269,9 +269,11 @@ private: void _update_resource_paths_after_move(const HashMap &p_renames) const; void _save_scenes_after_move(const HashMap &p_renames) const; void _update_favorites_list_after_move(const HashMap &p_files_renames, const HashMap &p_folders_renames) const; - void _update_project_settings_after_move(const HashMap &p_renames) const; + void _update_project_settings_after_move(const HashMap &p_renames, const HashMap &p_folders_renames); String _get_unique_name(const FileOrFolder &p_entry, const String &p_at_path); + void _update_folder_colors_setting(); + void _resource_removed(const Ref &p_resource); void _file_removed(String p_file); void _folder_removed(String p_folder);