From ff561c13794d1fd4d8af2d18c41dd625f9a2b4cd Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Wed, 8 May 2024 02:03:44 -0400 Subject: [PATCH] Expose `set_edited` and `is_edited` on EditorInterface --- doc/classes/EditorInterface.xml | 17 +++++++++++++++++ editor/editor_interface.cpp | 13 +++++++++++++ editor/editor_interface.h | 3 +++ 3 files changed, 33 insertions(+) diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index a04764a8887..b805aa064f4 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -266,6 +266,13 @@ Returns [code]true[/code] if the 3D editor currently has snapping mode enabled, and [code]false[/code] otherwise. + + + + + Returns [code]true[/code] if the object has been marked as edited through [method set_object_edited]. + + @@ -490,6 +497,16 @@ Sets the editor's current main screen to the one specified in [param name]. [param name] must match the title of the tab in question exactly (e.g. [code]2D[/code], [code]3D[/code], [code skip-lint]Script[/code], [code]Game[/code], or [code]AssetLib[/code] for default tabs). + + + + + + If [param edited] is [code]true[/code], the object is marked as edited. + [b]Note:[/b] This is primarily used by the editor for [Resource] based objects to track their modified state. For example, any changes to an open scene, a resource in the inspector, or an edited script will cause this method to be called with [code]true[/code]. Saving the scene, script, or resource resets the edited state by calling this method with [code]false[/code]. + [b]Note:[/b] Each call to this method increments the object's edited version. This is used to track changes in the editor and to trigger when thumbnails should be regenerated for resources. + + diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index 79cd296aa82..9c6729d9f11 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -705,6 +705,16 @@ void EditorInterface::reload_scene_from_path(const String &scene_path) { EditorNode::get_singleton()->reload_scene(scene_path); } +void EditorInterface::set_object_edited(Object *p_object, bool p_edited) { + ERR_FAIL_NULL_MSG(p_object, "Cannot change edited status on a null object."); + p_object->set_edited(p_edited); +} + +bool EditorInterface::is_object_edited(Object *p_object) const { + ERR_FAIL_NULL_V_MSG(p_object, false, "Cannot check edit status on a null object."); + return p_object->is_edited(); +} + Node *EditorInterface::get_edited_scene_root() const { return EditorNode::get_singleton()->get_edited_scene(); } @@ -895,6 +905,9 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath", "set_inherited"), &EditorInterface::open_scene_from_path, DEFVAL(false)); ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path); + ClassDB::bind_method(D_METHOD("set_object_edited", "object", "edited"), &EditorInterface::set_object_edited); + ClassDB::bind_method(D_METHOD("is_object_edited", "object"), &EditorInterface::is_object_edited); + ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorInterface::get_open_scenes); ClassDB::bind_method(D_METHOD("get_open_scene_roots"), &EditorInterface::get_open_scene_roots); ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root); diff --git a/editor/editor_interface.h b/editor/editor_interface.h index 76936855c21..1cd86511e63 100644 --- a/editor/editor_interface.h +++ b/editor/editor_interface.h @@ -175,6 +175,9 @@ public: void open_scene_from_path(const String &scene_path, bool p_set_inherited = false); void reload_scene_from_path(const String &scene_path); + void set_object_edited(Object *p_object, bool p_edited); + bool is_object_edited(Object *p_object) const; + PackedStringArray get_open_scenes() const; TypedArray get_open_scene_roots() const; Node *get_edited_scene_root() const;