diff --git a/doc/classes/ScriptEditor.xml b/doc/classes/ScriptEditor.xml index 678c1270c5..4f26f1cf50 100644 --- a/doc/classes/ScriptEditor.xml +++ b/doc/classes/ScriptEditor.xml @@ -18,6 +18,14 @@ [b]Note:[/b] This should be called whenever the script is changed to keep the open documentation state up to date. + + + + + Closes the file at the given [param path], discarding any unsaved changes. + Returns [constant OK] on success or [constant ERR_FILE_NOT_FOUND] if the file is not found. + + diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp index 5d053dec2f..2ed0ddc20f 100644 --- a/editor/script/script_editor_plugin.cpp +++ b/editor/script/script_editor_plugin.cpp @@ -2624,6 +2624,20 @@ Ref ScriptEditor::open_file(const String &p_file) { return Ref(); } +Error ScriptEditor::close_file(const String &p_file) { + for (int i = 0; i < tab_container->get_tab_count(); i++) { + ScriptEditorBase *seb = Object::cast_to(tab_container->get_tab_control(i)); + if (seb && seb->get_edited_resource()->get_path() == p_file) { + if (seb->is_unsaved()) { + seb->get_edited_resource()->reload_from_file(); + } + _close_tab(i, false, _get_current_editor() == seb); + return OK; + } + } + return ERR_FILE_NOT_FOUND; +} + void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args) { ERR_FAIL_NULL(p_obj); Ref