diff options
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r-- | editor/code_editor.cpp | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 16780a795f..e05ace53da 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -277,7 +277,8 @@ void FindReplaceBar::_replace_all() { } text_edit->set_v_scroll(vsval); - set_error(vformat(TTR("Replaced %d occurrence(s)."), rc)); + matches_label->add_color_override("font_color", rc > 0 ? get_color("font_color", "Label") : get_color("error_color", "Editor")); + matches_label->set_text(vformat(TTR("%d replaced."), rc)); text_edit->call_deferred("connect", "text_changed", this, "_editor_text_changed"); results_count = -1; @@ -900,7 +901,7 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/smooth_scrolling")); text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/navigation/show_minimap")); - text_editor->set_minimap_width(EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width")); + text_editor->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width") * EDSCALE); text_editor->set_show_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_bookmark_gutter_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter")); @@ -1182,6 +1183,19 @@ void CodeTextEditor::move_lines_down() { text_editor->update(); } +void CodeTextEditor::_delete_line(int p_line) { + // this is currently intended to be called within delete_lines() + // so `begin_complex_operation` is omitted here + text_editor->set_line(p_line, ""); + if (p_line == 0 && text_editor->get_line_count() > 1) { + text_editor->cursor_set_line(1); + text_editor->cursor_set_column(0); + } + text_editor->backspace_at_cursor(); + text_editor->unfold_line(p_line); + text_editor->cursor_set_line(p_line); +} + void CodeTextEditor::delete_lines() { text_editor->begin_complex_operation(); if (text_editor->is_selection_active()) { @@ -1189,22 +1203,13 @@ void CodeTextEditor::delete_lines() { int from_line = text_editor->get_selection_from_line(); int count = Math::abs(to_line - from_line) + 1; - text_editor->cursor_set_line(to_line, false); - while (count) { - text_editor->set_line(text_editor->cursor_get_line(), ""); - text_editor->backspace_at_cursor(); - count--; - if (count) - text_editor->unfold_line(from_line); + text_editor->cursor_set_line(from_line, false); + for (int i = 0; i < count; i++) { + _delete_line(from_line); } - text_editor->cursor_set_line(from_line - 1); text_editor->deselect(); } else { - int line = text_editor->cursor_get_line(); - text_editor->set_line(text_editor->cursor_get_line(), ""); - text_editor->backspace_at_cursor(); - text_editor->unfold_line(line); - text_editor->cursor_set_line(line); + _delete_line(text_editor->cursor_get_line()); } text_editor->end_complex_operation(); } @@ -1504,6 +1509,10 @@ void CodeTextEditor::_set_show_warnings_panel(bool p_show) { emit_signal("show_warnings_panel", p_show); } +void CodeTextEditor::_toggle_scripts_pressed() { + toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_icon("Back", "EditorIcons") : get_icon("Forward", "EditorIcons")); +} + void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { @@ -1519,6 +1528,9 @@ void CodeTextEditor::_notification(int p_what) { emit_signal("load_theme_settings"); } break; case NOTIFICATION_THEME_CHANGED: { + if (toggle_scripts_button->is_visible()) { + update_toggle_scripts_button(); + } _update_font(); } break; case NOTIFICATION_ENTER_TREE: { @@ -1526,6 +1538,9 @@ void CodeTextEditor::_notification(int p_what) { add_constant_override("separation", 4 * EDSCALE); } break; case NOTIFICATION_VISIBILITY_CHANGED: { + if (toggle_scripts_button->is_visible()) { + update_toggle_scripts_button(); + } set_process_input(is_visible_in_tree()); } break; default: @@ -1559,12 +1574,14 @@ void CodeTextEditor::goto_next_bookmark() { if (line >= bmarks[bmarks.size() - 1]) { text_editor->unfold_line(bmarks[0]); text_editor->cursor_set_line(bmarks[0]); + text_editor->center_viewport_to_cursor(); } else { for (List<int>::Element *E = bmarks.front(); E; E = E->next()) { int bline = E->get(); if (bline > line) { text_editor->unfold_line(bline); text_editor->cursor_set_line(bline); + text_editor->center_viewport_to_cursor(); return; } } @@ -1583,12 +1600,14 @@ void CodeTextEditor::goto_prev_bookmark() { if (line <= bmarks[0]) { text_editor->unfold_line(bmarks[bmarks.size() - 1]); text_editor->cursor_set_line(bmarks[bmarks.size() - 1]); + text_editor->center_viewport_to_cursor(); } else { for (List<int>::Element *E = bmarks.back(); E; E = E->prev()) { int bline = E->get(); if (bline < line) { text_editor->unfold_line(bline); text_editor->cursor_set_line(bline); + text_editor->center_viewport_to_cursor(); return; } } @@ -1617,6 +1636,7 @@ void CodeTextEditor::_bind_methods() { ClassDB::bind_method("_complete_request", &CodeTextEditor::_complete_request); ClassDB::bind_method("_font_resize_timeout", &CodeTextEditor::_font_resize_timeout); ClassDB::bind_method("_error_pressed", &CodeTextEditor::_error_pressed); + ClassDB::bind_method("_toggle_scripts_pressed", &CodeTextEditor::_toggle_scripts_pressed); ClassDB::bind_method("_warning_button_pressed", &CodeTextEditor::_warning_button_pressed); ClassDB::bind_method("_warning_label_gui_input", &CodeTextEditor::_warning_label_gui_input); @@ -1631,6 +1651,15 @@ void CodeTextEditor::set_code_complete_func(CodeTextEditorCodeCompleteFunc p_cod code_complete_ud = p_ud; } +void CodeTextEditor::show_toggle_scripts_button() { + toggle_scripts_button->show(); +} + +void CodeTextEditor::update_toggle_scripts_button() { + toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? get_icon("Back", "EditorIcons") : get_icon("Forward", "EditorIcons")); + toggle_scripts_button->set_tooltip(TTR("Toggle Scripts Panel") + " (" + ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text() + ")"); +} + CodeTextEditor::CodeTextEditor() { code_complete_func = NULL; @@ -1672,6 +1701,11 @@ CodeTextEditor::CodeTextEditor() { error_line = 0; error_column = 0; + toggle_scripts_button = memnew(ToolButton); + toggle_scripts_button->connect("pressed", this, "_toggle_scripts_pressed"); + status_bar->add_child(toggle_scripts_button); + toggle_scripts_button->hide(); + // Error ScrollContainer *scroll = memnew(ScrollContainer); scroll->set_h_size_flags(SIZE_EXPAND_FILL); |