From 0dbfb864ad173c9f9d4d5d9315631eec01376806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 10 Oct 2016 10:38:12 +0200 Subject: [PATCH] Backport goodies for the code editors Refactor duplicated code (from 0159e4f96918990ee7bc3e9616ba073e566ad6e4) Add line length guideline to code editors (from d9c1729a8f1d3eceb259ef540b378b70beb55f24) Allow turning off zero-padding for line numbers (from 00b3af246b03bc789a7edc45c11b000d7d63ad27) (In 3.0 zero-padding is off by default, but for 2.1 I'm setting the default to be on because it's how it always worked.) Fixed line lenght guideline drawing with color option (from @Paulb23's 6b42cd5fe637d6d0fe30fa397eca659d295ad956) --- scene/gui/text_edit.cpp | 32 +++++++++++++++- scene/gui/text_edit.h | 9 +++++ tools/editor/code_editor.cpp | 18 +++++++++ tools/editor/code_editor.h | 1 + tools/editor/editor_settings.cpp | 11 ++++++ tools/editor/plugins/script_editor_plugin.cpp | 24 +----------- tools/editor/plugins/shader_editor_plugin.cpp | 38 ++----------------- 7 files changed, 75 insertions(+), 58 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1a0e87057f..f7e8893a20 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -684,6 +684,8 @@ void TextEdit::_notification(int p_what) { // get the highlighted words String highlighted_text = get_selection_text(); + String line_num_padding = line_numbers_zero_padded ? "0" : " "; + for (int i=0;idraw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT)+cache.breakpoint_gutter_width,ofs_y+cache.font->get_ascent()),fc,cache.line_number_color); @@ -1056,6 +1058,14 @@ void TextEdit::_notification(int p_what) { } } + if (line_length_guideline) { + int x=xmargin_beg+cache.font->get_char_size('0').width*line_length_guideline_col-cursor.x_ofs; + if (x>xmargin_beg && xcanvas_item_add_line(ci,Point2(x,0),Point2(x,cache.size.height),cache.line_length_guideline_color); + } + } + + bool completion_below = false; if (completion_active) { // code completion box @@ -3380,6 +3390,7 @@ void TextEdit::_update_caches() { cache.selection_color=get_color("selection_color"); cache.mark_color=get_color("mark_color"); cache.current_line_color=get_color("current_line_color"); + cache.line_length_guideline_color=get_color("line_length_guideline_color"); cache.breakpoint_color=get_color("breakpoint_color"); cache.brace_mismatch_color=get_color("brace_mismatch_color"); cache.word_highlighted_color=get_color("word_highlighted_color"); @@ -4386,10 +4397,26 @@ void TextEdit::set_show_line_numbers(bool p_show) { update(); } +void TextEdit::set_line_numbers_zero_padded(bool p_zero_padded) { + + line_numbers_zero_padded=p_zero_padded; + update(); +} + bool TextEdit::is_show_line_numbers_enabled() const { return line_numbers; } +void TextEdit::set_show_line_length_guideline(bool p_show) { + line_length_guideline=p_show; + update(); +} + +void TextEdit::set_line_length_guideline_column(int p_column) { + line_length_guideline_col=p_column; + update(); +} + void TextEdit::set_draw_breakpoint_gutter(bool p_draw) { draw_breakpoint_gutter = p_draw; update(); @@ -4651,6 +4678,9 @@ TextEdit::TextEdit() { completion_line_ofs=0; tooltip_obj=NULL; line_numbers=false; + line_numbers_zero_padded=false; + line_length_guideline=false; + line_length_guideline_col=80; draw_breakpoint_gutter=false; next_operation_is_complex=false; scroll_past_end_of_file_enabled=false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 9468fa2d48..b7ddaddc44 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -91,6 +91,7 @@ class TextEdit : public Control { Color mark_color; Color breakpoint_color; Color current_line_color; + Color line_length_guideline_color; Color brace_mismatch_color; Color word_highlighted_color; Color search_result_color; @@ -232,6 +233,9 @@ class TextEdit : public Control { bool text_changed_dirty; bool undo_enabled; bool line_numbers; + bool line_numbers_zero_padded; + bool line_length_guideline; + int line_length_guideline_col; bool draw_breakpoint_gutter; int breakpoint_gutter_width; @@ -481,6 +485,11 @@ public: void set_show_line_numbers(bool p_show); bool is_show_line_numbers_enabled() const; + void set_line_numbers_zero_padded(bool p_zero_padded); + + void set_show_line_length_guideline(bool p_show); + void set_line_length_guideline_column(int p_column); + void set_draw_breakpoint_gutter(bool p_draw); bool is_drawing_breakpoint_gutter() const; diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index c4d5d79f12..589e18cb01 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -1085,6 +1085,24 @@ void CodeTextEditor::_font_resize_timeout() { } } +void CodeTextEditor::update_editor_settings() { + + text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete")); + text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file")); + text_editor->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size")); + text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs")); + text_editor->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers")); + text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/line_numbers_zero_padded")); + text_editor->set_show_line_length_guideline(EditorSettings::get_singleton()->get("text_editor/show_line_length_guideline")); + text_editor->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/line_length_guideline_column")); + text_editor->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting")); + text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences")); + text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink")); + text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed")); + text_editor->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/show_breakpoint_gutter")); + text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret")); +} + void CodeTextEditor::set_error(const String& p_error) { if (p_error!="") { diff --git a/tools/editor/code_editor.h b/tools/editor/code_editor.h index 3becef64cb..6c2fe6ac4c 100644 --- a/tools/editor/code_editor.h +++ b/tools/editor/code_editor.h @@ -236,6 +236,7 @@ protected: public: + void update_editor_settings(); TextEdit *get_text_edit() { return text_editor; } FindReplaceBar *get_find_replace_bar() { return find_replace_bar; } virtual void apply_code() {} diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 27caf01f14..a1464b3ad1 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -546,9 +546,15 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { hints["text_editor/tab_size"]=PropertyInfo(Variant::INT,"text_editor/tab_size",PROPERTY_HINT_RANGE,"1, 64, 1"); // size of 0 crashes. set("text_editor/draw_tabs", true); + set("text_editor/line_numbers_zero_padded", true); + set("text_editor/show_line_numbers", true); set("text_editor/show_breakpoint_gutter", true); + set("text_editor/show_line_length_guideline", false); + set("text_editor/line_length_guideline_column", 80); + hints["text_editor/line_length_guideline_column"]=PropertyInfo(Variant::INT,"text_editor/line_length_guideline_column",PROPERTY_HINT_RANGE,"20, 160, 10"); + set("text_editor/trim_trailing_whitespace_on_save", false); set("text_editor/idle_parse_delay",2); set("text_editor/create_signal_callbacks",true); @@ -687,6 +693,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { } void EditorSettings::_load_default_text_editor_theme() { + set("text_editor/background_color",Color::html("3b000000")); set("text_editor/completion_background_color", Color::html("2C2A32")); set("text_editor/completion_selected_color", Color::html("434244")); @@ -710,6 +717,7 @@ void EditorSettings::_load_default_text_editor_theme() { set("text_editor/selection_color",Color::html("7b5dbe")); set("text_editor/brace_mismatch_color",Color(1,0.2,0.2)); set("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15)); + set("text_editor/line_length_guideline_color",Color(0.3,0.5,0.8,0.1)); set("text_editor/mark_color", Color(1.0,0.4,0.4,0.4)); set("text_editor/breakpoint_color", Color(0.8,0.8,0.4,0.2)); set("text_editor/word_highlighted_color",Color(0.8,0.9,0.9,0.15)); @@ -944,6 +952,7 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) { bool EditorSettings::_save_text_editor_theme(String p_file) { String theme_section = "color_theme"; Ref cf = memnew( ConfigFile ); // hex is better? + cf->set_value(theme_section, "background_color", ((Color)get("text_editor/background_color")).to_html()); cf->set_value(theme_section, "completion_background_color", ((Color)get("text_editor/completion_background_color")).to_html()); cf->set_value(theme_section, "completion_selected_color", ((Color)get("text_editor/completion_selected_color")).to_html()); @@ -967,11 +976,13 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { cf->set_value(theme_section, "selection_color", ((Color)get("text_editor/selection_color")).to_html()); cf->set_value(theme_section, "brace_mismatch_color", ((Color)get("text_editor/brace_mismatch_color")).to_html()); cf->set_value(theme_section, "current_line_color", ((Color)get("text_editor/current_line_color")).to_html()); + cf->set_value(theme_section, "line_length_guideline_color", ((Color)get("text_editor/line_length_guideline_color")).to_html()); cf->set_value(theme_section, "mark_color", ((Color)get("text_editor/mark_color")).to_html()); cf->set_value(theme_section, "breakpoint_color", ((Color)get("text_editor/breakpoint_color")).to_html()); cf->set_value(theme_section, "word_highlighted_color", ((Color)get("text_editor/word_highlighted_color")).to_html()); cf->set_value(theme_section, "search_result_color", ((Color)get("text_editor/search_result_color")).to_html()); cf->set_value(theme_section, "search_result_border_color", ((Color)get("text_editor/search_result_border_color")).to_html()); + Error err = cf->save(p_file); if (err == OK) { diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 20534eef5c..51ff4be467 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -2229,19 +2229,9 @@ void ScriptEditor::edit(const Ref