From a248c318de3f221d174becd39050ce0728d9caf0 Mon Sep 17 00:00:00 2001 From: Jeronimo Schreyer Date: Fri, 9 Jun 2023 10:07:38 -0300 Subject: [PATCH] Expose the TextEdit control of the script editor Refactor ScriptEditor and ScriptTextEditor with added method to retrieve the script editor's TextEdit control. Update doc/classes/ScriptEditor.xml script_editor_plugin.cpp script_editor_plugin.h script_text_editor.cpp script_text_editor.h --- doc/classes/ScriptEditor.xml | 6 ++++++ editor/plugins/script_editor_plugin.cpp | 5 +++++ editor/plugins/script_editor_plugin.h | 1 + editor/plugins/script_text_editor.cpp | 4 ++++ editor/plugins/script_text_editor.h | 1 + 5 files changed, 17 insertions(+) diff --git a/doc/classes/ScriptEditor.xml b/doc/classes/ScriptEditor.xml index 0d182353c65..dff570dc509 100644 --- a/doc/classes/ScriptEditor.xml +++ b/doc/classes/ScriptEditor.xml @@ -25,6 +25,12 @@ + + + + Returns the underlying [Control] used for editing scripts. For text scripts, this is a [TextEdit]. + + diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 1e2e8260915..66a1520a805 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -343,6 +343,10 @@ ScriptEditorBase *ScriptEditor::_get_current_editor() const { return Object::cast_to(tab_container->get_child(selected)); } +Control *ScriptEditor::_get_base_editor() const { + return Object::cast_to(_get_current_editor())->get_code_editor_text_edit(); +} + void ScriptEditor::_update_history_arrows() { script_back->set_disabled(history_pos <= 0); script_forward->set_disabled(history_pos >= history.size() - 1); @@ -3235,6 +3239,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("get_open_scripts"), &ScriptEditor::_get_open_scripts); ClassDB::bind_method(D_METHOD("open_script_create_dialog", "base_name", "base_path"), &ScriptEditor::open_script_create_dialog); ClassDB::bind_method(D_METHOD("reload_scripts"), &ScriptEditor::reload_scripts); + ClassDB::bind_method(D_METHOD("get_base_editor"), &ScriptEditor::_get_base_editor); ADD_SIGNAL(MethodInfo("editor_script_changed", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 8d445095487..65d78f0917a 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -338,6 +338,7 @@ class ScriptEditor : public PanelContainer { void _script_created(Ref