From 809a32c045e62280e89e9c4513d98f3c006f7be5 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Thu, 1 Jul 2021 17:40:59 +0100 Subject: [PATCH] Clean up and complete CodeEdit inspector and docs --- doc/classes/CodeEdit.xml | 142 ++++++++++++------ doc/classes/TextEdit.xml | 12 +- editor/plugins/script_text_editor.cpp | 4 +- scene/gui/code_edit.cpp | 20 ++- scene/gui/code_edit.h | 2 +- .../resources/default_theme/default_theme.cpp | 1 - 6 files changed, 117 insertions(+), 64 deletions(-) diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index d22ba65421..0b060ec277 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -1,8 +1,10 @@ + Multiline text control intended for editing code. + CodeEdit is a specialised [TextEdit] designed for editing plain text code files. It contains a bunch of features commonly found in code editors such as line numbers, line folding, code completion, indent management and string / comment management. [b]Note[/b]: By default [CodeEdit] always use left-to-right text direction to correctly display source code. @@ -31,12 +33,9 @@ - - - - - - + + + Adds a brace pair. Both the start and end keys must be symbols. Only the start key has to be unique. @@ -93,11 +92,13 @@ + Clears all bookmarked lines. + Clears all breakpointed lines. @@ -109,6 +110,7 @@ + Clears all executed lines. @@ -150,10 +152,8 @@ - - - - + + Gets the matching auto brace close key for [code]open_key[/code]. @@ -161,11 +161,13 @@ + Gets all bookmarked lines. + Gets all breakpointed lines. @@ -226,6 +228,7 @@ + Gets all executing lines. @@ -241,26 +244,21 @@ - - + Returns the full text with char [code]0xFFFF[/code] at the cursor location. - - - - + + Returns [code]true[/code] if close key [code]close_key[/code] exists. - - - - + + Returns [code]true[/code] if open key [code]open_key[/code] exists. @@ -305,18 +303,21 @@ + Returns whether the line at the specified index is bookmarked or not. + Returns whether the line at the specified index is breakpointed or not. + Returns whether the line at the specified index is marked as executing or not. @@ -373,6 +374,7 @@ + Sets the line as bookmarked. @@ -380,6 +382,7 @@ + Sets the line as breakpointed. @@ -387,13 +390,12 @@ + Sets the line as executing. - - - - + + Sets the symbol emitted by [signal symbol_validate] as a valid lookup. @@ -408,6 +410,7 @@ + Unfolds all lines, folded or not. @@ -451,18 +454,26 @@ Sets the comment delimiters. All existing comment delimiters will be removed. - + Sets the string delimiters. All existing string delimiters will be removed. - + + Sets if bookmarked should be drawn in the gutter. This gutter is shared with breakpoints and executing lines. - + + Sets if breakpoints should be drawn in the gutter. This gutter is shared with bookmarks and executing lines. - + + Sets if executing lines should be marked in the gutter. This gutter is shared with breakpoints and bookmarks lines. - + + Sets if foldable lines icons should be drawn in the gutter. - + + Sets if line numbers should be drawn in the gutter. + + + Sets if line numbers drawn in the gutter are zero padded. Sets whether automatic indent are enabled, this will add an extra indent if a prefix or brace is found. @@ -477,23 +488,23 @@ Use spaces instead of tabs for indentation. - + Sets whether line folding is allowed. + Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently Set when a validated word from [signal symbol_validate] is clicked, the [signal symbol_lookup] should be emitted. - - + Emitted when a breakpoint is added or removed from a line. If the line is moved via backspace a removed is emitted at the old line. @@ -502,19 +513,15 @@ - - - - - - + + + Emitted when the user has clicked on a valid symbol. - - + Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by calling [method set_symbol_lookup_word_as_valid]. @@ -522,114 +529,159 @@ + Marks the option as a class. + Marks the option as a function. + Marks the option as a Godot signal. + Marks the option as a variable. + Marks the option as a member. + Marks the option as a enum entry. + Marks the option as a constant. + Marks the option as a Godot node path. + Marks the option as a file path. + Marks the option as unclassified or plain text. + Sets the background [Color]. + Sets a custom [Texture2D] to draw in the bookmark gutter for bookmarked lines. + [Color] of the bookmark icon for bookmarked lines. + [Color] of the text to highlight mismatched braces. + Sets a custom [Texture2D] to draw in the breakpoint gutter for breakpointed lines. + [Color] of the breakpoint icon for bookmarked lines. + Sets a custom [Texture2D] to draw in the line folding gutter when a line can be folded. + [Color] of the text behind the caret when block caret is enabled. + [Color] of the caret. + [Color] for all icons related to line folding. + [StyleBox] for the code completion popup. + Sets the background [Color] for the code completion popup. + Background highlight [Color] for matching text in code completion options. + Font [Color] for the code completion popup. + Max number of options to display in the code completion popup at any one time. + Max width of options in the code completion popup. Options longer then this will be cut off. + [Color] of the scrollbar in the code completion popup. + Width of the scrollbar in the code completion popup. + Background highlight [Color] for the current selected option item in the code completion popup. + Background [Color] of the line containing the caret. + Icon to draw in the executing gutter for executing lines. + [Color] of the executing icon for executing lines. + Sets the [StyleBox] when in focus. + Sets a custom [Texture2D] to draw in the line folding gutter when a line is folded and can be unfolded. + Sets a custom [Texture2D] to draw at the end of a folded line. + Sets the default [Font]. + Sets the font [Color]. The tint of text outline of the [CodeEdit]. + Sets the font [Color] when [member readonly] is enabled. + Sets the [Color] of the selected text. [member override_selected_font_color] has to be enabled. - Font size of the [CodeEdit]'s text. + Sets default font size. - Color of the main line length guideline, secondary guidelines will have 50% alpha applied. + [Color] of the main line length guideline, secondary guidelines will have 50% alpha applied. + Sets the [Color] of line numbers. + Sets the spacing between the lines. + Sets the [StyleBox]. The size of the text outline. - - + Sets the [StyleBox] when [member readonly] is enabled. + Sets the highlight [Color] of text selections. + Sets a custom [Texture2D] for space text characters. + Sets a custom [Texture2D] for tab text characters. + Sets the highlight [Color] of multiple occurrences. [member highlight_all_occurrences] has to be enabled. diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 62c33e9436..5d62050a94 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -17,10 +17,8 @@ - - - - + + @@ -265,8 +263,7 @@ - - + @@ -296,8 +293,7 @@ - - + diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 6670206647..5bbe56a800 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -204,7 +204,9 @@ void ScriptTextEditor::_set_theme_for_script() { for (const String &string : strings) { String beg = string.get_slice(" ", 0); String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); - text_edit->add_string_delimiter(beg, end, end == ""); + if (!text_edit->has_string_delimiter(beg)) { + text_edit->add_string_delimiter(beg, end, end == ""); + } if (!end.is_empty() && !text_edit->has_auto_brace_completion_open_key(beg)) { text_edit->add_auto_brace_completion_pair(beg, end); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index d76597b1c9..45d74c631a 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2173,21 +2173,21 @@ void CodeEdit::_bind_methods() { /* Inspector */ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "symbol_lookup_on_click"), "set_symbol_lookup_on_click_enabled", "is_symbol_lookup_on_click_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "line_folding"), "set_line_folding_enabled", "is_line_folding_enabled"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "line_length_guidelines"), "set_line_length_guidelines", "get_line_length_guidelines"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter"); + ADD_GROUP("Gutters", "gutters_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_executing_lines"), "set_draw_executing_lines_gutter", "is_drawing_executing_lines_gutter"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_executing_lines"), "set_draw_executing_lines_gutter", "is_drawing_executing_lines_gutter"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_line_numbers"), "set_draw_line_numbers", "is_draw_line_numbers_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "zero_pad_line_numbers"), "set_line_numbers_zero_padded", "is_line_numbers_zero_padded"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_line_numbers"), "set_draw_line_numbers", "is_draw_line_numbers_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_zero_pad_line_numbers"), "set_line_numbers_zero_padded", "is_line_numbers_zero_padded"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_fold_gutter"), "set_draw_fold_gutter", "is_drawing_fold_gutter"); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "line_folding"), "set_line_folding_enabled", "is_line_folding_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_fold_gutter"), "set_draw_fold_gutter", "is_drawing_fold_gutter"); ADD_GROUP("Delimiters", "delimiter_"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "delimiter_strings"), "set_string_delimiters", "get_string_delimiters"); @@ -2902,6 +2902,10 @@ CodeEdit::CodeEdit() { add_auto_brace_completion_pair("\"", "\""); add_auto_brace_completion_pair("\'", "\'"); + /* Delimiter traking */ + add_string_delimiter("\"", "\"", false); + add_string_delimiter("\'", "\'", false); + /* Text Direction */ set_layout_direction(LAYOUT_DIRECTION_LTR); set_text_direction(TEXT_DIRECTION_LTR); diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index efd778ffb3..72fdc6e787 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -125,7 +125,7 @@ private: void _update_gutter_indexes(); /* Line Folding */ - bool line_folding_enabled = true; + bool line_folding_enabled = false; /* Delimiters */ enum DelimiterType { diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index ad589d94d6..d0dee2b5e3 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -501,7 +501,6 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_color("caret_background_color", "CodeEdit", Color(0, 0, 0)); theme->set_color("brace_mismatch_color", "CodeEdit", Color(1, 0.2, 0.2)); theme->set_color("line_number_color", "CodeEdit", Color(0.67, 0.67, 0.67, 0.4)); - theme->set_color("safe_line_number_color", "CodeEdit", Color(0.67, 0.78, 0.67, 0.6)); theme->set_color("word_highlighted_color", "CodeEdit", Color(0.8, 0.9, 0.9, 0.15)); theme->set_color("line_length_guideline_color", "CodeEdit", Color(0.3, 0.5, 0.8, 0.1));