Fix favorite folder colors
This commit is contained in:
parent
03bd8ba9c2
commit
1725231e14
@ -430,7 +430,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
|
||||
} else if (favorite.ends_with("/")) {
|
||||
text = favorite.substr(0, favorite.length() - 1).get_file();
|
||||
icon = folder_icon;
|
||||
color = assigned_folder_colors.has(favorite) ? folder_colors[assigned_folder_colors[favorite]] : default_folder_color;
|
||||
color = FileSystemDock::get_dir_icon_color(favorite, default_folder_color);
|
||||
} else {
|
||||
text = favorite.get_file();
|
||||
int index;
|
||||
@ -3951,6 +3951,30 @@ void FileSystemDock::_file_sort_popup(int p_id) {
|
||||
set_file_sort((FileSortOption)p_id);
|
||||
}
|
||||
|
||||
// TODO: Could use a unit test.
|
||||
Color FileSystemDock::get_dir_icon_color(const String &p_dir_path, const Color &p_default) {
|
||||
if (!singleton) { // This method can be called from the project manager.
|
||||
return p_default;
|
||||
}
|
||||
Color folder_icon_color = p_default;
|
||||
|
||||
// Check for a folder color to inherit (if one is assigned).
|
||||
String parent_dir = ProjectSettings::get_singleton()->localize_path(p_dir_path);
|
||||
while (!parent_dir.is_empty() && parent_dir != "res://") {
|
||||
if (!parent_dir.ends_with("/")) {
|
||||
parent_dir += "/";
|
||||
}
|
||||
|
||||
const String color_name = singleton->assigned_folder_colors.get(parent_dir, String());
|
||||
if (!color_name.is_empty()) {
|
||||
folder_icon_color = singleton->folder_colors[color_name];
|
||||
break;
|
||||
}
|
||||
parent_dir = parent_dir.trim_suffix("/").get_base_dir();
|
||||
}
|
||||
return folder_icon_color;
|
||||
}
|
||||
|
||||
const HashMap<String, Color> &FileSystemDock::get_folder_colors() const {
|
||||
return folder_colors;
|
||||
}
|
||||
|
@ -383,6 +383,8 @@ public:
|
||||
static constexpr double ITEM_ALPHA_MAX = 0.15;
|
||||
static constexpr double ITEM_BG_DARK_SCALE = 0.3;
|
||||
|
||||
static Color get_dir_icon_color(const String &p_dir_path, const Color &p_default);
|
||||
|
||||
const HashMap<String, Color> &get_folder_colors() const;
|
||||
Dictionary get_assigned_folder_colors() const;
|
||||
|
||||
|
@ -973,35 +973,6 @@ void EditorFileDialog::update_file_name() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Could use a unit test.
|
||||
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();
|
||||
Dictionary assigned_folder_colors = FileSystemDock::get_singleton()->get_assigned_folder_colors();
|
||||
|
||||
Color folder_icon_color = theme_cache.folder_icon_color;
|
||||
|
||||
// Check for a folder color to inherit (if one is assigned).
|
||||
String parent_dir = ProjectSettings::get_singleton()->localize_path(p_dir_path);
|
||||
while (!parent_dir.is_empty() && parent_dir != "res://") {
|
||||
if (!parent_dir.ends_with("/")) {
|
||||
parent_dir += "/";
|
||||
}
|
||||
if (assigned_folder_colors.has(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();
|
||||
}
|
||||
|
||||
return folder_icon_color;
|
||||
}
|
||||
|
||||
// DO NOT USE THIS FUNCTION UNLESS NEEDED, CALL INVALIDATE() INSTEAD.
|
||||
void EditorFileDialog::update_file_list() {
|
||||
int thumbnail_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
|
||||
@ -1155,7 +1126,7 @@ void EditorFileDialog::update_file_list() {
|
||||
d["bundle"] = bundle;
|
||||
|
||||
item_list->set_item_metadata(-1, d);
|
||||
item_list->set_item_icon_modulate(-1, get_dir_icon_color(String(d["path"])));
|
||||
item_list->set_item_icon_modulate(-1, FileSystemDock::get_dir_icon_color(String(d["path"]), theme_cache.folder_icon_color));
|
||||
}
|
||||
|
||||
dirs.pop_front();
|
||||
@ -1840,7 +1811,7 @@ void EditorFileDialog::_update_favorites() {
|
||||
favorites->add_item(favorited_names[i], theme_cache.folder);
|
||||
favorites->set_item_tooltip(-1, favorited_paths[i]);
|
||||
favorites->set_item_metadata(-1, favorited_paths[i]);
|
||||
favorites->set_item_icon_modulate(-1, get_dir_icon_color(favorited_paths[i]));
|
||||
favorites->set_item_icon_modulate(-1, FileSystemDock::get_dir_icon_color(favorited_paths[i], theme_cache.folder_icon_color));
|
||||
|
||||
if (i == current_favorite) {
|
||||
favorite->set_pressed(true);
|
||||
@ -1925,7 +1896,7 @@ void EditorFileDialog::_update_recent() {
|
||||
recent->add_item(recentd_names[i], theme_cache.folder);
|
||||
recent->set_item_tooltip(-1, recentd_paths[i]);
|
||||
recent->set_item_metadata(-1, recentd_paths[i]);
|
||||
recent->set_item_icon_modulate(-1, get_dir_icon_color(recentd_paths[i]));
|
||||
recent->set_item_icon_modulate(-1, FileSystemDock::get_dir_icon_color(recentd_paths[i], theme_cache.folder_icon_color));
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
|
@ -301,8 +301,6 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Color get_dir_icon_color(const String &p_dir_path);
|
||||
|
||||
virtual void set_visible(bool p_visible) override;
|
||||
virtual void popup(const Rect2i &p_rect = Rect2i()) override;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user