From 156daddaaf16e36eb932452d1e30f4f77d29aae6 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sat, 7 Mar 2020 14:29:44 +0000 Subject: Expose Syntax highlighter for editor plugins --- editor/editor_node.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 39 +++++++++++++++++++----- editor/plugins/script_editor_plugin.h | 9 +++--- editor/plugins/script_text_editor.cpp | 2 ++ editor/plugins/text_editor.cpp | 1 + modules/gdscript/editor/gdscript_highlighter.cpp | 6 ++-- modules/gdscript/editor/gdscript_highlighter.h | 12 +++++--- modules/gdscript/register_types.cpp | 7 ++++- modules/visual_script/visual_script_editor.cpp | 2 ++ scene/resources/syntax_highlighter.cpp | 9 ++++++ scene/resources/syntax_highlighter.h | 2 ++ 11 files changed, 71 insertions(+), 19 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index f768a2cacf..2f669d9006 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3602,6 +3602,7 @@ void EditorNode::register_editor_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_virtual_class(); + ClassDB::register_virtual_class(); ClassDB::register_virtual_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 3f17f1166f..237aefb1b9 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -63,6 +63,8 @@ void ScriptEditorBase::_bind_methods() { // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text"))); + + BIND_VMETHOD(MethodInfo("add_syntax_highlighter", PropertyInfo(Variant::OBJECT, "highlighter"))); } static bool _is_built_in_script(Script *p_script) { @@ -2019,8 +2021,11 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra if (p_resource->get_class_name() != StringName("VisualScript")) { bool highlighter_set = false; - for (int i = 0; i < syntax_highlighters_func_count; i++) { - SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i](); + for (int i = 0; i < syntax_highlighters.size(); i++) { + Ref highlighter = syntax_highlighters[i]->_create(); + if (highlighter.is_null()) { + continue; + } se->add_syntax_highlighter(highlighter); if (script != nullptr && !highlighter_set) { @@ -2768,6 +2773,18 @@ Vector> ScriptEditor::get_open_scripts() const { return out_scripts; } +Array ScriptEditor::_get_open_script_editors() const { + Array script_editors; + for (int i = 0; i < tab_container->get_child_count(); i++) { + ScriptEditorBase *se = Object::cast_to(tab_container->get_child(i)); + if (!se) { + continue; + } + script_editors.push_back(se); + } + return script_editors; +} + void ScriptEditor::set_scene_root_script(Ref