Skip to content

Commit

Permalink
Merge pull request godotengine#99857 from 20kdc/backport-scene-saved
Browse files Browse the repository at this point in the history
[3.x] Backport  "[Editor] Add `EditorPlugin::scene_saved` signal"
  • Loading branch information
lawnjelly authored Dec 2, 2024
2 parents 36a0185 + 45d1948 commit 99741e6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion doc/classes/EditorPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@
<signal name="resource_saved">
<argument index="0" name="resource" type="Resource" />
<description>
Emitted when the given [code]resource[/code] was saved on disc. See also [signal scene_saved], which is used for edited scenes instead of this signal. The [PackedScene] does not count as a saved resource.
</description>
</signal>
<signal name="scene_changed">
Expand All @@ -529,7 +530,13 @@
<signal name="scene_closed">
<argument index="0" name="filepath" type="String" />
<description>
Emitted when user closes a scene. The argument is file path to a closed scene.
Emitted when user closes a scene. The argument is a file path to the closed scene.
</description>
</signal>
<signal name="scene_saved">
<argument index="0" name="filepath" type="String" />
<description>
Emitted when a scene was saved on disc. The argument is a file path to the saved scene. See also [signal resource_saved], used for other resources.
</description>
</signal>
</signals>
Expand Down
6 changes: 6 additions & 0 deletions editor/editor_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ void EditorData::notify_resource_saved(const Ref<Resource> &p_resource) {
}
}

void EditorData::notify_scene_saved(const String &p_path) {
for (int i = 0; i < editor_plugins.size(); i++) {
editor_plugins[i]->notify_scene_saved(p_path);
}
}

void EditorData::clear_editor_states() {
for (int i = 0; i < editor_plugins.size(); i++) {
editor_plugins[i]->clear();
Expand Down
1 change: 1 addition & 0 deletions editor/editor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class EditorData {
Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history);
void notify_edited_scene_changed();
void notify_resource_saved(const Ref<Resource> &p_resource);
void notify_scene_saved(const String &p_path);

bool script_class_is_parent(const String &p_class, const String &p_inherits);
StringName script_class_get_base(const String &p_class) const;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ void EditorNode::_save_scene(String p_file, int idx) {

// This needs to be emitted before saving external resources.
emit_signal("scene_saved", p_file);
editor_data.notify_scene_saved(p_file);

_save_external_resources();
editor_data.save_editor_external_data();
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) {
emit_signal("resource_saved", p_resource);
}

void EditorPlugin::notify_scene_saved(const String &p_scene_filepath) {
emit_signal("scene_saved", p_scene_filepath);
}

bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
if (get_script_instance() && get_script_instance()->has_method("forward_canvas_gui_input")) {
return get_script_instance()->call("forward_canvas_gui_input", p_event);
Expand Down Expand Up @@ -884,6 +888,7 @@ void EditorPlugin::_bind_methods() {
ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath")));
ADD_SIGNAL(MethodInfo("main_screen_changed", PropertyInfo(Variant::STRING, "screen_name")));
ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
ADD_SIGNAL(MethodInfo("scene_saved", PropertyInfo(Variant::STRING, "filepath")));

BIND_ENUM_CONSTANT(CONTAINER_TOOLBAR);
BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_MENU);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class EditorPlugin : public Node {
void notify_scene_changed(const Node *scn_root);
void notify_scene_closed(const String &scene_filepath);
void notify_resource_saved(const Ref<Resource> &p_resource);
void notify_scene_saved(const String &p_scene_filepath);

virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
virtual void forward_canvas_draw_over_viewport(Control *p_overlay);
Expand Down

0 comments on commit 99741e6

Please sign in to comment.