summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorDaniel J. Ramirez <djrmuv@gmail.com>2017-10-02 18:33:42 -0500
committerDaniel J. Ramirez <djrmuv@gmail.com>2017-10-02 18:33:42 -0500
commit6d874ea685bb57e1c78b7c67f0af7feafc1b55d5 (patch)
tree1c3dcd88f11f753a0e844c78c1804a75320e4b87 /editor/plugins
parent6dc1025e6313d711939269e1578fff5ffc0cd30a (diff)
Added correct initialization for script editor theme.
Some style fixes for VS interface.
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/script_editor_plugin.cpp3
-rw-r--r--editor/plugins/script_text_editor.cpp40
-rw-r--r--editor/plugins/script_text_editor.h12
3 files changed, 45 insertions, 10 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 9af5885a17..5e66488afb 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1683,9 +1683,8 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
}
ERR_FAIL_COND_V(!se, false);
- // load script before adding as child else editor will crash at theme loading
- se->set_edited_script(p_script);
tab_container->add_child(se);
+ se->set_edited_script(p_script);
se->set_tooltip_request_func("_get_debug_tooltip", this);
if (se->get_edit_menu()) {
se->get_edit_menu()->hide();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index b66e9598f9..a24856dad7 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -168,14 +168,34 @@ void ScriptTextEditor::_load_theme_settings() {
text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 4));
+ colors_cache.symbol_color = symbol_color;
+ colors_cache.keyword_color = keyword_color;
+ colors_cache.basetype_color = basetype_color;
+ colors_cache.type_color = type_color;
+ colors_cache.comment_color = comment_color;
+ colors_cache.string_color = string_color;
+
+ theme_loaded = true;
+ if (!script.is_null())
+ _set_theme_for_script();
+}
+
+void ScriptTextEditor::_set_theme_for_script() {
+
+ if (!theme_loaded)
+ return;
+
+ TextEdit *text_edit = code_editor->get_text_edit();
+
List<String> keywords;
script->get_language()->get_reserved_words(&keywords);
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
- text_edit->add_keyword_color(E->get(), keyword_color);
+ text_edit->add_keyword_color(E->get(), colors_cache.keyword_color);
}
//colorize core types
+ const Color basetype_color = colors_cache.basetype_color;
text_edit->add_keyword_color("String", basetype_color);
text_edit->add_keyword_color("Vector2", basetype_color);
text_edit->add_keyword_color("Rect2", basetype_color);
@@ -210,7 +230,7 @@ void ScriptTextEditor::_load_theme_settings() {
if (n.begins_with("_"))
n = n.substr(1, n.length());
- text_edit->add_keyword_color(n, type_color);
+ text_edit->add_keyword_color(n, colors_cache.type_color);
}
//colorize comments
@@ -223,7 +243,7 @@ void ScriptTextEditor::_load_theme_settings() {
String beg = comment.get_slice(" ", 0);
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
- text_edit->add_color_region(beg, end, comment_color, end == "");
+ text_edit->add_color_region(beg, end, colors_cache.comment_color, end == "");
}
//colorize strings
@@ -235,7 +255,7 @@ void ScriptTextEditor::_load_theme_settings() {
String string = E->get();
String beg = string.get_slice(" ", 0);
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
- text_edit->add_color_region(beg, end, string_color, end == "");
+ text_edit->add_color_region(beg, end, colors_cache.string_color, end == "");
}
}
@@ -263,10 +283,10 @@ void ScriptTextEditor::reload_text() {
void ScriptTextEditor::_notification(int p_what) {
- if (p_what == NOTIFICATION_READY) {
-
- //emit_signal("name_changed");
- _load_theme_settings();
+ switch (p_what) {
+ case NOTIFICATION_READY:
+ _load_theme_settings();
+ break;
}
}
@@ -556,6 +576,8 @@ 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() {
@@ -1452,6 +1474,8 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) {
ScriptTextEditor::ScriptTextEditor() {
+ theme_loaded = false;
+
code_editor = memnew(CodeTextEditor);
add_child(code_editor);
code_editor->add_constant_override("separation", 0);
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index f8b7470ec8..83f3ea57c0 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -57,6 +57,17 @@ class ScriptTextEditor : public ScriptEditorBase {
int color_line;
String color_args;
+ struct ColorsCache {
+ Color symbol_color;
+ Color keyword_color;
+ Color basetype_color;
+ Color type_color;
+ Color comment_color;
+ Color string_color;
+ } colors_cache;
+
+ bool theme_loaded;
+
enum {
EDIT_UNDO,
EDIT_REDO,
@@ -101,6 +112,7 @@ protected:
void _validate_script();
void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force);
void _load_theme_settings();
+ void _set_theme_for_script();
void _notification(int p_what);
static void _bind_methods();