diff options
Diffstat (limited to 'editor/plugins/text_shader_editor.cpp')
-rw-r--r-- | editor/plugins/text_shader_editor.cpp | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 6e786c1d94..fb8bed381e 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -30,12 +30,12 @@ #include "text_shader_editor.h" +#include "core/config/project_settings.h" #include "core/version_generated.gen.h" +#include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" -#include "editor/filesystem_dock.h" -#include "editor/project_settings_editor.h" #include "editor/themes/editor_scale.h" #include "editor/themes/editor_theme_manager.h" #include "scene/gui/split_container.h" @@ -49,6 +49,11 @@ Dictionary GDShaderSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l for (const Point2i ®ion : disabled_branch_regions) { if (p_line >= region.x && p_line <= region.y) { + // When "color_regions[0].p_start_key.length() > 2", + // disabled_branch_region causes color_region to break. + // This should be seen as a temporary solution. + CodeHighlighter::_get_line_syntax_highlighting_impl(p_line); + Dictionary highlighter_info; highlighter_info["color"] = disabled_branch_color; @@ -311,6 +316,11 @@ void ShaderTextEditor::_load_theme_settings() { syntax_highlighter->add_color_region("/*", "*/", comment_color, false); syntax_highlighter->add_color_region("//", "", comment_color, true); + const Color doc_comment_color = EDITOR_GET("text_editor/theme/highlighting/doc_comment_color"); + syntax_highlighter->add_color_region("/**", "*/", doc_comment_color, false); + // "/**/" will be treated as the start of the "/**" region, this line is guaranteed to end the color_region. + syntax_highlighter->add_color_region("/**/", "", comment_color, true); + // Disabled preprocessor branches use translucent text color to be easier to distinguish from comments. syntax_highlighter->set_disabled_branch_color(Color(EDITOR_GET("text_editor/theme/highlighting/text_color")) * Color(1, 1, 1, 0.5)); @@ -331,6 +341,8 @@ void ShaderTextEditor::_load_theme_settings() { warnings_panel->add_theme_font_override("normal_font", EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("main"), EditorStringName(EditorFonts))); warnings_panel->add_theme_font_size_override("normal_font_size", EditorNode::get_singleton()->get_editor_theme()->get_font_size(SNAME("main_size"), EditorStringName(EditorFonts))); } + + syntax_highlighter->set_uint_suffix_enabled(true); } void ShaderTextEditor::_check_shader_mode() { @@ -431,7 +443,7 @@ void ShaderTextEditor::_code_complete_script(const String &p_code, List<ScriptLa } void ShaderTextEditor::_validate_script() { - emit_signal(SNAME("script_changed")); // Ensure to notify that it changed, so it is applied + emit_signal(CoreStringName(script_changed)); // Ensure to notify that it changed, so it is applied String code; @@ -578,9 +590,7 @@ void ShaderTextEditor::_update_warning_panel() { int warning_count = 0; warnings_panel->push_table(2); - for (int i = 0; i < warnings.size(); i++) { - ShaderWarning &w = warnings[i]; - + for (const ShaderWarning &w : warnings) { if (warning_count == 0) { if (saved_treat_warning_as_errors) { String error_text = "error(" + itos(w.get_line()) + "): " + w.get_message() + " " + TTR("Warnings should be fixed to prevent errors."); @@ -650,10 +660,10 @@ void TextShaderEditor::_menu_option(int p_option) { code_editor->get_text_editor()->select_all(); } break; case EDIT_MOVE_LINE_UP: { - code_editor->move_lines_up(); + code_editor->get_text_editor()->move_lines_up(); } break; case EDIT_MOVE_LINE_DOWN: { - code_editor->move_lines_down(); + code_editor->get_text_editor()->move_lines_down(); } break; case EDIT_INDENT: { if (shader.is_null() && shader_inc.is_null()) { @@ -668,10 +678,10 @@ void TextShaderEditor::_menu_option(int p_option) { code_editor->get_text_editor()->unindent_lines(); } break; case EDIT_DELETE_LINE: { - code_editor->delete_lines(); + code_editor->get_text_editor()->delete_lines(); } break; case EDIT_DUPLICATE_SELECTION: { - code_editor->duplicate_selection(); + code_editor->get_text_editor()->duplicate_selection(); } break; case EDIT_DUPLICATE_LINES: { code_editor->get_text_editor()->duplicate_lines(); @@ -725,6 +735,13 @@ void TextShaderEditor::_menu_option(int p_option) { } } +void TextShaderEditor::_prepare_edit_menu() { + const CodeEdit *tx = code_editor->get_text_editor(); + PopupMenu *popup = edit_menu->get_popup(); + popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo()); + popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo()); +} + void TextShaderEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: @@ -753,6 +770,7 @@ void TextShaderEditor::_apply_editor_settings() { code_editor->update_editor_settings(); trim_trailing_whitespace_on_save = EDITOR_GET("text_editor/behavior/files/trim_trailing_whitespace_on_save"); + trim_final_newlines_on_save = EDITOR_GET("text_editor/behavior/files/trim_final_newlines_on_save"); } void TextShaderEditor::_show_warnings_panel(bool p_show) { @@ -917,6 +935,10 @@ void TextShaderEditor::save_external_data(const String &p_str) { trim_trailing_whitespace(); } + if (trim_final_newlines_on_save) { + trim_final_newlines(); + } + apply_shaders(); Ref<Shader> edited_shader = code_editor->get_edited_shader(); @@ -943,6 +965,10 @@ void TextShaderEditor::trim_trailing_whitespace() { code_editor->trim_trailing_whitespace(); } +void TextShaderEditor::trim_final_newlines() { + code_editor->trim_final_newlines(); +} + void TextShaderEditor::validate_script() { code_editor->_validate_script(); } @@ -1007,7 +1033,7 @@ void TextShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { } } if (!tx->has_selection()) { - tx->set_caret_line(row, true, false); + tx->set_caret_line(row, true, false, -1); tx->set_caret_column(col); } } @@ -1078,6 +1104,9 @@ void TextShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !code_editor->get_text_editor()->has_undo()); + context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !code_editor->get_text_editor()->has_redo()); + context_menu->set_position(get_screen_position() + p_position); context_menu->reset_size(); context_menu->popup(); @@ -1095,7 +1124,7 @@ TextShaderEditor::TextShaderEditor() { code_editor->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); code_editor->connect("show_warnings_panel", callable_mp(this, &TextShaderEditor::_show_warnings_panel)); - code_editor->connect("script_changed", callable_mp(this, &TextShaderEditor::apply_shaders)); + code_editor->connect(CoreStringName(script_changed), callable_mp(this, &TextShaderEditor::apply_shaders)); EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &TextShaderEditor::_editor_settings_changed)); ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &TextShaderEditor::_project_settings_changed)); @@ -1103,7 +1132,7 @@ TextShaderEditor::TextShaderEditor() { code_editor->get_text_editor()->set_context_menu_enabled(false); code_editor->get_text_editor()->set_draw_breakpoints_gutter(false); code_editor->get_text_editor()->set_draw_executing_lines_gutter(false); - code_editor->get_text_editor()->connect("gui_input", callable_mp(this, &TextShaderEditor::_text_edit_gui_input)); + code_editor->get_text_editor()->connect(SceneStringName(gui_input), callable_mp(this, &TextShaderEditor::_text_edit_gui_input)); code_editor->update_editor_settings(); @@ -1118,6 +1147,7 @@ TextShaderEditor::TextShaderEditor() { edit_menu->set_shortcut_context(this); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); + edit_menu->connect("about_to_popup", callable_mp(this, &TextShaderEditor::_prepare_edit_menu)); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO); |