Merge pull request #23161 from groud/fix_fav_in_open_dialog

Fixes favorites not working in the open dialog
This commit is contained in:
Rémi Verschelde 2018-10-24 19:01:47 +02:00 committed by GitHub
commit 468c2999d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -1135,14 +1135,10 @@ void EditorFileDialog::_update_drives() {
} }
void EditorFileDialog::_favorite_selected(int p_idx) { void EditorFileDialog::_favorite_selected(int p_idx) {
dir_access->change_dir(favorites->get_item_metadata(p_idx));
Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
ERR_FAIL_INDEX(p_idx, favorited.size());
dir_access->change_dir(favorited[p_idx]);
file->set_text(""); file->set_text("");
invalidate();
update_dir(); update_dir();
invalidate();
_push_history(); _push_history();
} }
@ -1192,7 +1188,7 @@ void EditorFileDialog::_update_favorites() {
bool res = access == ACCESS_RESOURCES; bool res = access == ACCESS_RESOURCES;
String current = get_current_dir(); String current = get_current_dir();
Ref<Texture> star = get_icon("Favorites", "EditorIcons"); Ref<Texture> folder_icon = get_icon("Folder", "EditorIcons");
favorites->clear(); favorites->clear();
favorite->set_pressed(false); favorite->set_pressed(false);
@ -1203,16 +1199,23 @@ void EditorFileDialog::_update_favorites() {
if (cres != res) if (cres != res)
continue; continue;
String name = favorited[i]; String name = favorited[i];
bool setthis = false;
bool setthis = name == current;
if (res && name == "res://") { if (res && name == "res://") {
if (name == current)
setthis = true;
name = "/"; name = "/";
} else if (name.ends_with("/")) {
if (name == current)
setthis = true;
name = name.substr(0, name.length() - 1);
name = name.get_file();
favorites->add_item(name, folder_icon);
} else { } else {
name = name.get_file() + "/"; continue; // We don't handle favorite files here
} }
favorites->add_item(name, star);
favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]); favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]);
if (setthis) { if (setthis) {