diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2020-03-07 14:29:44 +0000 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2020-07-11 15:40:00 +0100 |
commit | 156daddaaf16e36eb932452d1e30f4f77d29aae6 (patch) | |
tree | 942c5f0fe5bf8cbab99ca5534ecef4f76ea8d6b9 /modules | |
parent | 2f1080be9b032b1cf5086201e45057baa6b1a179 (diff) |
Expose Syntax highlighter for editor plugins
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/editor/gdscript_highlighter.h | 12 | ||||
-rw-r--r-- | modules/gdscript/register_types.cpp | 7 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 2 |
4 files changed, 19 insertions, 8 deletions
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 4be83877be..8ab3dc1d56 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -387,6 +387,8 @@ void GDScriptSyntaxHighlighter::_update_cache() { type_color = EDITOR_GET("text_edit/highlighting/base_type_color"); } -SyntaxHighlighter *GDScriptSyntaxHighlighter::create() { - return memnew(GDScriptSyntaxHighlighter); +Ref<SyntaxHighlighter> GDScriptSyntaxHighlighter::_create() const { + Ref<GDScriptSyntaxHighlighter> syntax_highlighter; + syntax_highlighter.instance(); + return syntax_highlighter; } diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index 47ea5a3d62..c1de22167a 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -34,6 +34,8 @@ #include "scene/gui/text_edit.h" class GDScriptSyntaxHighlighter : public SyntaxHighlighter { + GDCLASS(GDScriptSyntaxHighlighter, SyntaxHighlighter) + private: enum Type { NONE, @@ -60,13 +62,13 @@ private: Color type_color; public: - static SyntaxHighlighter *create(); + virtual void _update_cache() override; + virtual Dictionary _get_line_syntax_highlighting(int p_line) override; - virtual void _update_cache(); - virtual Dictionary _get_line_syntax_highlighting(int p_line); + virtual String _get_name() const override; + virtual Array _get_supported_languages() const override; - virtual String _get_name() const; - virtual Array _get_supported_languages() const; + virtual Ref<SyntaxHighlighter> _create() const override; }; #endif // GDSCRIPT_HIGHLIGHTER_H diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 884946efc1..6c4e529922 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -142,6 +142,12 @@ static void _editor_init() { gd_export.instance(); EditorExport::get_singleton()->add_export_plugin(gd_export); +#ifdef TOOLS_ENABLED + Ref<GDScriptSyntaxHighlighter> gdscript_syntax_highlighter; + gdscript_syntax_highlighter.instance(); + ScriptEditor::get_singleton()->register_syntax_highlighter(gdscript_syntax_highlighter); +#endif + #ifndef GDSCRIPT_NO_LSP register_lsp_types(); GDScriptLanguageServer *lsp_plugin = memnew(GDScriptLanguageServer); @@ -166,7 +172,6 @@ void register_gdscript_types() { ResourceSaver::add_resource_format_saver(resource_saver_gd); #ifdef TOOLS_ENABLED - ScriptEditor::register_create_syntax_highlighter_function(GDScriptSyntaxHighlighter::create); EditorNode::add_init_callback(_editor_init); gdscript_translation_parser_plugin.instance(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 7a803d8930..c8ecf0c283 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -4686,6 +4686,8 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members); ClassDB::bind_method("_generic_search", &VisualScriptEditor::_generic_search); + + ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &VisualScriptEditor::add_syntax_highlighter); } VisualScriptEditor::VisualScriptEditor() { |