summaryrefslogtreecommitdiff
path: root/editor/plugins/text_editor.cpp
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2020-03-07 11:17:18 +0000
committerPaulb23 <p_batty@hotmail.co.uk>2020-07-11 15:26:58 +0100
commit2f1080be9b032b1cf5086201e45057baa6b1a179 (patch)
treec6af7f72914a1ea9c88eddb80925ae174cfbd8e3 /editor/plugins/text_editor.cpp
parentbe119c5c473be3fb73458baca7066d85869d6f1d (diff)
Convert syntax highlighters into a resource
Diffstat (limited to 'editor/plugins/text_editor.cpp')
-rw-r--r--editor/plugins/text_editor.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index 3ceb9bfd82..071a46b5ee 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -33,16 +33,16 @@
#include "core/os/keyboard.h"
#include "editor/editor_node.h"
-void TextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
- highlighters[p_highlighter->get_name()] = p_highlighter;
- highlighter_menu->add_radio_check_item(p_highlighter->get_name());
+void TextEditor::add_syntax_highlighter(Ref<SyntaxHighlighter> p_highlighter) {
+ highlighters[p_highlighter->_get_name()] = p_highlighter;
+ highlighter_menu->add_radio_check_item(p_highlighter->_get_name());
}
-void TextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
+void TextEditor::set_syntax_highlighter(Ref<SyntaxHighlighter> p_highlighter) {
TextEdit *te = code_editor->get_text_edit();
- te->_set_syntax_highlighting(p_highlighter);
- if (p_highlighter != nullptr) {
- highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->get_name()), true);
+ te->set_syntax_highlighting(p_highlighter);
+ if (p_highlighter.is_valid()) {
+ highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->_get_name()), true);
} else {
highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text("Standard"), true);
}
@@ -61,7 +61,7 @@ void TextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
}
void TextEditor::_change_syntax_highlighter(int p_idx) {
- Map<String, SyntaxHighlighter *>::Element *el = highlighters.front();
+ Map<String, Ref<SyntaxHighlighter> >::Element *el = highlighters.front();
while (el != nullptr) {
highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(el->key()), false);
el = el->next();
@@ -634,7 +634,7 @@ TextEditor::TextEditor() {
convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize")), EDIT_CAPITALIZE);
convert_case->connect("id_pressed", callable_mp(this, &TextEditor::_edit_option));
- highlighters["Standard"] = nullptr;
+ highlighters["Standard"] = Ref<SyntaxHighlighter>();
highlighter_menu = memnew(PopupMenu);
highlighter_menu->set_name("highlighter_menu");
edit_menu->get_popup()->add_child(highlighter_menu);
@@ -666,11 +666,6 @@ TextEditor::TextEditor() {
}
TextEditor::~TextEditor() {
- for (const Map<String, SyntaxHighlighter *>::Element *E = highlighters.front(); E; E = E->next()) {
- if (E->get() != nullptr) {
- memdelete(E->get());
- }
- }
highlighters.clear();
}