summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-18 17:40:59 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-18 17:40:59 +0200
commit7b1d169e0e096d5afb7e7359236ef4cb1fb8accc (patch)
tree63ad23a52b7b7d21693acd953f694832e9e3ad09
parent804d9775b55c566950d74331ec3bedfdb9255206 (diff)
parent86762f0a03206998bddc539a80c438c2da5068ce (diff)
downloadredot-engine-7b1d169e0e096d5afb7e7359236ef4cb1fb8accc.tar.gz
Merge pull request #96683 from elliotfontaine/toggle-replace-button
Code Editor: Add button to toggle between search and search+replace
-rw-r--r--editor/code_editor.cpp22
-rw-r--r--editor/code_editor.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index dd8aa523c4..59783c58b5 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -108,6 +108,7 @@ void FindReplaceBar::_notification(int p_what) {
hide_button->set_texture_hover(get_editor_theme_icon(SNAME("Close")));
hide_button->set_texture_pressed(get_editor_theme_icon(SNAME("Close")));
hide_button->set_custom_minimum_size(hide_button->get_texture_normal()->get_size());
+ _update_toggle_replace_button(replace_text->is_visible_in_tree());
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -539,6 +540,14 @@ void FindReplaceBar::_hide_bar(bool p_force_focus) {
hide();
}
+void FindReplaceBar::_update_toggle_replace_button(bool p_replace_visible) {
+ String tooltip = p_replace_visible ? TTR("Hide Replace") : TTR("Show Replace");
+ String shortcut = ED_GET_SHORTCUT(p_replace_visible ? "script_text_editor/find" : "script_text_editor/replace")->get_as_text();
+ toggle_replace_button->set_tooltip_text(vformat("%s (%s)", tooltip, shortcut));
+ StringName rtl_compliant_arrow = is_layout_rtl() ? SNAME("GuiTreeArrowLeft") : SNAME("GuiTreeArrowRight");
+ toggle_replace_button->set_icon(get_editor_theme_icon(p_replace_visible ? SNAME("GuiTreeArrowDown") : rtl_compliant_arrow));
+}
+
void FindReplaceBar::_show_search(bool p_with_replace, bool p_show_only) {
show();
if (p_show_only) {
@@ -582,6 +591,7 @@ void FindReplaceBar::popup_search(bool p_show_only) {
hbc_button_replace->hide();
hbc_option_replace->hide();
selection_only->set_pressed(false);
+ _update_toggle_replace_button(false);
_show_search(false, p_show_only);
}
@@ -591,6 +601,7 @@ void FindReplaceBar::popup_replace() {
replace_text->show();
hbc_button_replace->show();
hbc_option_replace->show();
+ _update_toggle_replace_button(true);
}
selection_only->set_pressed(text_editor->has_selection(0) && text_editor->get_selection_from_line(0) < text_editor->get_selection_to_line(0));
@@ -644,6 +655,11 @@ void FindReplaceBar::_replace_text_submitted(const String &p_text) {
}
}
+void FindReplaceBar::_toggle_replace_pressed() {
+ bool replace_visible = replace_text->is_visible_in_tree();
+ replace_visible ? popup_search(true) : popup_replace();
+}
+
String FindReplaceBar::get_search_text() const {
return search_text->get_text();
}
@@ -702,6 +718,12 @@ void FindReplaceBar::_bind_methods() {
}
FindReplaceBar::FindReplaceBar() {
+ toggle_replace_button = memnew(Button);
+ add_child(toggle_replace_button);
+ toggle_replace_button->set_flat(true);
+ toggle_replace_button->set_focus_mode(FOCUS_NONE);
+ toggle_replace_button->connect(SceneStringName(pressed), callable_mp(this, &FindReplaceBar::_toggle_replace_pressed));
+
vbc_lineedit = memnew(VBoxContainer);
add_child(vbc_lineedit);
vbc_lineedit->set_alignment(BoxContainer::ALIGNMENT_CENTER);
diff --git a/editor/code_editor.h b/editor/code_editor.h
index e56405a4b2..c1c65a2a4a 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -70,6 +70,7 @@ class FindReplaceBar : public HBoxContainer {
SEARCH_PREV,
};
+ Button *toggle_replace_button = nullptr;
LineEdit *search_text = nullptr;
Label *matches_label = nullptr;
Button *find_prev = nullptr;
@@ -106,12 +107,14 @@ class FindReplaceBar : public HBoxContainer {
void _show_search(bool p_with_replace, bool p_show_only);
void _hide_bar(bool p_force_focus = false);
+ void _update_toggle_replace_button(bool p_replace_visible);
void _editor_text_changed();
void _search_options_changed(bool p_pressed);
void _search_text_changed(const String &p_text);
void _search_text_submitted(const String &p_text);
void _replace_text_submitted(const String &p_text);
+ void _toggle_replace_pressed();
protected:
void _notification(int p_what);