Skip to content

Commit b67eb68

Browse files
committed
Misc code cleanup in EditorFileDialog
1 parent 33c30b9 commit b67eb68

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

editor/gui/editor_file_dialog.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ void EditorFileDialog::_favorite_move_down() {
15221522
}
15231523

15241524
void EditorFileDialog::_update_favorites() {
1525-
bool res = (access == ACCESS_RESOURCES);
1525+
bool access_resources = (access == ACCESS_RESOURCES);
15261526

15271527
String current = get_current_dir();
15281528
favorites->clear();
@@ -1538,8 +1538,11 @@ void EditorFileDialog::_update_favorites() {
15381538
for (int i = 0; i < favorited.size(); i++) {
15391539
String name = favorited[i];
15401540

1541-
bool cres = name.begins_with("res://");
1542-
if (cres != res || !name.ends_with("/")) {
1541+
if (access_resources != name.begins_with("res://")) {
1542+
continue;
1543+
}
1544+
1545+
if (!name.ends_with("/")) {
15431546
continue;
15441547
}
15451548

@@ -1551,7 +1554,7 @@ void EditorFileDialog::_update_favorites() {
15511554
}
15521555

15531556
// Compute favorite display text.
1554-
if (res && name == "res://") {
1557+
if (access_resources && name == "res://") {
15551558
if (name == current) {
15561559
current_favorite = favorited_paths.size();
15571560
}
@@ -1562,7 +1565,7 @@ void EditorFileDialog::_update_favorites() {
15621565
if (name == current || name == current + "/") {
15631566
current_favorite = favorited_paths.size();
15641567
}
1565-
name = name.substr(0, name.length() - 1);
1568+
name = name.trim_suffix("/");
15661569
name = name.get_file();
15671570
favorited_paths.append(favorited[i]);
15681571
favorited_names.append(name);
@@ -1589,7 +1592,7 @@ void EditorFileDialog::_update_favorites() {
15891592
}
15901593

15911594
void EditorFileDialog::_favorite_pressed() {
1592-
bool res = (access == ACCESS_RESOURCES);
1595+
bool access_resources = (access == ACCESS_RESOURCES);
15931596

15941597
String cd = get_current_dir();
15951598
if (!cd.ends_with("/")) {
@@ -1599,13 +1602,12 @@ void EditorFileDialog::_favorite_pressed() {
15991602
Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
16001603

16011604
bool found = false;
1602-
for (int i = 0; i < favorited.size(); i++) {
1603-
bool cres = favorited[i].begins_with("res://");
1604-
if (cres != res) {
1605+
for (const String &name : favorited) {
1606+
if (access_resources != name.begins_with("res://")) {
16051607
continue;
16061608
}
16071609

1608-
if (favorited[i] == cd) {
1610+
if (name == cd) {
16091611
found = true;
16101612
break;
16111613
}
@@ -1625,31 +1627,30 @@ void EditorFileDialog::_favorite_pressed() {
16251627
void EditorFileDialog::_update_recent() {
16261628
recent->clear();
16271629

1628-
bool res = (access == ACCESS_RESOURCES);
1630+
bool access_resources = (access == ACCESS_RESOURCES);
16291631
Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
16301632
Vector<String> recentd_paths;
16311633
Vector<String> recentd_names;
1634+
bool modified = false;
16321635

16331636
for (int i = 0; i < recentd.size(); i++) {
1634-
bool cres = recentd[i].begins_with("res://");
1635-
if (cres != res) {
1637+
String name = recentd[i];
1638+
if (access_resources != name.begins_with("res://")) {
16361639
continue;
16371640
}
16381641

1639-
if (!dir_access->dir_exists(recentd[i])) {
1642+
if (!dir_access->dir_exists(name)) {
16401643
// Remove invalid directory from the list of Recent directories.
16411644
recentd.remove_at(i--);
1645+
modified = true;
16421646
continue;
16431647
}
16441648

16451649
// Compute recent directory display text.
1646-
String name = recentd[i];
1647-
if (res && name == "res://") {
1650+
if (access_resources && name == "res://") {
16481651
name = "/";
16491652
} else {
1650-
if (name.ends_with("/")) {
1651-
name = name.substr(0, name.length() - 1);
1652-
}
1653+
name = name.trim_suffix("/");
16531654
name = name.get_file();
16541655
}
16551656
recentd_paths.append(recentd[i]);
@@ -1663,7 +1664,10 @@ void EditorFileDialog::_update_recent() {
16631664
recent->set_item_metadata(-1, recentd_paths[i]);
16641665
recent->set_item_icon_modulate(-1, get_dir_icon_color(recentd_paths[i]));
16651666
}
1666-
EditorSettings::get_singleton()->set_recent_dirs(recentd);
1667+
1668+
if (modified) {
1669+
EditorSettings::get_singleton()->set_recent_dirs(recentd);
1670+
}
16671671
}
16681672

16691673
void EditorFileDialog::_recent_selected(int p_idx) {

0 commit comments

Comments
 (0)