Move ConnectionGutter to editor code_editor

This commit is contained in:
Paulb23 2020-07-29 22:26:49 +01:00
parent 7829fdc1d0
commit d18a90b8f0
5 changed files with 67 additions and 150 deletions

View file

@ -935,7 +935,6 @@ void CodeTextEditor::update_editor_settings() {
text_editor->set_draw_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers"));
text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/appearance/line_numbers_zero_padded"));
text_editor->set_draw_bookmarks_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter"));
text_editor->set_draw_info_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_info_gutter"));
text_editor->set_hiding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding"));
text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding"));
text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap"));

View file

@ -334,6 +334,7 @@ bool ScriptTextEditor::show_members_overview() {
}
void ScriptTextEditor::update_settings() {
code_editor->get_text_editor()->set_gutter_draw(connection_gutter, EditorSettings::get_singleton()->get("text_editor/appearance/show_info_gutter"));
code_editor->update_editor_settings();
}
@ -903,7 +904,14 @@ void ScriptTextEditor::update_toggle_scripts_button() {
void ScriptTextEditor::_update_connected_methods() {
CodeEdit *text_edit = code_editor->get_text_editor();
text_edit->clear_info_icons();
for (int i = 0; i < text_edit->get_line_count(); i++) {
if (text_edit->get_line_gutter_metadata(i, connection_gutter) == "") {
continue;
}
text_edit->set_line_gutter_metadata(i, connection_gutter, "");
text_edit->set_line_gutter_icon(i, connection_gutter, nullptr);
text_edit->set_line_gutter_clickable(i, connection_gutter, false);
}
missing_connections.clear();
if (!script_is_valid) {
@ -943,8 +951,10 @@ void ScriptTextEditor::_update_connected_methods() {
for (int j = 0; j < functions.size(); j++) {
String name = functions[j].get_slice(":", 0);
if (name == connection.callable.get_method()) {
line = functions[j].get_slice(":", 1).to_int();
text_edit->set_line_info_icon(line - 1, get_parent_control()->get_theme_icon("Slot", "EditorIcons"), connection.callable.get_method());
line = functions[j].get_slice(":", 1).to_int() - 1;
text_edit->set_line_gutter_metadata(line, connection_gutter, connection.callable.get_method());
text_edit->set_line_gutter_icon(line, connection_gutter, get_parent_control()->get_theme_icon("Slot", "EditorIcons"));
text_edit->set_line_gutter_clickable(line, connection_gutter, true);
methods_found.insert(connection.callable.get_method());
break;
}
@ -974,14 +984,32 @@ void ScriptTextEditor::_update_connected_methods() {
}
}
void ScriptTextEditor::_lookup_connections(int p_row, String p_method) {
void ScriptTextEditor::_update_gutter_indexes() {
for (int i = 0; i < code_editor->get_text_editor()->get_gutter_count(); i++) {
if (code_editor->get_text_editor()->get_gutter_name(i) == "connection_gutter") {
connection_gutter = i;
break;
}
}
}
void ScriptTextEditor::_gutter_clicked(int p_line, int p_gutter) {
if (p_gutter != connection_gutter) {
return;
}
String method = code_editor->get_text_editor()->get_line_gutter_metadata(p_line, p_gutter);
if (method == "") {
return;
}
Node *base = get_tree()->get_edited_scene_root();
if (!base) {
return;
}
Vector<Node *> nodes = _find_all_node_for_script(base, base, script);
connection_info_dialog->popup_connections(p_method, nodes);
connection_info_dialog->popup_connections(method, nodes);
}
void ScriptTextEditor::_edit_option(int p_op) {
@ -1309,6 +1337,16 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]);
}
void ScriptTextEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_row_height());
} break;
default:
break;
}
}
void ScriptTextEditor::_bind_methods() {
ClassDB::bind_method("_update_connected_methods", &ScriptTextEditor::_update_connected_methods);
@ -1636,7 +1674,9 @@ void ScriptTextEditor::_enable_code_editor() {
code_editor->get_text_editor()->connect("breakpoint_toggled", callable_mp(this, &ScriptTextEditor::_breakpoint_toggled));
code_editor->get_text_editor()->connect("symbol_lookup", callable_mp(this, &ScriptTextEditor::_lookup_symbol));
code_editor->get_text_editor()->connect("symbol_validate", callable_mp(this, &ScriptTextEditor::_validate_symbol));
code_editor->get_text_editor()->connect("info_clicked", callable_mp(this, &ScriptTextEditor::_lookup_connections));
code_editor->get_text_editor()->connect("gutter_added", callable_mp(this, &ScriptTextEditor::_update_gutter_indexes));
code_editor->get_text_editor()->connect("gutter_removed", callable_mp(this, &ScriptTextEditor::_update_gutter_indexes));
code_editor->get_text_editor()->connect("gutter_clicked", callable_mp(this, &ScriptTextEditor::_gutter_clicked));
code_editor->get_text_editor()->connect("gui_input", callable_mp(this, &ScriptTextEditor::_text_edit_gui_input));
code_editor->show_toggle_scripts_button();
@ -1755,6 +1795,13 @@ ScriptTextEditor::ScriptTextEditor() {
code_editor->set_code_complete_func(_code_complete_scripts, this);
code_editor->set_v_size_flags(SIZE_EXPAND_FILL);
connection_gutter = 1;
code_editor->get_text_editor()->add_gutter(connection_gutter);
code_editor->get_text_editor()->set_gutter_name(connection_gutter, "connection_gutter");
code_editor->get_text_editor()->set_gutter_draw(connection_gutter, false);
code_editor->get_text_editor()->set_gutter_overwritable(connection_gutter, true);
code_editor->get_text_editor()->set_gutter_type(connection_gutter, TextEdit::GUTTER_TPYE_ICON);
warnings_panel = memnew(RichTextLabel);
warnings_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
warnings_panel->set_h_size_flags(SIZE_EXPAND_FILL);

View file

@ -81,6 +81,10 @@ class ScriptTextEditor : public ScriptEditorBase {
ScriptEditorQuickOpen *quick_open = nullptr;
ConnectionInfoDialog *connection_info_dialog = nullptr;
int connection_gutter = -1;
void _gutter_clicked(int p_line, int p_gutter);
void _update_gutter_indexes();
PopupPanel *color_panel = nullptr;
ColorPicker *color_picker = nullptr;
Vector2 color_position;
@ -154,6 +158,7 @@ protected:
void _show_warnings_panel(bool p_show);
void _warning_clicked(Variant p_line);
void _notification(int p_what);
static void _bind_methods();
Map<String, Ref<EditorSyntaxHighlighter>> highlighters;
@ -169,8 +174,6 @@ protected:
void _lookup_symbol(const String &p_symbol, int p_row, int p_column);
void _validate_symbol(const String &p_symbol);
void _lookup_connections(int p_row, String p_method);
void _convert_case(CodeTextEditor::CaseStyle p_case);
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);

View file

@ -167,12 +167,6 @@ void TextEdit::Text::clear_wrap_cache() {
}
}
void TextEdit::Text::clear_info_icons() {
for (int i = 0; i < text.size(); i++) {
text.write[i].has_info = false;
}
}
void TextEdit::Text::clear() {
text.clear();
insert(0, "");
@ -204,7 +198,6 @@ void TextEdit::Text::insert(int p_at, const String &p_text) {
line.marked = false;
line.safe = false;
line.hidden = false;
line.has_info = false;
line.width_cache = -1;
line.wrap_amount_cache = -1;
line.data = p_text;
@ -278,10 +271,6 @@ void TextEdit::_update_scrollbars() {
int visible_width = size.width - cache.style_normal->get_minimum_size().width;
int total_width = text.get_max_width(true) + vmin.x + gutters_width + gutter_padding;
if (draw_info_gutter) {
total_width += cache.info_gutter_width;
}
if (draw_minimap) {
total_width += cache.minimap_width;
}
@ -572,13 +561,6 @@ void TextEdit::_notification(int p_what) {
draw_caret = false;
}
if (draw_info_gutter) {
info_gutter_width = (get_row_height());
cache.info_gutter_width = info_gutter_width;
} else {
cache.info_gutter_width = 0;
}
cache.minimap_width = 0;
if (draw_minimap) {
cache.minimap_width = minimap_width;
@ -588,7 +570,7 @@ void TextEdit::_notification(int p_what) {
RID ci = get_canvas_item();
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width + gutter_padding + cache.info_gutter_width;
int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width + gutter_padding;
int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT) - cache.minimap_width;
// Let's do it easy for now.
@ -1082,31 +1064,6 @@ void TextEdit::_notification(int p_what) {
gutter_offset += gutter.width;
}
// Draw info icons.
if (draw_info_gutter && text.has_info_icon(line)) {
int vertical_gap = (get_row_height() * 40) / 100;
int horizontal_gap = (cache.info_gutter_width * 30) / 100;
int gutter_left = cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width;
Ref<Texture2D> info_icon = text.get_info_icon(line);
// Ensure the icon fits the gutter size.
Size2i icon_size = info_icon->get_size();
if (icon_size.width > cache.info_gutter_width - horizontal_gap) {
icon_size.width = cache.info_gutter_width - horizontal_gap;
}
if (icon_size.height > get_row_height() - horizontal_gap) {
icon_size.height = get_row_height() - horizontal_gap;
}
Size2i icon_pos;
int xofs = horizontal_gap - (info_icon->get_width() / 4);
int yofs = vertical_gap - (info_icon->get_height() / 4);
icon_pos.x = gutter_left + xofs + ofs_x;
icon_pos.y = ofs_y + yofs;
draw_texture_rect(info_icon, Rect2(icon_pos, icon_size));
}
}
// Loop through characters in one line.
@ -1783,10 +1740,6 @@ void TextEdit::backspace_at_cursor() {
set_line_as_hidden(prev_line, true);
}
if (text.has_info_icon(cursor.line)) {
set_line_info_icon(prev_line, text.get_info_icon(cursor.line), text.get_info(cursor.line));
}
if (auto_brace_completion_enabled &&
cursor.column > 0 &&
_is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
@ -1974,7 +1927,7 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
row = text.size() - 1;
col = text[row].size();
} else {
int colx = p_mouse.x - (cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width + gutter_padding + cache.info_gutter_width);
int colx = p_mouse.x - (cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width + gutter_padding);
colx += cursor.x_ofs;
col = get_char_pos_for_line(colx, row, wrap_index);
if (is_wrap_enabled() && wrap_index < times_line_wraps(row)) {
@ -2019,7 +1972,7 @@ Vector2i TextEdit::_get_cursor_pixel_pos() {
// Calculate final pixel position
int y = (row - get_v_scroll_offset() + 1 /*Bottom of line*/) * get_row_height();
int x = cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width + gutter_padding + cache.info_gutter_width - cursor.x_ofs;
int x = cache.style_normal->get_margin(MARGIN_LEFT) + gutters_width + gutter_padding - cursor.x_ofs;
int ix = 0;
while (ix < rows2[0].size() && ix < cursor.column) {
if (cache.font != nullptr) {
@ -2168,17 +2121,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
left_margin += gutters[i].width;
}
// Emit info clicked.
if (draw_info_gutter && text.has_info_icon(row)) {
if (mb->get_position().x > left_margin - 6 && mb->get_position().x <= left_margin + cache.info_gutter_width - 3) {
emit_signal("info_clicked", row, text.get_info(row));
return;
}
}
// Unfold on folded icon click.
if (is_folded(row)) {
left_margin += cache.info_gutter_width + gutter_padding + text.get_line_width(row) - cursor.x_ofs;
left_margin += gutter_padding + text.get_line_width(row) - cursor.x_ofs;
if (mb->get_position().x > left_margin && mb->get_position().x <= left_margin + cache.folded_eol_icon->get_width() + 3) {
unfold_line(row);
return;
@ -3768,12 +3713,8 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
if (shift_first_line) {
text.move_gutters(p_line, p_line + 1);
text.set_hidden(p_line + 1, text.is_hidden(p_line));
if (text.has_info_icon(p_line)) {
text.set_info_icon(p_line + 1, text.get_info_icon(p_line), text.get_info(p_line));
}
text.set_hidden(p_line, false);
text.set_info_icon(p_line, nullptr, "");
}
text.set_line_wrap_amount(p_line, -1);
@ -4031,7 +3972,7 @@ int TextEdit::get_total_visible_rows() const {
}
void TextEdit::_update_wrap_at() {
wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.info_gutter_width - cache.minimap_width - wrap_right_offset;
wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.minimap_width - wrap_right_offset;
update_cursor_wrap_offset();
text.clear_wrap_cache();
@ -4066,7 +4007,7 @@ void TextEdit::adjust_viewport_to_cursor() {
set_line_as_last_visible(cur_line, cur_wrap);
}
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.info_gutter_width - cache.minimap_width;
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.minimap_width;
if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
}
@ -4101,7 +4042,7 @@ void TextEdit::center_viewport_to_cursor() {
}
set_line_as_center_visible(cursor.line, get_cursor_wrap_index());
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.info_gutter_width - cache.minimap_width;
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.minimap_width;
if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
}
@ -4556,7 +4497,7 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
_get_mouse_pos(p_pos, row, col);
int left_margin = cache.style_normal->get_margin(MARGIN_LEFT);
int gutter = left_margin + gutters_width + cache.info_gutter_width;
int gutter = left_margin + gutters_width;
if (p_pos.x < gutter) {
for (int i = 0; i < gutters.size(); i++) {
if (!gutters[i].draw) {
@ -4570,15 +4511,6 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
}
left_margin += gutters[i].width;
}
// Info icons.
if (draw_info_gutter && p_pos.x > left_margin - 6 && p_pos.x <= left_margin + cache.info_gutter_width - 3) {
if (text.has_info_icon(row)) {
return CURSOR_POINTING_HAND;
}
return CURSOR_ARROW;
}
return CURSOR_ARROW;
}
@ -5457,17 +5389,6 @@ bool TextEdit::is_line_set_as_safe(int p_line) const {
return text.is_safe(p_line);
}
void TextEdit::set_line_info_icon(int p_line, Ref<Texture2D> p_icon, String p_info) {
ERR_FAIL_INDEX(p_line, text.size());
text.set_info_icon(p_line, p_icon, p_info);
update();
}
void TextEdit::clear_info_icons() {
text.clear_info_icons();
update();
}
void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
ERR_FAIL_INDEX(p_line, text.size());
if (is_hiding_enabled() || !p_hidden) {
@ -6544,24 +6465,6 @@ void TextEdit::set_line_length_guideline_hard_column(int p_column) {
update();
}
void TextEdit::set_draw_info_gutter(bool p_draw) {
draw_info_gutter = p_draw;
update();
}
bool TextEdit::is_drawing_info_gutter() const {
return draw_info_gutter;
}
void TextEdit::set_info_gutter_width(int p_gutter_width) {
info_gutter_width = p_gutter_width;
update();
}
int TextEdit::get_info_gutter_width() const {
return info_gutter_width;
}
void TextEdit::set_draw_minimap(bool p_draw) {
draw_minimap = p_draw;
update();
@ -6886,7 +6789,6 @@ void TextEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("gutter_added"));
ADD_SIGNAL(MethodInfo("gutter_removed"));
ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::INT, "column")));
ADD_SIGNAL(MethodInfo("info_clicked", PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::STRING, "info")));
ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol")));
BIND_ENUM_CONSTANT(MENU_CUT);
@ -6919,8 +6821,6 @@ TextEdit::TextEdit() {
_update_caches();
cache.row_height = 1;
cache.line_spacing = 1;
info_gutter_width = 0;
cache.info_gutter_width = 0;
set_default_cursor_shape(CURSOR_IBEAM);
indent_size = 4;
@ -6987,7 +6887,6 @@ TextEdit::TextEdit() {
line_length_guidelines = false;
line_length_guideline_soft_col = 80;
line_length_guideline_hard_col = 100;
draw_info_gutter = false;
hiding_enabled = false;
next_operation_is_complex = false;
scroll_past_end_of_file_enabled = false;

View file

@ -83,17 +83,13 @@ private:
bool marked : 1;
bool hidden : 1;
bool safe : 1;
bool has_info : 1;
int wrap_amount_cache : 24;
Ref<Texture2D> info_icon;
String info;
String data;
Line() {
width_cache = 0;
marked = false;
hidden = false;
safe = false;
has_info = false;
wrap_amount_cache = 0;
}
};
@ -121,25 +117,12 @@ private:
bool is_hidden(int p_line) const { return text[p_line].hidden; }
void set_safe(int p_line, bool p_safe) { text.write[p_line].safe = p_safe; }
bool is_safe(int p_line) const { return text[p_line].safe; }
void set_info_icon(int p_line, Ref<Texture2D> p_icon, String p_info) {
if (p_icon.is_null()) {
text.write[p_line].has_info = false;
return;
}
text.write[p_line].info_icon = p_icon;
text.write[p_line].info = p_info;
text.write[p_line].has_info = true;
}
bool has_info_icon(int p_line) const { return text[p_line].has_info; }
const Ref<Texture2D> &get_info_icon(int p_line) const { return text[p_line].info_icon; }
const String &get_info(int p_line) const { return text[p_line].info; }
void insert(int p_at, const String &p_text);
void remove(int p_at);
int size() const { return text.size(); }
void clear();
void clear_width_cache();
void clear_wrap_cache();
void clear_info_icons();
_FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; }
/* Gutters. */
@ -314,8 +297,6 @@ private:
int line_length_guideline_soft_col;
int line_length_guideline_hard_col;
bool hiding_enabled;
bool draw_info_gutter;
int info_gutter_width;
bool draw_minimap;
int minimap_width;
Point2 minimap_char_size;
@ -429,8 +410,6 @@ private:
Size2 get_minimum_size() const override;
int _get_control_height() const;
int get_row_height() const;
void _reset_caret_blink_timer();
void _toggle_draw_caret();
@ -493,12 +472,10 @@ protected:
int row_height;
int line_spacing;
int info_gutter_width;
int minimap_width;
Cache() {
row_height = 0;
line_spacing = 0;
info_gutter_width = 0;
minimap_width = 0;
}
} cache;
@ -602,9 +579,6 @@ public:
void set_line_as_safe(int p_line, bool p_safe);
bool is_line_set_as_safe(int p_line) const;
void set_line_info_icon(int p_line, Ref<Texture2D> p_icon, String p_info = "");
void clear_info_icons();
void set_line_as_hidden(int p_line, bool p_hidden);
bool is_line_hidden(int p_line) const;
void fold_all_lines();
@ -623,6 +597,7 @@ public:
String get_text();
String get_line(int line) const;
void set_line(int line, String new_text);
int get_row_height() const;
void backspace_at_cursor();
void indent_left();
@ -751,12 +726,6 @@ public:
void set_line_length_guideline_soft_column(int p_column);
void set_line_length_guideline_hard_column(int p_column);
void set_draw_info_gutter(bool p_draw);
bool is_drawing_info_gutter() const;
void set_info_gutter_width(int p_gutter_width);
int get_info_gutter_width() const;
void set_draw_minimap(bool p_draw);
bool is_drawing_minimap() const;