From b4db9dc6884bffb9c1dc40c0643d2d1446c03f41 Mon Sep 17 00:00:00 2001 From: Pablo Andres Fuente Date: Mon, 23 Sep 2024 01:02:08 -0300 Subject: [PATCH] Update Inspector when rename a file via File System Dock Fixes #56803 Connecting `FileSystemDock` `files_moved` signal to `InspectorDock` and then checking if we need to update or not the object stored on `EditorSelectionHistory`. --- editor/editor_node.cpp | 3 ++- editor/inspector_dock.cpp | 17 +++++++++++++++++ editor/inspector_dock.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6f5d53ac541..bb3d526d80b 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -7808,11 +7808,12 @@ EditorNode::EditorNode() { // Instantiate and place editor docks. memnew(SceneTreeDock(scene_root, editor_selection, editor_data)); + memnew(FileSystemDock); memnew(InspectorDock(editor_data)); memnew(ImportDock); memnew(NodeDock); - FileSystemDock *filesystem_dock = memnew(FileSystemDock); + FileSystemDock *filesystem_dock = FileSystemDock::get_singleton(); filesystem_dock->connect("inherit", callable_mp(this, &EditorNode::_inherit_request)); filesystem_dock->connect("instantiate", callable_mp(this, &EditorNode::_instantiate_request)); filesystem_dock->connect("display_mode_changed", callable_mp(this, &EditorNode::_save_editor_layout)); diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index e8ee16e7524..716ca4fea36 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -399,6 +399,21 @@ void InspectorDock::_resource_selected(const Ref &p_res, const String EditorNode::get_singleton()->push_item(r.operator->(), p_property); } +void InspectorDock::_files_moved(const String &p_old_file, const String &p_new_file) { + // Because only the file name is shown, we care about changes on the file name. + if (p_old_file.get_file() == p_new_file.get_file()) { + return; + } + + ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current(); + Ref res(current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr); + // We only care about updating the path if the current object is the one being renamed. + if (res.is_valid() && p_old_file == res->get_path()) { + res->set_path(p_new_file); + object_selector->update_path(); + } +} + void InspectorDock::_edit_forward() { if (EditorNode::get_singleton()->get_editor_selection_history()->next()) { EditorNode::get_singleton()->edit_current(); @@ -823,6 +838,8 @@ InspectorDock::InspectorDock(EditorData &p_editor_data) { inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected)); + FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &InspectorDock::_files_moved)); + set_process_shortcut_input(true); } diff --git a/editor/inspector_dock.h b/editor/inspector_dock.h index a4efb38338c..5db47cde8b5 100644 --- a/editor/inspector_dock.h +++ b/editor/inspector_dock.h @@ -124,6 +124,7 @@ class InspectorDock : public VBoxContainer { void _info_pressed(); void _resource_created(); void _resource_selected(const Ref &p_res, const String &p_property); + void _files_moved(const String &p_old_file, const String &p_new_file); void _edit_forward(); void _edit_back(); void _menu_collapseall();