@@ -1580,7 +1580,7 @@ void EditorFileDialog::_favorite_move_down() {
15801580}
15811581
15821582void EditorFileDialog::_update_favorites () {
1583- bool res = (access == ACCESS_RESOURCES);
1583+ bool access_resources = (access == ACCESS_RESOURCES);
15841584
15851585 String current = get_current_dir ();
15861586 favorites->clear ();
@@ -1596,8 +1596,11 @@ void EditorFileDialog::_update_favorites() {
15961596 for (int i = 0 ; i < favorited.size (); i++) {
15971597 String name = favorited[i];
15981598
1599- bool cres = name.begins_with (" res://" );
1600- if (cres != res || !name.ends_with (" /" )) {
1599+ if (access_resources != name.begins_with (" res://" )) {
1600+ continue ;
1601+ }
1602+
1603+ if (!name.ends_with (" /" )) {
16011604 continue ;
16021605 }
16031606
@@ -1609,7 +1612,7 @@ void EditorFileDialog::_update_favorites() {
16091612 }
16101613
16111614 // Compute favorite display text.
1612- if (res && name == " res://" ) {
1615+ if (access_resources && name == " res://" ) {
16131616 if (name == current) {
16141617 current_favorite = favorited_paths.size ();
16151618 }
@@ -1620,7 +1623,7 @@ void EditorFileDialog::_update_favorites() {
16201623 if (name == current || name == current + " /" ) {
16211624 current_favorite = favorited_paths.size ();
16221625 }
1623- name = name.substr ( 0 , name. length () - 1 );
1626+ name = name.trim_suffix ( " / " );
16241627 name = name.get_file ();
16251628 favorited_paths.append (favorited[i]);
16261629 favorited_names.append (name);
@@ -1647,7 +1650,7 @@ void EditorFileDialog::_update_favorites() {
16471650}
16481651
16491652void EditorFileDialog::_favorite_pressed () {
1650- bool res = (access == ACCESS_RESOURCES);
1653+ bool access_resources = (access == ACCESS_RESOURCES);
16511654
16521655 String cd = get_current_dir ();
16531656 if (!cd.ends_with (" /" )) {
@@ -1657,13 +1660,12 @@ void EditorFileDialog::_favorite_pressed() {
16571660 Vector<String> favorited = EditorSettings::get_singleton ()->get_favorites ();
16581661
16591662 bool found = false ;
1660- for (int i = 0 ; i < favorited.size (); i++) {
1661- bool cres = favorited[i].begins_with (" res://" );
1662- if (cres != res) {
1663+ for (const String &name : favorited) {
1664+ if (access_resources != name.begins_with (" res://" )) {
16631665 continue ;
16641666 }
16651667
1666- if (favorited[i] == cd) {
1668+ if (name == cd) {
16671669 found = true ;
16681670 break ;
16691671 }
@@ -1683,31 +1685,30 @@ void EditorFileDialog::_favorite_pressed() {
16831685void EditorFileDialog::_update_recent () {
16841686 recent->clear ();
16851687
1686- bool res = (access == ACCESS_RESOURCES);
1688+ bool access_resources = (access == ACCESS_RESOURCES);
16871689 Vector<String> recentd = EditorSettings::get_singleton ()->get_recent_dirs ();
16881690 Vector<String> recentd_paths;
16891691 Vector<String> recentd_names;
1692+ bool modified = false ;
16901693
16911694 for (int i = 0 ; i < recentd.size (); i++) {
1692- bool cres = recentd[i]. begins_with ( " res:// " ) ;
1693- if (cres != res) {
1695+ String name = recentd[i];
1696+ if (access_resources != name. begins_with ( " res:// " ) ) {
16941697 continue ;
16951698 }
16961699
1697- if (!dir_access->dir_exists (recentd[i] )) {
1700+ if (!dir_access->dir_exists (name )) {
16981701 // Remove invalid directory from the list of Recent directories.
16991702 recentd.remove_at (i--);
1703+ modified = true ;
17001704 continue ;
17011705 }
17021706
17031707 // Compute recent directory display text.
1704- String name = recentd[i];
1705- if (res && name == " res://" ) {
1708+ if (access_resources && name == " res://" ) {
17061709 name = " /" ;
17071710 } else {
1708- if (name.ends_with (" /" )) {
1709- name = name.substr (0 , name.length () - 1 );
1710- }
1711+ name = name.trim_suffix (" /" );
17111712 name = name.get_file ();
17121713 }
17131714 recentd_paths.append (recentd[i]);
@@ -1721,7 +1722,10 @@ void EditorFileDialog::_update_recent() {
17211722 recent->set_item_metadata (-1 , recentd_paths[i]);
17221723 recent->set_item_icon_modulate (-1 , get_dir_icon_color (recentd_paths[i]));
17231724 }
1724- EditorSettings::get_singleton ()->set_recent_dirs (recentd);
1725+
1726+ if (modified) {
1727+ EditorSettings::get_singleton ()->set_recent_dirs (recentd);
1728+ }
17251729}
17261730
17271731void EditorFileDialog::_recent_selected (int p_idx) {
0 commit comments