1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Abstracted the syntax highlighter from text edit

This commit is contained in:
Paulb23
2018-04-02 12:41:44 +01:00
parent 098c7ba4f9
commit f7c727e6c3
11 changed files with 828 additions and 272 deletions

View File

@@ -1778,6 +1778,20 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
}
ERR_FAIL_COND_V(!se, false);
bool highlighter_set = false;
for (int i = 0; i < syntax_highlighters_func_count; i++) {
SyntaxHighlighter *highlighter = syntax_highlighters_funcs[i]();
se->add_syntax_highlighter(highlighter);
if (!highlighter_set) {
List<String> languages = highlighter->get_supported_languages();
if (languages.find(p_script->get_language()->get_name())) {
se->set_syntax_highlighter(highlighter);
highlighter_set = true;
}
}
}
tab_container->add_child(se);
se->set_edited_script(p_script);
se->set_tooltip_request_func("_get_debug_tooltip", this);
@@ -2494,6 +2508,14 @@ void ScriptEditor::_open_script_request(const String &p_path) {
}
}
int ScriptEditor::syntax_highlighters_func_count = 0;
CreateSyntaxHighlighterFunc ScriptEditor::syntax_highlighters_funcs[ScriptEditor::SYNTAX_HIGHLIGHTER_FUNC_MAX];
void ScriptEditor::register_create_syntax_highlighter_function(CreateSyntaxHighlighterFunc p_func) {
ERR_FAIL_COND(syntax_highlighters_func_count == SYNTAX_HIGHLIGHTER_FUNC_MAX);
syntax_highlighters_funcs[syntax_highlighters_func_count++] = p_func;
}
int ScriptEditor::script_editor_func_count = 0;
CreateScriptEditorFunc ScriptEditor::script_editor_funcs[ScriptEditor::SCRIPT_EDITOR_FUNC_MAX];