Fix favorite files handling

This commit is contained in:
kobewi
2026-01-19 14:43:01 +01:00
parent 5f9a510441
commit ed4689c4ee
7 changed files with 69 additions and 18 deletions

View File

@@ -409,6 +409,8 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
}
if (fav_changed) {
EditorSettings::get_singleton()->set_favorites(favorite_paths);
// Setting favorites causes the tree to update, so continuing is redundant.
return;
}
Ref<Texture2D> folder_icon = get_editor_theme_icon(SNAME("Folder"));
@@ -2479,7 +2481,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
}
}
EditorSettings::get_singleton()->set_favorites(favorites_list);
_update_tree(get_uncollapsed_paths());
} break;
case FILE_MENU_REMOVE_FAVORITE: {
@@ -2489,10 +2490,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
favorites_list.erase(p_selected[i]);
}
EditorSettings::get_singleton()->set_favorites(favorites_list);
_update_tree(get_uncollapsed_paths());
if (current_path == "Favorites") {
_update_file_list(true);
}
} break;
case FILE_MENU_SHOW_IN_FILESYSTEM: {
@@ -4553,6 +4550,7 @@ FileSystemDock::FileSystemDock() {
file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS;
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &FileSystemDock::_project_settings_changed));
EditorSettings::get_singleton()->connect("_favorites_changed", callable_mp(this, &FileSystemDock::update_all));
main_scene_path = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
add_resource_tooltip_plugin(memnew(EditorTextureTooltipPlugin));

View File

@@ -275,6 +275,7 @@ private:
void _update_tree(const Vector<String> &p_uncollapsed_paths = Vector<String>(), bool p_uncollapse_root = false, bool p_scroll_to_selected = true);
void _navigate_to_path(const String &p_path, bool p_select_in_favorites = false, bool p_grab_focus = false);
bool _update_filtered_items(TreeItem *p_tree_item = nullptr);
void _append_favorite_items();
void _file_list_gui_input(Ref<InputEvent> p_event);
void _tree_gui_input(Ref<InputEvent> p_event);

View File

@@ -126,9 +126,33 @@ void EditorFileDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
// Synchronize back favorites and recent directories, in case they have changed.
EditorSettings::get_singleton()->set_favorites(get_favorite_list(), false);
EditorSettings::get_singleton()->set_recent_dirs(get_recent_list(), false);
// Synchronize back favorites and recent directories if they have changed.
if (favorites_changed) {
Vector<String> settings_favorites = EditorSettings::get_singleton()->get_favorites();
Vector<String> current_favorites = get_favorite_list();
LocalVector<String> to_erase;
// The favorite list in EditorSettings may have files in between. They need to be handled properly to preserve order.
for (const String &fav : settings_favorites) {
if (!fav.ends_with("/")) {
continue;
}
int64_t idx = current_favorites.find(fav);
if (idx == -1) {
to_erase.push_back(fav);
} else {
current_favorites.remove_at(idx);
}
}
for (const String &fav : to_erase) {
settings_favorites.erase(fav);
}
settings_favorites.append_array(current_favorites);
EditorSettings::get_singleton()->set_favorites(settings_favorites, false);
}
if (recents_changed) {
EditorSettings::get_singleton()->set_recent_dirs(get_recent_list(), false);
}
}
} break;

View File

@@ -1595,13 +1595,11 @@ void EditorSettings::save_project_metadata() {
}
void EditorSettings::set_favorites(const Vector<String> &p_favorites, bool p_update_file_dialog) {
if (p_update_file_dialog) {
FileDialog::set_favorite_list(p_favorites);
} else if (p_favorites == favorites) {
// If the list came from EditorFileDialog, it may be the same as before.
return;
}
set_favorites_bind(p_favorites);
if (p_update_file_dialog) {
FileDialog::set_favorite_list(get_favorite_folders());
}
emit_signal(SNAME("_favorites_changed"));
}
void EditorSettings::set_favorites_bind(const Vector<String> &p_favorites) {
@@ -1636,6 +1634,22 @@ Vector<String> EditorSettings::get_favorites() const {
return favorites;
}
Vector<String> EditorSettings::get_favorite_folders() const {
Vector<String> folder_favorites;
folder_favorites.resize(favorites.size());
String *folder_write = folder_favorites.ptrw();
int i = 0;
for (const String &fav : favorites) {
if (fav.ends_with("/")) {
folder_write[i] = fav;
i++;
}
}
folder_favorites.resize(i);
return folder_favorites;
}
HashMap<String, PackedStringArray> EditorSettings::get_favorite_properties() const {
return favorite_properties;
}
@@ -1643,9 +1657,6 @@ HashMap<String, PackedStringArray> EditorSettings::get_favorite_properties() con
void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs, bool p_update_file_dialog) {
if (p_update_file_dialog) {
FileDialog::set_recent_list(p_recent_dirs);
} else if (p_recent_dirs == recent_dirs) {
// If the list came from EditorFileDialog, it may be the same as before.
return;
}
set_recent_dirs_bind(p_recent_dirs);
}
@@ -1694,7 +1705,7 @@ void EditorSettings::load_favorites_and_recent_dirs() {
line = f->get_line().strip_edges();
}
}
FileDialog::set_favorite_list(favorites);
FileDialog::set_favorite_list(get_favorite_folders());
/// Inspector Favorites
@@ -2282,6 +2293,7 @@ void EditorSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("mark_setting_changed", "setting"), &EditorSettings::mark_setting_changed);
ADD_SIGNAL(MethodInfo("settings_changed"));
ADD_SIGNAL(MethodInfo("_favorites_changed"));
BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
}

View File

@@ -180,6 +180,7 @@ public:
void set_favorites(const Vector<String> &p_favorites, bool p_update_file_dialog = true);
void set_favorites_bind(const Vector<String> &p_favorites);
Vector<String> get_favorites() const;
Vector<String> get_favorite_folders() const;
void set_favorite_properties(const HashMap<String, PackedStringArray> &p_favorite_properties);
HashMap<String, PackedStringArray> get_favorite_properties() const;
void set_recent_dirs(const Vector<String> &p_recent_dirs, bool p_update_file_dialog = true);