Fix various issues with the folder color lookup

This commit is contained in:
Yuri Sizov 2023-12-14 20:43:46 +01:00
parent a6c0c90058
commit efa8c46fab

View file

@ -769,19 +769,26 @@ void EditorFileDialog::update_file_name() {
// TODO: Could use a unit test. // TODO: Could use a unit test.
Color EditorFileDialog::get_dir_icon_color(const String &p_dir_path) { Color EditorFileDialog::get_dir_icon_color(const String &p_dir_path) {
if (!FileSystemDock::get_singleton()) { // This dialog can be called from the project manager.
return theme_cache.folder_icon_color;
}
const HashMap<String, Color> &folder_colors = FileSystemDock::get_singleton()->get_folder_colors(); const HashMap<String, Color> &folder_colors = FileSystemDock::get_singleton()->get_folder_colors();
Dictionary assigned_folder_colors = FileSystemDock::get_singleton()->get_assigned_folder_colors(); Dictionary assigned_folder_colors = FileSystemDock::get_singleton()->get_assigned_folder_colors();
Color folder_icon_color = theme_cache.folder_icon_color; Color folder_icon_color = theme_cache.folder_icon_color;
// Check for a folder color to inherit (if one is assigned). // Check for a folder color to inherit (if one is assigned).
String parent_dir = p_dir_path; String parent_dir = ProjectSettings::get_singleton()->localize_path(p_dir_path);
while (parent_dir != "res://" && folder_icon_color == theme_cache.folder_icon_color) { while (!parent_dir.is_empty() && parent_dir != "res://") {
if (!parent_dir.ends_with("/")) { if (!parent_dir.ends_with("/")) {
parent_dir += "/"; parent_dir += "/";
} }
if (assigned_folder_colors.has(parent_dir)) { if (assigned_folder_colors.has(parent_dir)) {
folder_icon_color = folder_colors[assigned_folder_colors[parent_dir]]; folder_icon_color = folder_colors[assigned_folder_colors[parent_dir]];
if (folder_icon_color != theme_cache.folder_icon_color) {
break;
}
} }
parent_dir = parent_dir.trim_suffix("/").get_base_dir(); parent_dir = parent_dir.trim_suffix("/").get_base_dir();
} }