diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/code_editor.cpp | 33 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 31 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.h | 5 | ||||
-rw-r--r-- | editor/plugins/shader_editor_plugin.cpp | 22 | ||||
-rw-r--r-- | editor/plugins/shader_editor_plugin.h | 2 |
5 files changed, 66 insertions, 27 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index fb36bfc5e5..0a269d960e 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1663,17 +1663,29 @@ void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) { void CodeTextEditor::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { + error_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); + error_button->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + error_button->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + error_button->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + + warning_button->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons"))); + warning_button->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); + warning_button->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + warning_button->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + + line_and_col_txt->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + line_and_col_txt->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + + if (p_what == NOTIFICATION_ENTER_TREE) { + break; + } if (toggle_scripts_button->is_visible()) { update_toggle_scripts_button(); } _update_text_editor_theme(); } break; - case NOTIFICATION_ENTER_TREE: { - error_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); - warning_button->set_icon(get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons"))); - add_theme_constant_override("separation", 4 * EDSCALE); - } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (toggle_scripts_button->is_visible()) { update_toggle_scripts_button(); @@ -1874,10 +1886,6 @@ CodeTextEditor::CodeTextEditor() { error_button->connect("pressed", callable_mp(this, &CodeTextEditor::_error_button_pressed)); error_button->set_tooltip(TTR("Errors")); - error_button->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor"))); - error_button->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); - error_button->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); - is_errors_panel_opened = false; set_error_count(0); @@ -1890,10 +1898,6 @@ CodeTextEditor::CodeTextEditor() { warning_button->connect("pressed", callable_mp(this, &CodeTextEditor::_warning_button_pressed)); warning_button->set_tooltip(TTR("Warnings")); - warning_button->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("warning_color"), SNAME("Editor"))); - warning_button->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); - warning_button->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); - is_warnings_panel_opened = false; set_warning_count(0); @@ -1901,8 +1905,6 @@ CodeTextEditor::CodeTextEditor() { line_and_col_txt = memnew(Label); status_bar->add_child(line_and_col_txt); line_and_col_txt->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER); - line_and_col_txt->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); - line_and_col_txt->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); line_and_col_txt->set_tooltip(TTR("Line and column numbers.")); line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP); @@ -1933,4 +1935,5 @@ CodeTextEditor::CodeTextEditor() { font_resize_timer->connect("timeout", callable_mp(this, &CodeTextEditor::_font_resize_timeout)); EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &CodeTextEditor::_on_settings_change)); + add_theme_constant_override("separation", 4 * EDSCALE); } diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index b765091d2b..09af73520b 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -413,12 +413,14 @@ void ScriptTextEditor::_validate_script() { String text = te->get_text(); List<String> fnc; - Set<int> safe_lines; - List<ScriptLanguage::Warning> warnings; - List<ScriptLanguage::ScriptError> errors; + + warnings.clear(); + errors.clear(); + safe_lines.clear(); if (!script->get_language()->validate(text, script->get_path(), &fnc, &errors, &warnings, &safe_lines)) { - String error_text = TTR("Error at ") + "(" + itos(errors[0].line) + "," + itos(errors[0].column) + "): " + errors[0].message; + // TRANSLATORS: Script error pointing to a line and column number. + String error_text = vformat(TTR("Error at (%d, %d):"), errors[0].line, errors[0].column) + " " + errors[0].message; code_editor->set_error(error_text); code_editor->set_error_pos(errors[0].line - 1, errors[0].column - 1); script_is_valid = false; @@ -437,7 +439,14 @@ void ScriptTextEditor::_validate_script() { script_is_valid = true; } _update_connected_methods(); + _update_warnings(); + _update_errors(); + emit_signal(SNAME("name_changed")); + emit_signal(SNAME("edited_script_changed")); +} + +void ScriptTextEditor::_update_warnings() { int warning_nb = warnings.size(); warnings_panel->clear(); @@ -465,7 +474,6 @@ void ScriptTextEditor::_validate_script() { } } - code_editor->set_error_count(errors.size()); code_editor->set_warning_count(warning_nb); if (has_connections_table) { @@ -489,6 +497,10 @@ void ScriptTextEditor::_validate_script() { warnings_panel->pop(); // Cell. } warnings_panel->pop(); // Table. +} + +void ScriptTextEditor::_update_errors() { + code_editor->set_error_count(errors.size()); errors_panel->clear(); errors_panel->push_table(2); @@ -507,6 +519,7 @@ void ScriptTextEditor::_validate_script() { } errors_panel->pop(); // Table + CodeEdit *te = code_editor->get_text_editor(); bool highlight_safe = EDITOR_DEF("text_editor/appearance/gutters/highlight_type_safe_lines", true); bool last_is_safe = false; for (int i = 0; i < te->get_line_count(); i++) { @@ -536,9 +549,6 @@ void ScriptTextEditor::_validate_script() { te->set_line_gutter_item_color(i, 1, default_line_number_color); } } - - emit_signal(SNAME("name_changed")); - emit_signal(SNAME("edited_script_changed")); } void ScriptTextEditor::_update_bookmark_list() { @@ -1323,6 +1333,11 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) { void ScriptTextEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: + if (is_visible_in_tree()) { + _update_warnings(); + _update_errors(); + } + [[fallthrough]]; case NOTIFICATION_ENTER_TREE: { code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_line_height()); } break; diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index bc674ce964..1e2284b403 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -62,6 +62,9 @@ class ScriptTextEditor : public ScriptEditorBase { bool editor_enabled = false; Vector<String> functions; + List<ScriptLanguage::Warning> warnings; + List<ScriptLanguage::ScriptError> errors; + Set<int> safe_lines; List<Connection> missing_connections; @@ -154,6 +157,8 @@ protected: void _breakpoint_toggled(int p_row); void _validate_script(); // No longer virtual. + void _update_warnings(); + void _update_errors(); void _update_bookmark_list(); void _bookmark_item_pressed(int p_idx); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index afecada1db..4bbeb33406 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -50,6 +50,20 @@ static bool saved_treat_warning_as_errors = false; static Map<ShaderWarning::Code, bool> saved_warnings; static uint32_t saved_warning_flags = 0U; +void ShaderTextEditor::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_THEME_CHANGED: { + if (is_visible_in_tree()) { + _load_theme_settings(); + if (warnings.size() > 0 && last_compile_result == OK) { + warnings_panel->clear(); + _update_warning_panel(); + } + } + } break; + } +} + Ref<Shader> ShaderTextEditor::get_edited_shader() const { return shader; } @@ -243,9 +257,9 @@ void ShaderTextEditor::_validate_script() { sl.enable_warning_checking(saved_warnings_enabled); sl.set_warning_flags(saved_warning_flags); - Error err = sl.compile(code, info); + last_compile_result = sl.compile(code, info); - if (err != OK) { + if (last_compile_result != OK) { String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); set_error(error_text); set_error_pos(sl.get_error_line() - 1, 0); @@ -260,14 +274,14 @@ void ShaderTextEditor::_validate_script() { set_error(""); } - if (warnings.size() > 0 || err != OK) { + if (warnings.size() > 0 || last_compile_result != OK) { warnings_panel->clear(); } warnings.clear(); for (List<ShaderWarning>::Element *E = sl.get_warnings_ptr(); E; E = E->next()) { warnings.push_back(E->get()); } - if (warnings.size() > 0 && err == OK) { + if (warnings.size() > 0 && last_compile_result == OK) { warnings.sort_custom<WarningsComparator>(); _update_warning_panel(); } else { diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index db2d1438b3..9196ded921 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -55,11 +55,13 @@ class ShaderTextEditor : public CodeTextEditor { RichTextLabel *warnings_panel = nullptr; Ref<Shader> shader; List<ShaderWarning> warnings; + Error last_compile_result = Error::OK; void _check_shader_mode(); void _update_warning_panel(); protected: + void _notification(int p_what); static void _bind_methods(); virtual void _load_theme_settings() override; |