Skip to content

Commit dc590a5

Browse files
committed
Merge pull request #112201 from timothyqiu/update-main-scene
Fix FileSystem item color not updated after changing main scene
2 parents c287d61 + 64c9436 commit dc590a5

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

editor/docks/filesystem_dock.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ void FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
287287

288288
// Create all items for the files in the subdirectory.
289289
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
290-
const String main_scene = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
291-
292290
// Build the list of the files to display.
293291
List<FileInfo> file_list;
294292
for (int i = 0; i < p_dir->get_file_count(); i++) {
@@ -337,7 +335,7 @@ void FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
337335
file_item->select(0);
338336
file_item->set_as_cursor(0);
339337
}
340-
if (main_scene == file_metadata) {
338+
if (main_scene_path == file_metadata) {
341339
file_item->set_custom_color(0, get_theme_color(SNAME("accent_color"), EditorStringName(Editor)));
342340
}
343341
EditorResourcePreview::get_singleton()->queue_resource_preview(file_metadata, callable_mp(this, &FileSystemDock::_tree_thumbnail_done).bind(tree_update_id, file_item->get_instance_id()));
@@ -1132,7 +1130,6 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
11321130
sort_file_info_list(file_list, file_sort);
11331131

11341132
// Fills the ItemList control node from the FileInfos.
1135-
const String main_scene = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
11361133
for (FileInfo &E : file_list) {
11371134
FileInfo *finfo = &(E);
11381135
String fname = finfo->name;
@@ -1166,7 +1163,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
11661163
files->set_item_metadata(item_index, fpath);
11671164
}
11681165

1169-
if (fpath == main_scene) {
1166+
if (fpath == main_scene_path) {
11701167
files->set_item_custom_fg_color(item_index, get_theme_color(SNAME("accent_color"), EditorStringName(Editor)));
11711168
}
11721169

@@ -2397,7 +2394,8 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
23972394
case FILE_MENU_MAIN_SCENE: {
23982395
// Set as main scene with selected scene file.
23992396
if (p_selected.size() == 1) {
2400-
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(p_selected[0]));
2397+
main_scene_path = ResourceUID::path_to_uid(p_selected[0]);
2398+
ProjectSettings::get_singleton()->set("application/run/main_scene", main_scene_path);
24012399
ProjectSettings::get_singleton()->save();
24022400
_update_tree(get_uncollapsed_paths());
24032401
_update_file_list(true);
@@ -3330,7 +3328,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
33303328
if (filenames.size() == 1) {
33313329
p_popup->add_icon_item(get_editor_theme_icon(SNAME("Load")), TTRC("Open Scene"), FILE_MENU_OPEN);
33323330
p_popup->add_icon_item(get_editor_theme_icon(SNAME("CreateNewSceneFrom")), TTRC("New Inherited Scene"), FILE_MENU_INHERIT);
3333-
if (ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene")) != filenames[0]) {
3331+
if (main_scene_path != filenames[0]) {
33343332
p_popup->add_icon_item(get_editor_theme_icon(SNAME("PlayScene")), TTRC("Set as Main Scene"), FILE_MENU_MAIN_SCENE);
33353333
}
33363334
} else {
@@ -4013,6 +4011,12 @@ void FileSystemDock::_feature_profile_changed() {
40134011

40144012
void FileSystemDock::_project_settings_changed() {
40154013
assigned_folder_colors = ProjectSettings::get_singleton()->get_setting("file_customization/folder_colors");
4014+
4015+
const String &current_main_scene_path = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
4016+
if (main_scene_path != current_main_scene_path) {
4017+
main_scene_path = current_main_scene_path;
4018+
update_all();
4019+
}
40164020
}
40174021

40184022
void FileSystemDock::set_file_sort(FileSortOption p_file_sort) {
@@ -4479,6 +4483,8 @@ FileSystemDock::FileSystemDock() {
44794483
file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS;
44804484

44814485
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &FileSystemDock::_project_settings_changed));
4486+
main_scene_path = ResourceUID::ensure_path(GLOBAL_GET("application/run/main_scene"));
4487+
44824488
add_resource_tooltip_plugin(memnew(EditorTextureTooltipPlugin));
44834489
add_resource_tooltip_plugin(memnew(EditorAudioStreamTooltipPlugin));
44844490
}

editor/docks/filesystem_dock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class FileSystemDock : public EditorDock {
245245

246246
String current_path = "res://";
247247
String select_after_scan;
248+
String main_scene_path;
248249

249250
bool updating_tree = false;
250251
int tree_update_id;

0 commit comments

Comments
 (0)