1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Misc code cleanup in EditorFileDialog

This commit is contained in:
kobewi
2024-08-15 08:17:40 +02:00
parent 33c30b9e63
commit b67eb68e5b

View File

@@ -1522,7 +1522,7 @@ void EditorFileDialog::_favorite_move_down() {
} }
void EditorFileDialog::_update_favorites() { void EditorFileDialog::_update_favorites() {
bool res = (access == ACCESS_RESOURCES); bool access_resources = (access == ACCESS_RESOURCES);
String current = get_current_dir(); String current = get_current_dir();
favorites->clear(); favorites->clear();
@@ -1538,8 +1538,11 @@ void EditorFileDialog::_update_favorites() {
for (int i = 0; i < favorited.size(); i++) { for (int i = 0; i < favorited.size(); i++) {
String name = favorited[i]; String name = favorited[i];
bool cres = name.begins_with("res://"); if (access_resources != name.begins_with("res://")) {
if (cres != res || !name.ends_with("/")) { continue;
}
if (!name.ends_with("/")) {
continue; continue;
} }
@@ -1551,7 +1554,7 @@ void EditorFileDialog::_update_favorites() {
} }
// Compute favorite display text. // Compute favorite display text.
if (res && name == "res://") { if (access_resources && name == "res://") {
if (name == current) { if (name == current) {
current_favorite = favorited_paths.size(); current_favorite = favorited_paths.size();
} }
@@ -1562,7 +1565,7 @@ void EditorFileDialog::_update_favorites() {
if (name == current || name == current + "/") { if (name == current || name == current + "/") {
current_favorite = favorited_paths.size(); current_favorite = favorited_paths.size();
} }
name = name.substr(0, name.length() - 1); name = name.trim_suffix("/");
name = name.get_file(); name = name.get_file();
favorited_paths.append(favorited[i]); favorited_paths.append(favorited[i]);
favorited_names.append(name); favorited_names.append(name);
@@ -1589,7 +1592,7 @@ void EditorFileDialog::_update_favorites() {
} }
void EditorFileDialog::_favorite_pressed() { void EditorFileDialog::_favorite_pressed() {
bool res = (access == ACCESS_RESOURCES); bool access_resources = (access == ACCESS_RESOURCES);
String cd = get_current_dir(); String cd = get_current_dir();
if (!cd.ends_with("/")) { if (!cd.ends_with("/")) {
@@ -1599,13 +1602,12 @@ void EditorFileDialog::_favorite_pressed() {
Vector<String> favorited = EditorSettings::get_singleton()->get_favorites(); Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
bool found = false; bool found = false;
for (int i = 0; i < favorited.size(); i++) { for (const String &name : favorited) {
bool cres = favorited[i].begins_with("res://"); if (access_resources != name.begins_with("res://")) {
if (cres != res) {
continue; continue;
} }
if (favorited[i] == cd) { if (name == cd) {
found = true; found = true;
break; break;
} }
@@ -1625,31 +1627,30 @@ void EditorFileDialog::_favorite_pressed() {
void EditorFileDialog::_update_recent() { void EditorFileDialog::_update_recent() {
recent->clear(); recent->clear();
bool res = (access == ACCESS_RESOURCES); bool access_resources = (access == ACCESS_RESOURCES);
Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs(); Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
Vector<String> recentd_paths; Vector<String> recentd_paths;
Vector<String> recentd_names; Vector<String> recentd_names;
bool modified = false;
for (int i = 0; i < recentd.size(); i++) { for (int i = 0; i < recentd.size(); i++) {
bool cres = recentd[i].begins_with("res://"); String name = recentd[i];
if (cres != res) { if (access_resources != name.begins_with("res://")) {
continue; continue;
} }
if (!dir_access->dir_exists(recentd[i])) { if (!dir_access->dir_exists(name)) {
// Remove invalid directory from the list of Recent directories. // Remove invalid directory from the list of Recent directories.
recentd.remove_at(i--); recentd.remove_at(i--);
modified = true;
continue; continue;
} }
// Compute recent directory display text. // Compute recent directory display text.
String name = recentd[i]; if (access_resources && name == "res://") {
if (res && name == "res://") {
name = "/"; name = "/";
} else { } else {
if (name.ends_with("/")) { name = name.trim_suffix("/");
name = name.substr(0, name.length() - 1);
}
name = name.get_file(); name = name.get_file();
} }
recentd_paths.append(recentd[i]); recentd_paths.append(recentd[i]);
@@ -1663,7 +1664,10 @@ void EditorFileDialog::_update_recent() {
recent->set_item_metadata(-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, get_dir_icon_color(recentd_paths[i]));
} }
if (modified) {
EditorSettings::get_singleton()->set_recent_dirs(recentd); EditorSettings::get_singleton()->set_recent_dirs(recentd);
}
} }
void EditorFileDialog::_recent_selected(int p_idx) { void EditorFileDialog::_recent_selected(int p_idx) {