From 2f1080be9b032b1cf5086201e45057baa6b1a179 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sat, 7 Mar 2020 11:17:18 +0000 Subject: Convert syntax highlighters into a resource --- modules/gdscript/editor/gdscript_highlighter.cpp | 65 ++++++++++++------------ modules/gdscript/editor/gdscript_highlighter.h | 6 +-- modules/visual_script/visual_script_editor.cpp | 4 +- modules/visual_script/visual_script_editor.h | 4 +- 4 files changed, 39 insertions(+), 40 deletions(-) (limited to 'modules') diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index d0f27b632b..4be83877be 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -31,7 +31,6 @@ #include "gdscript_highlighter.h" #include "../gdscript_tokenizer.h" #include "editor/editor_settings.h" -#include "scene/gui/text_edit.h" inline bool _is_symbol(CharType c) { return is_symbol(c); @@ -57,8 +56,8 @@ static bool _is_bin_symbol(CharType c) { return (c == '0' || c == '1'); } -Map GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) { - Map color_map; +Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) { + Dictionary color_map; Type next_type = NONE; Type current_type = NONE; @@ -82,14 +81,14 @@ Map GDScriptSyntaxHighlighter::_get_line_syntax_ Color keyword_color; Color color; - int in_region = text_editor->_is_line_in_region(p_line); + int in_region = text_edit->_is_line_in_region(p_line); int deregion = 0; - const Map cri_map = text_editor->_get_line_color_region_info(p_line); - const String &str = text_editor->get_line(p_line); + const Map cri_map = text_edit->_get_line_color_region_info(p_line); + const String &str = text_edit->get_line(p_line); Color prev_color; for (int j = 0; j < str.length(); j++) { - TextEdit::HighlighterInfo highlighter_info; + Dictionary highlighter_info; if (deregion > 0) { deregion--; @@ -101,7 +100,7 @@ Map GDScriptSyntaxHighlighter::_get_line_syntax_ if (deregion != 0) { if (color != prev_color) { prev_color = color; - highlighter_info.color = color; + highlighter_info["color"] = color; color_map[j] = highlighter_info; } continue; @@ -163,7 +162,7 @@ Map GDScriptSyntaxHighlighter::_get_line_syntax_ in_region = cri.region; } } else { - TextEdit::ColorRegion cr = text_editor->_get_color_region(cri.region); + TextEdit::ColorRegion cr = text_edit->_get_color_region(cri.region); if (in_region == cri.region && !cr.line_only) { //ignore otherwise if (cri.end || cr.eq) { deregion = cr.eq ? cr.begin_key.length() : cr.end_key.length(); @@ -184,10 +183,10 @@ Map GDScriptSyntaxHighlighter::_get_line_syntax_ String word = str.substr(j, to - j); Color col = Color(); - if (text_editor->has_keyword_color(word)) { - col = text_editor->get_keyword_color(word); - } else if (text_editor->has_member_color(word)) { - col = text_editor->get_member_color(word); + if (text_edit->has_keyword_color(word)) { + col = text_edit->get_keyword_color(word); + } else if (text_edit->has_member_color(word)) { + col = text_edit->get_member_color(word); for (int k = j - 1; k >= 0; k--) { if (str[k] == '.') { col = Color(); //member indexing not allowed @@ -276,7 +275,7 @@ Map GDScriptSyntaxHighlighter::_get_line_syntax_ if (in_region >= 0) { next_type = REGION; - color = text_editor->_get_color_region(in_region).color; + color = text_edit->_get_color_region(in_region).color; } else if (in_node_path) { next_type = NODE_PATH; color = node_path_color; @@ -335,32 +334,32 @@ Map GDScriptSyntaxHighlighter::_get_line_syntax_ if (color != prev_color) { prev_color = color; - highlighter_info.color = color; + highlighter_info["color"] = color; color_map[j] = highlighter_info; } } return color_map; } -String GDScriptSyntaxHighlighter::get_name() const { +String GDScriptSyntaxHighlighter::_get_name() const { return "GDScript"; } -List GDScriptSyntaxHighlighter::get_supported_languages() { - List languages; +Array GDScriptSyntaxHighlighter::_get_supported_languages() const { + Array languages; languages.push_back("GDScript"); return languages; } void GDScriptSyntaxHighlighter::_update_cache() { - font_color = text_editor->get_theme_color("font_color"); - symbol_color = text_editor->get_theme_color("symbol_color"); - function_color = text_editor->get_theme_color("function_color"); - number_color = text_editor->get_theme_color("number_color"); - member_color = text_editor->get_theme_color("member_variable_color"); + font_color = text_edit->get_theme_color("font_color"); + symbol_color = text_edit->get_theme_color("symbol_color"); + function_color = text_edit->get_theme_color("function_color"); + number_color = text_edit->get_theme_color("number_color"); + member_color = text_edit->get_theme_color("member_variable_color"); - const String text_editor_color_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme"); - const bool default_theme = text_editor_color_theme == "Default"; + const String text_edit_color_theme = EditorSettings::get_singleton()->get("text_edit/theme/color_theme"); + const bool default_theme = text_edit_color_theme == "Default"; if (default_theme || EditorSettings::get_singleton()->is_dark_theme()) { function_definition_color = Color(0.4, 0.9, 1.0); @@ -370,22 +369,22 @@ void GDScriptSyntaxHighlighter::_update_cache() { node_path_color = Color(0.32, 0.55, 0.29); } - EDITOR_DEF("text_editor/highlighting/gdscript/function_definition_color", function_definition_color); - EDITOR_DEF("text_editor/highlighting/gdscript/node_path_color", node_path_color); - if (text_editor_color_theme == "Adaptive" || default_theme) { + EDITOR_DEF("text_edit/highlighting/gdscript/function_definition_color", function_definition_color); + EDITOR_DEF("text_edit/highlighting/gdscript/node_path_color", node_path_color); + if (text_edit_color_theme == "Adaptive" || default_theme) { EditorSettings::get_singleton()->set_initial_value( - "text_editor/highlighting/gdscript/function_definition_color", + "text_edit/highlighting/gdscript/function_definition_color", function_definition_color, true); EditorSettings::get_singleton()->set_initial_value( - "text_editor/highlighting/gdscript/node_path_color", + "text_edit/highlighting/gdscript/node_path_color", node_path_color, true); } - function_definition_color = EDITOR_GET("text_editor/highlighting/gdscript/function_definition_color"); - node_path_color = EDITOR_GET("text_editor/highlighting/gdscript/node_path_color"); - type_color = EDITOR_GET("text_editor/highlighting/base_type_color"); + function_definition_color = EDITOR_GET("text_edit/highlighting/gdscript/function_definition_color"); + node_path_color = EDITOR_GET("text_edit/highlighting/gdscript/node_path_color"); + type_color = EDITOR_GET("text_edit/highlighting/base_type_color"); } SyntaxHighlighter *GDScriptSyntaxHighlighter::create() { diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index e652fb1471..47ea5a3d62 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -63,10 +63,10 @@ public: static SyntaxHighlighter *create(); virtual void _update_cache(); - virtual Map _get_line_syntax_highlighting(int p_line); + virtual Dictionary _get_line_syntax_highlighting(int p_line); - virtual String get_name() const; - virtual List get_supported_languages(); + virtual String _get_name() const; + virtual Array _get_supported_languages() const; }; #endif // GDSCRIPT_HIGHLIGHTER_H diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index b7ca3c882b..7a803d8930 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -4660,10 +4660,10 @@ void VisualScriptEditor::_member_option(int p_option) { } } -void VisualScriptEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) { +void VisualScriptEditor::add_syntax_highlighter(Ref p_highlighter) { } -void VisualScriptEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) { +void VisualScriptEditor::set_syntax_highlighter(Ref p_highlighter) { } void VisualScriptEditor::_bind_methods() { diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 28418965b8..f39def0b32 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -288,8 +288,8 @@ protected: static void _bind_methods(); public: - virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter) override; - virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter) override; + virtual void add_syntax_highlighter(Ref p_highlighter) override; + virtual void set_syntax_highlighter(Ref p_highlighter) override; virtual void apply_code() override; virtual RES get_edited_resource() const override; -- cgit v1.2.3