Add special coloring to members, to make shadowing more obvious.
This commit is contained in:
parent
ab9f7f4fc2
commit
419705db6e
@ -63,6 +63,7 @@ void ScriptTextEditor::apply_code() {
|
|||||||
//print_line("applying code");
|
//print_line("applying code");
|
||||||
script->set_source_code(code_editor->get_text_edit()->get_text());
|
script->set_source_code(code_editor->get_text_edit()->get_text());
|
||||||
script->update_exports();
|
script->update_exports();
|
||||||
|
_update_member_keywords();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Script> ScriptTextEditor::get_edited_script() const {
|
Ref<Script> ScriptTextEditor::get_edited_script() const {
|
||||||
@ -70,6 +71,37 @@ Ref<Script> ScriptTextEditor::get_edited_script() const {
|
|||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptTextEditor::_update_member_keywords() {
|
||||||
|
member_keywords.clear();
|
||||||
|
code_editor->get_text_edit()->clear_member_keywords();
|
||||||
|
Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
|
||||||
|
|
||||||
|
StringName instance_base = script->get_instance_base_type();
|
||||||
|
|
||||||
|
if (instance_base == StringName())
|
||||||
|
return;
|
||||||
|
List<PropertyInfo> plist;
|
||||||
|
ClassDB::get_property_list(instance_base, &plist);
|
||||||
|
|
||||||
|
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
||||||
|
String name = E->get().name;
|
||||||
|
if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP)
|
||||||
|
continue;
|
||||||
|
if (name.find("/") != -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
code_editor->get_text_edit()->add_member_keyword(name, member_variable_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> clist;
|
||||||
|
ClassDB::get_integer_constant_list(instance_base, &clist);
|
||||||
|
|
||||||
|
for (List<String>::Element *E = clist.front(); E; E = E->next()) {
|
||||||
|
|
||||||
|
code_editor->get_text_edit()->add_member_keyword(E->get(), member_variable_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptTextEditor::_load_theme_settings() {
|
void ScriptTextEditor::_load_theme_settings() {
|
||||||
|
|
||||||
TextEdit *text_edit = code_editor->get_text_edit();
|
TextEdit *text_edit = code_editor->get_text_edit();
|
||||||
@ -563,6 +595,7 @@ void ScriptTextEditor::_validate_script() {
|
|||||||
if (!script->is_tool()) {
|
if (!script->is_tool()) {
|
||||||
script->set_source_code(text);
|
script->set_source_code(text);
|
||||||
script->update_exports();
|
script->update_exports();
|
||||||
|
_update_member_keywords();
|
||||||
//script->reload(); //will update all the variables in property editors
|
//script->reload(); //will update all the variables in property editors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ class ScriptTextEditor : public ScriptEditorBase {
|
|||||||
|
|
||||||
Vector<String> functions;
|
Vector<String> functions;
|
||||||
|
|
||||||
|
Vector<String> member_keywords;
|
||||||
|
|
||||||
HBoxContainer *edit_hb;
|
HBoxContainer *edit_hb;
|
||||||
|
|
||||||
MenuButton *edit_menu;
|
MenuButton *edit_menu;
|
||||||
@ -58,6 +60,8 @@ class ScriptTextEditor : public ScriptEditorBase {
|
|||||||
int color_line;
|
int color_line;
|
||||||
String color_args;
|
String color_args;
|
||||||
|
|
||||||
|
void _update_member_keywords();
|
||||||
|
|
||||||
struct ColorsCache {
|
struct ColorsCache {
|
||||||
Color symbol_color;
|
Color symbol_color;
|
||||||
Color keyword_color;
|
Color keyword_color;
|
||||||
|
@ -1025,6 +1025,21 @@ void TextEdit::_notification(int p_what) {
|
|||||||
|
|
||||||
const Color *col = keywords.custom_getptr(range, hash);
|
const Color *col = keywords.custom_getptr(range, hash);
|
||||||
|
|
||||||
|
if (!col) {
|
||||||
|
col = member_keywords.custom_getptr(range, hash);
|
||||||
|
|
||||||
|
if (col) {
|
||||||
|
for (int k = j - 1; k >= 0; k--) {
|
||||||
|
if (str[k] == '.') {
|
||||||
|
col = NULL; //member indexing not allowed
|
||||||
|
break;
|
||||||
|
} else if (str[k] > 32) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (col) {
|
if (col) {
|
||||||
|
|
||||||
in_keyword = true;
|
in_keyword = true;
|
||||||
@ -4138,6 +4153,16 @@ void TextEdit::add_color_region(const String &p_begin_key, const String &p_end_k
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEdit::add_member_keyword(const String &p_keyword, const Color &p_color) {
|
||||||
|
member_keywords[p_keyword] = p_color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextEdit::clear_member_keywords() {
|
||||||
|
member_keywords.clear();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void TextEdit::set_syntax_coloring(bool p_enabled) {
|
void TextEdit::set_syntax_coloring(bool p_enabled) {
|
||||||
|
|
||||||
syntax_coloring = p_enabled;
|
syntax_coloring = p_enabled;
|
||||||
|
@ -210,6 +210,7 @@ class TextEdit : public Control {
|
|||||||
|
|
||||||
//syntax coloring
|
//syntax coloring
|
||||||
HashMap<String, Color> keywords;
|
HashMap<String, Color> keywords;
|
||||||
|
HashMap<String, Color> member_keywords;
|
||||||
|
|
||||||
Vector<ColorRegion> color_regions;
|
Vector<ColorRegion> color_regions;
|
||||||
|
|
||||||
@ -546,6 +547,9 @@ public:
|
|||||||
void add_color_region(const String &p_begin_key = String(), const String &p_end_key = String(), const Color &p_color = Color(), bool p_line_only = false);
|
void add_color_region(const String &p_begin_key = String(), const String &p_end_key = String(), const Color &p_color = Color(), bool p_line_only = false);
|
||||||
void clear_colors();
|
void clear_colors();
|
||||||
|
|
||||||
|
void add_member_keyword(const String &p_keyword, const Color &p_color);
|
||||||
|
void clear_member_keywords();
|
||||||
|
|
||||||
int get_v_scroll() const;
|
int get_v_scroll() const;
|
||||||
void set_v_scroll(int p_scroll);
|
void set_v_scroll(int p_scroll);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user