mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 08:23:29 +00:00
Abstracted the syntax highlighter from text edit
This commit is contained in:
parent
098c7ba4f9
commit
f7c727e6c3
11 changed files with 828 additions and 272 deletions
|
@ -573,6 +573,7 @@ void ScriptTextEditor::set_edited_script(const Ref<Script> &p_script) {
|
|||
ERR_FAIL_COND(!script.is_null());
|
||||
|
||||
script = p_script;
|
||||
_set_theme_for_script();
|
||||
|
||||
code_editor->get_text_edit()->set_text(script->get_source_code());
|
||||
code_editor->get_text_edit()->clear_undo_history();
|
||||
|
@ -580,8 +581,6 @@ void ScriptTextEditor::set_edited_script(const Ref<Script> &p_script) {
|
|||
|
||||
emit_signal("name_changed");
|
||||
code_editor->update_line_and_column();
|
||||
|
||||
_set_theme_for_script();
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_validate_script() {
|
||||
|
@ -1245,11 +1244,26 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptTextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
|
||||
highlighters[p_highlighter->get_name()] = p_highlighter;
|
||||
highlighter_menu->get_popup()->add_item(p_highlighter->get_name());
|
||||
}
|
||||
|
||||
void ScriptTextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
|
||||
TextEdit *te = code_editor->get_text_edit();
|
||||
te->_set_syntax_highlighting(p_highlighter);
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
|
||||
set_syntax_highlighter(highlighters[highlighter_menu->get_popup()->get_item_text(p_idx)]);
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method("_validate_script", &ScriptTextEditor::_validate_script);
|
||||
ClassDB::bind_method("_load_theme_settings", &ScriptTextEditor::_load_theme_settings);
|
||||
ClassDB::bind_method("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled);
|
||||
ClassDB::bind_method("_change_syntax_highlighter", &ScriptTextEditor::_change_syntax_highlighter);
|
||||
ClassDB::bind_method("_edit_option", &ScriptTextEditor::_edit_option);
|
||||
ClassDB::bind_method("_goto_line", &ScriptTextEditor::_goto_line);
|
||||
ClassDB::bind_method("_lookup_symbol", &ScriptTextEditor::_lookup_symbol);
|
||||
|
@ -1635,6 +1649,14 @@ ScriptTextEditor::ScriptTextEditor() {
|
|||
|
||||
edit_hb->add_child(edit_menu);
|
||||
|
||||
highlighters["Standard"] = NULL;
|
||||
|
||||
highlighter_menu = memnew(MenuButton);
|
||||
highlighter_menu->set_text(TTR("Syntax Highlighter"));
|
||||
highlighter_menu->get_popup()->add_item("Standard");
|
||||
highlighter_menu->get_popup()->connect("id_pressed", this, "_change_syntax_highlighter");
|
||||
edit_hb->add_child(highlighter_menu);
|
||||
|
||||
quick_open = memnew(ScriptEditorQuickOpen);
|
||||
add_child(quick_open);
|
||||
quick_open->connect("goto_line", this, "_goto_line");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue