Clean up and complete CodeEdit inspector and docs

This commit is contained in:
Paulb23 2021-07-01 17:40:59 +01:00
parent dd5a37f556
commit 809a32c045
6 changed files with 117 additions and 64 deletions

View file

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="CodeEdit" inherits="TextEdit" version="4.0">
<brief_description>
Multiline text control intended for editing code.
</brief_description>
<description>
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.
</description>
<tutorials>
@ -31,12 +33,9 @@
</description>
</method>
<method name="add_auto_brace_completion_pair">
<return type="void">
</return>
<argument index="0" name="start_key" type="String">
</argument>
<argument index="1" name="end_key" type="String">
</argument>
<return type="void" />
<argument index="0" name="start_key" type="String" />
<argument index="1" name="end_key" type="String" />
<description>
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 @@
<method name="clear_bookmarked_lines">
<return type="void" />
<description>
Clears all bookmarked lines.
</description>
</method>
<method name="clear_breakpointed_lines">
<return type="void" />
<description>
Clears all breakpointed lines.
</description>
</method>
<method name="clear_comment_delimiters">
@ -109,6 +110,7 @@
<method name="clear_executing_lines">
<return type="void" />
<description>
Clears all executed lines.
</description>
</method>
<method name="clear_string_delimiters">
@ -150,10 +152,8 @@
</description>
</method>
<method name="get_auto_brace_completion_close_key" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="open_key" type="String">
</argument>
<return type="String" />
<argument index="0" name="open_key" type="String" />
<description>
Gets the matching auto brace close key for [code]open_key[/code].
</description>
@ -161,11 +161,13 @@
<method name="get_bookmarked_lines" qualifiers="const">
<return type="Array" />
<description>
Gets all bookmarked lines.
</description>
</method>
<method name="get_breakpointed_lines" qualifiers="const">
<return type="Array" />
<description>
Gets all breakpointed lines.
</description>
</method>
<method name="get_code_completion_option" qualifiers="const">
@ -226,6 +228,7 @@
<method name="get_executing_lines" qualifiers="const">
<return type="Array" />
<description>
Gets all executing lines.
</description>
</method>
<method name="get_folded_lines" qualifiers="const">
@ -241,26 +244,21 @@
</description>
</method>
<method name="get_text_for_symbol_lookup">
<return type="String">
</return>
<return type="String" />
<description>
Returns the full text with char [code]0xFFFF[/code] at the cursor location.
</description>
</method>
<method name="has_auto_brace_completion_close_key" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="close_key" type="String">
</argument>
<return type="bool" />
<argument index="0" name="close_key" type="String" />
<description>
Returns [code]true[/code] if close key [code]close_key[/code] exists.
</description>
</method>
<method name="has_auto_brace_completion_open_key" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="open_key" type="String">
</argument>
<return type="bool" />
<argument index="0" name="open_key" type="String" />
<description>
Returns [code]true[/code] if open key [code]open_key[/code] exists.
</description>
@ -305,18 +303,21 @@
<return type="bool" />
<argument index="0" name="line" type="int" />
<description>
Returns whether the line at the specified index is bookmarked or not.
</description>
</method>
<method name="is_line_breakpointed" qualifiers="const">
<return type="bool" />
<argument index="0" name="line" type="int" />
<description>
Returns whether the line at the specified index is breakpointed or not.
</description>
</method>
<method name="is_line_executing" qualifiers="const">
<return type="bool" />
<argument index="0" name="line" type="int" />
<description>
Returns whether the line at the specified index is marked as executing or not.
</description>
</method>
<method name="is_line_folded" qualifiers="const">
@ -373,6 +374,7 @@
<argument index="0" name="line" type="int" />
<argument index="1" name="bookmarked" type="bool" />
<description>
Sets the line as bookmarked.
</description>
</method>
<method name="set_line_as_breakpoint">
@ -380,6 +382,7 @@
<argument index="0" name="line" type="int" />
<argument index="1" name="breakpointed" type="bool" />
<description>
Sets the line as breakpointed.
</description>
</method>
<method name="set_line_as_executing">
@ -387,13 +390,12 @@
<argument index="0" name="line" type="int" />
<argument index="1" name="executing" type="bool" />
<description>
Sets the line as executing.
</description>
</method>
<method name="set_symbol_lookup_word_as_valid">
<return type="void">
</return>
<argument index="0" name="valid" type="bool">
</argument>
<return type="void" />
<argument index="0" name="valid" type="bool" />
<description>
Sets the symbol emitted by [signal symbol_validate] as a valid lookup.
</description>
@ -408,6 +410,7 @@
<method name="unfold_all_lines">
<return type="void" />
<description>
Unfolds all lines, folded or not.
</description>
</method>
<method name="unfold_line">
@ -451,18 +454,26 @@
<member name="delimiter_comments" type="String[]" setter="set_comment_delimiters" getter="get_comment_delimiters" default="[]">
Sets the comment delimiters. All existing comment delimiters will be removed.
</member>
<member name="delimiter_strings" type="String[]" setter="set_string_delimiters" getter="get_string_delimiters" default="[]">
<member name="delimiter_strings" type="String[]" setter="set_string_delimiters" getter="get_string_delimiters" default="[&quot;&apos; &apos;&quot;, &quot;\&quot; \&quot;&quot;]">
Sets the string delimiters. All existing string delimiters will be removed.
</member>
<member name="draw_bookmarks" type="bool" setter="set_draw_bookmarks_gutter" getter="is_drawing_bookmarks_gutter" default="false">
<member name="gutters_draw_bookmarks" type="bool" setter="set_draw_bookmarks_gutter" getter="is_drawing_bookmarks_gutter" default="false">
Sets if bookmarked should be drawn in the gutter. This gutter is shared with breakpoints and executing lines.
</member>
<member name="draw_breakpoints_gutter" type="bool" setter="set_draw_breakpoints_gutter" getter="is_drawing_breakpoints_gutter" default="false">
<member name="gutters_draw_breakpoints_gutter" type="bool" setter="set_draw_breakpoints_gutter" getter="is_drawing_breakpoints_gutter" default="false">
Sets if breakpoints should be drawn in the gutter. This gutter is shared with bookmarks and executing lines.
</member>
<member name="draw_executing_lines" type="bool" setter="set_draw_executing_lines_gutter" getter="is_drawing_executing_lines_gutter" default="false">
<member name="gutters_draw_executing_lines" type="bool" setter="set_draw_executing_lines_gutter" getter="is_drawing_executing_lines_gutter" default="false">
Sets if executing lines should be marked in the gutter. This gutter is shared with breakpoints and bookmarks lines.
</member>
<member name="draw_fold_gutter" type="bool" setter="set_draw_fold_gutter" getter="is_drawing_fold_gutter" default="false">
<member name="gutters_draw_fold_gutter" type="bool" setter="set_draw_fold_gutter" getter="is_drawing_fold_gutter" default="false">
Sets if foldable lines icons should be drawn in the gutter.
</member>
<member name="draw_line_numbers" type="bool" setter="set_draw_line_numbers" getter="is_draw_line_numbers_enabled" default="false">
<member name="gutters_draw_line_numbers" type="bool" setter="set_draw_line_numbers" getter="is_draw_line_numbers_enabled" default="false">
Sets if line numbers should be drawn in the gutter.
</member>
<member name="gutters_zero_pad_line_numbers" type="bool" setter="set_line_numbers_zero_padded" getter="is_line_numbers_zero_padded" default="false">
Sets if line numbers drawn in the gutter are zero padded.
</member>
<member name="indent_automatic" type="bool" setter="set_auto_indent_enabled" getter="is_auto_indent_enabled" default="false">
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.
</member>
<member name="layout_direction" type="int" setter="set_layout_direction" getter="get_layout_direction" override="true" enum="Control.LayoutDirection" default="2" />
<member name="line_folding" type="bool" setter="set_line_folding_enabled" getter="is_line_folding_enabled" default="true">
<member name="line_folding" type="bool" setter="set_line_folding_enabled" getter="is_line_folding_enabled" default="false">
Sets whether line folding is allowed.
</member>
<member name="line_length_guidelines" type="int[]" setter="set_line_length_guidelines" getter="get_line_length_guidelines" default="[]">
Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently
</member>
<member name="structured_text_bidi_override_options" type="Array" setter="set_structured_text_bidi_override_options" getter="get_structured_text_bidi_override_options" override="true" default="[]" />
<member name="symbol_lookup_on_click" type="bool" setter="set_symbol_lookup_on_click_enabled" getter="is_symbol_lookup_on_click_enabled" default="false">
Set when a validated word from [signal symbol_validate] is clicked, the [signal symbol_lookup] should be emitted.
</member>
<member name="text_direction" type="int" setter="set_text_direction" getter="get_text_direction" override="true" enum="Control.TextDirection" default="1" />
<member name="zero_pad_line_numbers" type="bool" setter="set_line_numbers_zero_padded" getter="is_line_numbers_zero_padded" default="false">
</member>
</members>
<signals>
<signal name="breakpoint_toggled">
<argument index="0" name="line" type="int" />
<description>
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.
</description>
</signal>
<signal name="request_code_completion">
@ -502,19 +513,15 @@
</description>
</signal>
<signal name="symbol_lookup">
<argument index="0" name="symbol" type="String">
</argument>
<argument index="1" name="line" type="int">
</argument>
<argument index="2" name="column" type="int">
</argument>
<argument index="0" name="symbol" type="String" />
<argument index="1" name="line" type="int" />
<argument index="2" name="column" type="int" />
<description>
Emitted when the user has clicked on a valid symbol.
</description>
</signal>
<signal name="symbol_validate">
<argument index="0" name="symbol" type="String">
</argument>
<argument index="0" name="symbol" type="String" />
<description>
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].
</description>
@ -522,114 +529,159 @@
</signals>
<constants>
<constant name="KIND_CLASS" value="0" enum="CodeCompletionKind">
Marks the option as a class.
</constant>
<constant name="KIND_FUNCTION" value="1" enum="CodeCompletionKind">
Marks the option as a function.
</constant>
<constant name="KIND_SIGNAL" value="2" enum="CodeCompletionKind">
Marks the option as a Godot signal.
</constant>
<constant name="KIND_VARIABLE" value="3" enum="CodeCompletionKind">
Marks the option as a variable.
</constant>
<constant name="KIND_MEMBER" value="4" enum="CodeCompletionKind">
Marks the option as a member.
</constant>
<constant name="KIND_ENUM" value="5" enum="CodeCompletionKind">
Marks the option as a enum entry.
</constant>
<constant name="KIND_CONSTANT" value="6" enum="CodeCompletionKind">
Marks the option as a constant.
</constant>
<constant name="KIND_NODE_PATH" value="7" enum="CodeCompletionKind">
Marks the option as a Godot node path.
</constant>
<constant name="KIND_FILE_PATH" value="8" enum="CodeCompletionKind">
Marks the option as a file path.
</constant>
<constant name="KIND_PLAIN_TEXT" value="9" enum="CodeCompletionKind">
Marks the option as unclassified or plain text.
</constant>
</constants>
<theme_items>
<theme_item name="background_color" type="Color" default="Color(0, 0, 0, 0)">
Sets the background [Color].
</theme_item>
<theme_item name="bookmark" type="Texture2D">
Sets a custom [Texture2D] to draw in the bookmark gutter for bookmarked lines.
</theme_item>
<theme_item name="bookmark_color" type="Color" default="Color(0.5, 0.64, 1, 0.8)">
[Color] of the bookmark icon for bookmarked lines.
</theme_item>
<theme_item name="brace_mismatch_color" type="Color" default="Color(1, 0.2, 0.2, 1)">
[Color] of the text to highlight mismatched braces.
</theme_item>
<theme_item name="breakpoint" type="Texture2D">
Sets a custom [Texture2D] to draw in the breakpoint gutter for breakpointed lines.
</theme_item>
<theme_item name="breakpoint_color" type="Color" default="Color(0.9, 0.29, 0.3, 1)">
[Color] of the breakpoint icon for bookmarked lines.
</theme_item>
<theme_item name="can_fold" type="Texture2D">
Sets a custom [Texture2D] to draw in the line folding gutter when a line can be folded.
</theme_item>
<theme_item name="caret_background_color" type="Color" default="Color(0, 0, 0, 1)">
[Color] of the text behind the caret when block caret is enabled.
</theme_item>
<theme_item name="caret_color" type="Color" default="Color(0.88, 0.88, 0.88, 1)">
[Color] of the caret.
</theme_item>
<theme_item name="code_folding_color" type="Color" default="Color(0.8, 0.8, 0.8, 0.8)">
[Color] for all icons related to line folding.
</theme_item>
<theme_item name="completion" type="StyleBox">
[StyleBox] for the code completion popup.
</theme_item>
<theme_item name="completion_background_color" type="Color" default="Color(0.17, 0.16, 0.2, 1)">
Sets the background [Color] for the code completion popup.
</theme_item>
<theme_item name="completion_existing_color" type="Color" default="Color(0.87, 0.87, 0.87, 0.13)">
Background highlight [Color] for matching text in code completion options.
</theme_item>
<theme_item name="completion_font_color" type="Color" default="Color(0.67, 0.67, 0.67, 1)">
Font [Color] for the code completion popup.
</theme_item>
<theme_item name="completion_lines" type="int" default="7">
Max number of options to display in the code completion popup at any one time.
</theme_item>
<theme_item name="completion_max_width" type="int" default="50">
Max width of options in the code completion popup. Options longer then this will be cut off.
</theme_item>
<theme_item name="completion_scroll_color" type="Color" default="Color(1, 1, 1, 1)">
[Color] of the scrollbar in the code completion popup.
</theme_item>
<theme_item name="completion_scroll_width" type="int" default="3">
Width of the scrollbar in the code completion popup.
</theme_item>
<theme_item name="completion_selected_color" type="Color" default="Color(0.26, 0.26, 0.27, 1)">
Background highlight [Color] for the current selected option item in the code completion popup.
</theme_item>
<theme_item name="current_line_color" type="Color" default="Color(0.25, 0.25, 0.26, 0.8)">
Background [Color] of the line containing the caret.
</theme_item>
<theme_item name="executing_line" type="Texture2D">
Icon to draw in the executing gutter for executing lines.
</theme_item>
<theme_item name="executing_line_color" type="Color" default="Color(0.98, 0.89, 0.27, 1)">
[Color] of the executing icon for executing lines.
</theme_item>
<theme_item name="focus" type="StyleBox">
Sets the [StyleBox] when in focus.
</theme_item>
<theme_item name="folded" type="Texture2D">
Sets a custom [Texture2D] to draw in the line folding gutter when a line is folded and can be unfolded.
</theme_item>
<theme_item name="folded_eol_icon" type="Texture2D">
Sets a custom [Texture2D] to draw at the end of a folded line.
</theme_item>
<theme_item name="font" type="Font">
Sets the default [Font].
</theme_item>
<theme_item name="font_color" type="Color" default="Color(0.88, 0.88, 0.88, 1)">
Sets the font [Color].
</theme_item>
<theme_item name="font_outline_color" type="Color" default="Color(1, 1, 1, 1)">
The tint of text outline of the [CodeEdit].
</theme_item>
<theme_item name="font_readonly_color" type="Color" default="Color(0.88, 0.88, 0.88, 0.5)">
Sets the font [Color] when [member readonly] is enabled.
</theme_item>
<theme_item name="font_selected_color" type="Color" default="Color(0, 0, 0, 1)">
Sets the [Color] of the selected text. [member override_selected_font_color] has to be enabled.
</theme_item>
<theme_item name="font_size" type="int">
Font size of the [CodeEdit]'s text.
Sets default font size.
</theme_item>
<theme_item name="line_length_guideline_color" type="Color" default="Color(0.3, 0.5, 0.8, 0.1)">
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.
</theme_item>
<theme_item name="line_number_color" type="Color" default="Color(0.67, 0.67, 0.67, 0.4)">
Sets the [Color] of line numbers.
</theme_item>
<theme_item name="line_spacing" type="int" default="4">
Sets the spacing between the lines.
</theme_item>
<theme_item name="normal" type="StyleBox">
Sets the [StyleBox].
</theme_item>
<theme_item name="outline_size" type="int" default="0">
The size of the text outline.
</theme_item>
<theme_item name="read_only" type="StyleBox">
</theme_item>
<theme_item name="safe_line_number_color" type="Color" default="Color(0.67, 0.78, 0.67, 0.6)">
Sets the [StyleBox] when [member readonly] is enabled.
</theme_item>
<theme_item name="selection_color" type="Color" default="Color(0.49, 0.49, 0.49, 1)">
Sets the highlight [Color] of text selections.
</theme_item>
<theme_item name="space" type="Texture2D">
Sets a custom [Texture2D] for space text characters.
</theme_item>
<theme_item name="tab" type="Texture2D">
Sets a custom [Texture2D] for tab text characters.
</theme_item>
<theme_item name="word_highlighted_color" type="Color" default="Color(0.8, 0.9, 0.9, 0.15)">
Sets the highlight [Color] of multiple occurrences. [member highlight_all_occurrences] has to be enabled.
</theme_item>
</theme_items>
</class>

View file

@ -17,10 +17,8 @@
</description>
</method>
<method name="_handle_unicode_input" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="unicode" type="int">
</argument>
<return type="void" />
<argument index="0" name="unicode" type="int" />
<description>
</description>
</method>
@ -265,8 +263,7 @@
</description>
</method>
<method name="get_total_gutter_width" qualifiers="const">
<return type="int">
</return>
<return type="int" />
<description>
</description>
</method>
@ -296,8 +293,7 @@
</description>
</method>
<method name="is_dragging_cursor" qualifiers="const">
<return type="bool">
</return>
<return type="bool" />
<description>
</description>
</method>

View file

@ -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);

View file

@ -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);

View file

@ -125,7 +125,7 @@ private:
void _update_gutter_indexes();
/* Line Folding */
bool line_folding_enabled = true;
bool line_folding_enabled = false;
/* Delimiters */
enum DelimiterType {

View file

@ -501,7 +501,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &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));