Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Move `FindInFilesDialog` to `FindInFilesPanel`

Simon Döhl45e4034f5ad1
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 8efc2a94be1..20eeb12a563 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -135,6 +135,7 @@
#include "editor/scene/material_editor_plugin.h"
#include "editor/scene/particle_process_material_editor_plugin.h"
#include "editor/script/editor_script.h"
+#include "editor/script/find_in_files.h"
#include "editor/script/script_text_editor.h"
#include "editor/script/text_editor.h"
#include "editor/settings/editor_build_profile.h"
@@ -3716,8 +3717,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
project_settings_editor->popup_project_settings();
} break;
- case PROJECT_FIND_IN_FILES: {
- ScriptEditor::get_singleton()->open_find_in_files_dialog("");
+ case PROJECT_FIND_IN_FILES:
+ case PROJECT_REPLACE_IN_FILES: {
+ FindInFiles::get_singleton()->open_dock("", PROJECT_REPLACE_IN_FILES == p_option);
} break;
case PROJECT_INSTALL_ANDROID_SOURCE: {
@@ -8099,6 +8101,7 @@ void EditorNode::_build_project_menu(bool p_dark_mode) {
project_menu->add_icon_shortcut(get_editor_theme_native_menu_icon(SNAME("ClassList"), menu_type == MENU_TYPE_GLOBAL, p_dark_mode), ED_GET_SHORTCUT("editor/project_settings"), PROJECT_OPEN_SETTINGS);
project_menu->add_shortcut(ED_GET_SHORTCUT("editor/find_in_files"), PROJECT_FIND_IN_FILES);
+ project_menu->add_shortcut(ED_GET_SHORTCUT("editor/replace_in_files"), PROJECT_REPLACE_IN_FILES);
project_menu->add_separator();
project_menu->add_item(TTRC("Version Control"), PROJECT_VERSION_CONTROL);
@@ -9023,6 +9026,7 @@ EditorNode::EditorNode() {
ED_SHORTCUT_AND_COMMAND("editor/project_settings", TTRC("Project Settings..."), KeyModifierMask::CMD_OR_CTRL + KeyModifierMask::SHIFT + Key::COMMA, TTRC("Project Settings"));
ED_SHORTCUT_AND_COMMAND("editor/find_in_files", TTRC("Find in Files..."), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::F);
+ ED_SHORTCUT_AND_COMMAND("editor/replace_in_files", TTRC("Replace in Files..."), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::R);
ED_SHORTCUT_AND_COMMAND("editor/export", TTRC("Export..."), Key::NONE, TTRC("Export"));
diff --git a/editor/editor_node.h b/editor/editor_node.h
index d63a416a551..545b2f56811 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -168,6 +168,7 @@ public:
// Project menu.
PROJECT_OPEN_SETTINGS,
PROJECT_FIND_IN_FILES,
+ PROJECT_REPLACE_IN_FILES,
PROJECT_VERSION_CONTROL,
PROJECT_EXPORT,
PROJECT_PACK_AS_ZIP,
diff --git a/editor/icons/MatchWord.svg b/editor/icons/MatchWord.svg
new file mode 100644
index 00000000000..a30bfb00edd
--- /dev/null
+++ b/editor/icons/MatchWord.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#e0e0e0" d="M5.2 1A3.2 3.4285713 0 0 0 2 4.4285713V13H3.6V9.571427H6.8V13H8.4V4.4285713A3.2 3.4285713 0 0 0 5.2 1Zm4.0000001 9.428573A2.4 2.5714284 0 0 0 12.4 12.849143V13H14V7.857142A2.4 2.5714284 0 0 0 11.599999 5.285714H10.8v1.7142858h.799999A.80000001.85714283 0 0 1 12.4 7.857142V8.0062848A2.4 2.5714284 0 0 0 9.2000001 10.428573ZM5.2 2.7142856A1.6 1.7142856 0 0 1 6.8 4.4285713V7.857142H3.6V4.4285713A1.6 1.7142856 0 0 1 5.2 2.7142856Zm6.399999 6.8571414a.80000112.857144 0 1 1 0 1.714288.80000112.857144 0 0 1 0-1.714288zM0 14H16V15H0zM0 13H1V14H0zM15 13H16V14H15z"/></svg>
diff --git a/editor/script/find_in_files.cpp b/editor/script/find_in_files.cpp
index 8db7014105c..040115468d8 100644
--- a/editor/script/find_in_files.cpp
+++ b/editor/script/find_in_files.cpp
@@ -47,14 +47,17 @@
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
-#include "scene/gui/check_button.h"
-#include "scene/gui/grid_container.h"
+#include "scene/gui/dialogs.h"
+#include "scene/gui/flow_container.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/progress_bar.h"
+#include "scene/gui/scroll_container.h"
+#include "scene/gui/split_container.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/tree.h"
#include "scene/main/scene_tree.h"
+#include "scene/main/timer.h"
#include "servers/rendering/rendering_server.h"
// TODO: Would be nice in Vector and Vectors.
@@ -92,6 +95,21 @@ static bool find_next(const String &p_line, const String &p_pattern, int p_from,
//--------------------------------------------------------------------------------
+void FindInFilesSearch::copy_from(const FindInFilesSearch *p_other) {
+ if (!p_other) {
+ return;
+ }
+
+ pattern = p_other->pattern;
+ whole_words = p_other->whole_words;
+ match_case = p_other->match_case;
+ root_dir = p_other->root_dir;
+
+ include_string = p_other->include_string;
+ exclude_string = p_other->exclude_string;
+ extension_filter = p_other->extension_filter;
+}
+
void FindInFilesSearch::set_search_text(const String &p_pattern) {
pattern = p_pattern;
}
@@ -112,12 +130,12 @@ void FindInFilesSearch::set_filter(const HashSet<String> &p_exts) {
extension_filter = p_exts;
}
-void FindInFilesSearch::set_includes(const HashSet<String> &p_include_wildcards) {
- include_wildcards = p_include_wildcards;
+void FindInFilesSearch::set_includes(const String &p_include_wildcards) {
+ include_string = p_include_wildcards;
}
-void FindInFilesSearch::set_excludes(const HashSet<String> &p_exclude_wildcards) {
- exclude_wildcards = p_exclude_wildcards;
+void FindInFilesSearch::set_excludes(const String &p_exclude_wildcards) {
+ exclude_string = p_exclude_wildcards;
}
void FindInFilesSearch::_notification(int p_what) {
@@ -134,6 +152,8 @@ void FindInFilesSearch::start() {
emit_signal(SceneStringName(finished));
return;
}
+ _calculate_wildcard(include_string, &include_wildcards);
+ _calculate_wildcard(exclude_string, &exclude_wildcards);
if (extension_filter.is_empty()) {
print_verbose("Nothing to search, filter matches no files");
emit_signal(SceneStringName(finished));
@@ -147,6 +167,7 @@ void FindInFilesSearch::start() {
folders_stack.clear();
folders_stack.push_back(init_folder);
+ files_to_scan.clear();
initial_files_count = 0;
searching = true;
@@ -349,6 +370,41 @@ bool FindInFilesSearch::_is_file_matched(const HashSet<String> &p_wildcards, con
return false;
}
+void FindInFilesSearch::_calculate_wildcard(const String &p_text, HashSet<String> *r_hash_set) {
+ r_hash_set->clear();
+ if (p_text.is_empty()) {
+ return;
+ }
+
+ PackedStringArray wildcards = p_text.split(",", false);
+ for (const String &wildcard : wildcards) {
+ r_hash_set->insert(_validate_filter_wildcard(wildcard));
+ }
+}
+
+String FindInFilesSearch::_validate_filter_wildcard(const String &p_expression) const {
+ String ret = p_expression.replace_char('\\', '/');
+ if (ret.begins_with("./")) {
+ // Relative to the project root.
+ ret = "res://" + ret.substr(2);
+ }
+
+ if (ret.begins_with(".")) {
+ // To match extension.
+ ret = "*" + ret;
+ }
+
+ if (!ret.begins_with("*")) {
+ ret = "*/" + ret.trim_prefix("/");
+ }
+
+ if (!ret.ends_with("*")) {
+ ret = ret.trim_suffix("/") + "/*";
+ }
+
+ return ret;
+}
+
void FindInFilesSearch::_bind_methods() {
ADD_SIGNAL(MethodInfo("result_found",
PropertyInfo(Variant::STRING, "path"),
@@ -362,71 +418,58 @@ void FindInFilesSearch::_bind_methods() {
//-----------------------------------------------------------------------------
-void FindInFilesDialog::set_search_text(const String &p_text) {
- if (!p_text.is_empty()) {
- search_text_line_edit->set_text(p_text);
- _on_search_text_modified(p_text);
- }
- if (replace_mode && !p_text.is_empty()) {
- callable_mp((Control *)replace_text_line_edit, &Control::grab_focus).call_deferred(false);
- replace_text_line_edit->select_all();
- } else {
- callable_mp((Control *)search_text_line_edit, &Control::grab_focus).call_deferred(false);
- search_text_line_edit->select_all();
+void FindInFilesSearchPanel::set_finder(FindInFilesSearch *p_finder, bool p_init) {
+ finder = p_finder;
+ search_text_line_edit->set_text(finder->get_search_text());
+ match_case_checkbox->set_pressed_no_signal(finder->get_match_case());
+ whole_words_checkbox->set_pressed_no_signal(finder->get_whole_words());
+ folder_line_edit->set_text(finder->get_folder());
+ includes_line_edit->set_text(finder->get_includes());
+ excludes_line_edit->set_text(finder->get_excludes());
+ for (Node *child : filters_container->iterate_children()) {
+ CheckBox *cb = Object::cast_to<CheckBox>(child);
+ if (!p_init && finder->get_filter()->has(cb->get_text())) {
+ cb->set_pressed_no_signal(true);
+ } else {
+ cb->set_pressed_no_signal(p_init);
+ }
}
+ // Update the finder in case we don't start a search before switching tabs to save initialization settings.
+ _update_finder();
+ // Don't search when setting finder to not overwrite old results in case they are desired.
+ debounce_timer->stop();
}
-void FindInFilesDialog::set_replace_text(const String &p_text) {
- replace_text_line_edit->set_text(p_text);
-}
-
-void FindInFilesDialog::set_replace_mode(bool p_replace) {
- if (replace_mode == p_replace) {
- return;
- }
-
- replace_mode = p_replace;
-
- if (replace_mode) {
- set_title(TTRC("Replace in Files"));
- replace_label->show();
- replace_text_line_edit->show();
- } else {
- set_title(TTRC("Find in Files"));
- replace_label->hide();
- replace_text_line_edit->hide();
+void FindInFilesSearchPanel::set_search_text(const String &p_text) {
+ if (!p_text.is_empty()) {
+ search_text_line_edit->set_text(p_text);
+ _on_search_submitted();
}
-
- // Recalculate the dialog size after hiding child controls.
- set_size(Size2(get_size().x, 0));
+ callable_mp(this, &FindInFilesSearchPanel::_highlight_search_text).call_deferred();
}
-String FindInFilesDialog::get_search_text() const {
- return search_text_line_edit->get_text();
-}
-
-String FindInFilesDialog::get_replace_text() const {
- return replace_text_line_edit->get_text();
+void FindInFilesSearchPanel::set_replace_text(const String &p_text) {
+ replace_line_edit->set_text(p_text);
+ replace_line_edit->emit_signal(SceneStringName(text_changed), p_text);
}
-bool FindInFilesDialog::is_match_case() const {
- return match_case_checkbox->is_pressed();
+void FindInFilesSearchPanel::set_replace(bool p_replace_mode) {
+ toggle_replace_button->set_pressed(p_replace_mode);
}
-bool FindInFilesDialog::is_whole_words() const {
- return whole_words_checkbox->is_pressed();
+String FindInFilesSearchPanel::get_search_text() const {
+ return search_text_line_edit->get_text();
}
-String FindInFilesDialog::get_folder() const {
- String p_text = folder_line_edit->get_text();
- return p_text.strip_edges();
+bool FindInFilesSearchPanel::is_replace_pressed() const {
+ return toggle_replace_button->is_pressed();
}
-HashSet<String> FindInFilesDialog::get_filter() const {
+HashSet<String> FindInFilesSearchPanel::get_filter() const {
// Could check the filters_preferences but it might not have been generated yet.
HashSet<String> filters;
- for (int i = 0; i < filters_container->get_child_count(); ++i) {
- CheckBox *cb = static_cast<CheckBox *>(filters_container->get_child(i));
+ for (Node *child : filters_container->iterate_children()) {
+ CheckBox *cb = Object::cast_to<CheckBox>(child);
if (cb->is_pressed()) {
filters.insert(cb->get_text());
}
@@ -434,282 +477,282 @@ HashSet<String> FindInFilesDialog::get_filter() const {
return filters;
}
-HashSet<String> FindInFilesDialog::get_includes() const {
- HashSet<String> includes;
- String p_text = includes_line_edit->get_text();
-
- if (p_text.is_empty()) {
- return includes;
- }
-
- PackedStringArray wildcards = p_text.split(",", false);
- for (const String &wildcard : wildcards) {
- includes.insert(_validate_filter_wildcard(wildcard));
+void FindInFilesSearchPanel::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_THEME_CHANGED: {
+ filters_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)));
+ match_case_checkbox->set_button_icon(get_editor_theme_icon(SNAME("MatchCase")));
+ whole_words_checkbox->set_button_icon(get_editor_theme_icon(SNAME("MatchWord")));
+ replace_all_button->set_button_icon(get_editor_theme_icon(SNAME("ReplaceText")));
+ } break;
}
- return includes;
}
-HashSet<String> FindInFilesDialog::get_excludes() const {
- HashSet<String> excludes;
- String p_text = excludes_line_edit->get_text();
+void FindInFilesSearchPanel::_highlight_search_text() {
+ search_text_line_edit->grab_focus(false);
+ search_text_line_edit->select_all();
+ search_text_line_edit->set_caret_column(search_text_line_edit->get_text().length());
+}
- if (p_text.is_empty()) {
- return excludes;
+void FindInFilesSearchPanel::_update_file_extensions(bool p_init) {
+ if (!p_init && !EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/behavior/general/find_in_file_extensions")) {
+ return;
}
-
- PackedStringArray wildcards = p_text.split(",", false);
- for (const String &wildcard : wildcards) {
- excludes.insert(_validate_filter_wildcard(wildcard));
+ // Refresh extension checkboxes when the settings changed.
+ for (Node *child : filters_container->iterate_children()) {
+ child->queue_free();
+ }
+ const PackedStringArray extensions = EDITOR_GET("text_editor/behavior/general/find_in_file_extensions");
+ for (const String &ext : extensions) {
+ CheckBox *cb = memnew(CheckBox);
+ cb->set_text(ext);
+ if (!filters_preferences.has(ext)) {
+ filters_preferences[ext] = true;
+ }
+ cb->set_pressed(filters_preferences[ext]);
+ cb->connect(SceneStringName(toggled), callable_mp(this, &FindInFilesSearchPanel::_on_filter_toggled).bind(ext));
+ cb->set_tooltip_text(TTRC("Include the files with the following extensions. Add or remove them in EditorSettings:\n\"text_editor/behavior/general/find_in_file_extensions\"."));
+ filters_container->add_child(cb);
}
- return excludes;
}
-void FindInFilesDialog::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_VISIBILITY_CHANGED: {
- if (is_visible() && extensions_dirty) {
- // Refresh extension checkboxes when the settings changed.
- for (Node *child : filters_container->iterate_children()) {
- child->queue_free();
- }
- const PackedStringArray extensions = EDITOR_GET("text_editor/behavior/general/find_in_file_extensions");
- for (const String &ext : extensions) {
- CheckBox *cb = memnew(CheckBox);
- cb->set_text(ext);
- if (!filters_preferences.has(ext)) {
- filters_preferences[ext] = true;
- }
- cb->set_pressed(filters_preferences[ext]);
- filters_container->add_child(cb);
- }
- extensions_dirty = false;
- }
- } break;
-
- case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
- if (EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/behavior/general/find_in_file_extensions")) {
- extensions_dirty = true;
- }
- } break;
- }
+void FindInFilesSearchPanel::_on_filter_toggled(bool p_pressed, const String &p_ext) {
+ filters_preferences[p_ext] = p_pressed;
+ _on_search_modified();
}
-void FindInFilesDialog::_on_folder_button_pressed() {
+void FindInFilesSearchPanel::_on_folder_button_pressed() {
folder_dialog->popup_file_dialog();
}
-void FindInFilesDialog::custom_action(const String &p_action) {
- for (int i = 0; i < filters_container->get_child_count(); ++i) {
- CheckBox *cb = static_cast<CheckBox *>(filters_container->get_child(i));
- filters_preferences[cb->get_text()] = cb->is_pressed();
- }
-
- if (p_action == "find") {
- emit_signal(SNAME("find_requested"));
- } else if (p_action == "replace") {
- emit_signal(SNAME("replace_requested"));
- }
- hide();
+void FindInFilesSearchPanel::_on_search_submitted() {
+ debounce_timer->stop();
+ _emit_find_requested();
}
-void FindInFilesDialog::_on_search_text_modified(const String &p_text) {
- ERR_FAIL_NULL(find_button);
- ERR_FAIL_NULL(replace_button);
+void FindInFilesSearchPanel::_on_search_modified() {
+ finder->stop();
+ _update_finder();
+ debounce_timer->start(0.5);
+}
- find_button->set_disabled(get_search_text().is_empty());
- replace_button->set_disabled(get_search_text().is_empty());
+void FindInFilesSearchPanel::_update_finder() {
+ finder->set_search_text(search_text_line_edit->get_text());
+ finder->set_match_case(match_case_checkbox->is_pressed());
+ finder->set_whole_words(whole_words_checkbox->is_pressed());
+ finder->set_folder(folder_line_edit->get_text().strip_edges());
+ finder->set_filter(get_filter());
+ finder->set_includes(includes_line_edit->get_text());
+ finder->set_excludes(excludes_line_edit->get_text());
}
-void FindInFilesDialog::_on_search_text_submitted(const String &p_text) {
- // This allows to trigger a global search without leaving the keyboard.
- if (!replace_mode && !find_button->is_disabled()) {
- custom_action("find");
- }
+void FindInFilesSearchPanel::_emit_find_requested() {
+ _update_finder();
+ emit_signal("find_requested");
+}
- if (replace_mode && !replace_button->is_disabled()) {
- custom_action("replace");
- }
+void FindInFilesSearchPanel::_toggle_replace_pressed(bool p_toggle) {
+ replace_hbox->set_visible(p_toggle);
+ _emit_find_requested();
}
-void FindInFilesDialog::_on_replace_text_submitted(const String &p_text) {
- // This allows to trigger a global search without leaving the keyboard.
- if (replace_mode && !replace_button->is_disabled()) {
- custom_action("replace");
+void FindInFilesSearchPanel::_on_replace_all_clicked(bool p_dialog) {
+ if (p_dialog && !dont_show_checkbox->is_pressed()) {
+ replace_all_confirm->popup_centered();
+ } else {
+ emit_signal("replace_all_requested");
}
}
-void FindInFilesDialog::_on_folder_selected(String p_path) {
+void FindInFilesSearchPanel::_on_folder_selected(String p_path) {
int i = p_path.find("://");
if (i != -1) {
p_path = p_path.substr(i + 3);
}
folder_line_edit->set_text(p_path);
+ _on_search_modified();
}
-String FindInFilesDialog::_validate_filter_wildcard(const String &p_expression) const {
- String ret = p_expression.replace_char('\\', '/');
- if (ret.begins_with("./")) {
- // Relative to the project root.
- ret = "res://" + ret.trim_prefix("./");
- }
-
- if (ret.begins_with(".")) {
- // To match extension.
- ret = "*" + ret;
- }
-
- if (!ret.begins_with("*")) {
- ret = "*/" + ret.trim_prefix("/");
- }
-
- if (!ret.ends_with("*")) {
- ret = ret.trim_suffix("/") + "/*";
- }
-
- return ret;
-}
-
-void FindInFilesDialog::_bind_methods() {
+void FindInFilesSearchPanel::_bind_methods() {
ADD_SIGNAL(MethodInfo("find_requested"));
- ADD_SIGNAL(MethodInfo("replace_requested"));
+ ADD_SIGNAL(MethodInfo("replace_all_requested"));
}
-FindInFilesDialog::FindInFilesDialog() {
- set_min_size(Size2(500 * EDSCALE, 0));
- set_title(TTRC("Find in Files"));
+FindInFilesSearchPanel::FindInFilesSearchPanel() {
+ set_custom_minimum_size(Size2(300 * EDSCALE, 50 * EDSCALE));
+ set_name(TTRC("Find in Files"));
+ set_anchors_preset(LayoutPreset::PRESET_FULL_RECT);
+ set_horizontal_scroll_mode(SCROLL_MODE_DISABLED);
+
+ Ref<StyleBoxEmpty> sb = memnew(StyleBoxEmpty);
+ sb->set_content_margin_all(6 * EDSCALE);
+ add_theme_style_override("panel", sb);
VBoxContainer *vbc = memnew(VBoxContainer);
- vbc->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 8 * EDSCALE);
- vbc->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 8 * EDSCALE);
- vbc->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -8 * EDSCALE);
- vbc->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -8 * EDSCALE);
+ vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_child(vbc);
- GridContainer *gc = memnew(GridContainer);
- gc->set_columns(2);
- vbc->add_child(gc);
-
- Label *find_label = memnew(Label);
- find_label->set_text(TTRC("Find:"));
- gc->add_child(find_label);
-
- search_text_line_edit = memnew(LineEdit);
- search_text_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- search_text_line_edit->set_accessibility_name(TTRC("Find:"));
- search_text_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesDialog::_on_search_text_modified));
- search_text_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
- gc->add_child(search_text_line_edit);
-
- replace_label = memnew(Label);
- replace_label->set_text(TTRC("Replace:"));
- replace_label->hide();
- gc->add_child(replace_label);
-
- replace_text_line_edit = memnew(LineEdit);
- replace_text_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- replace_text_line_edit->set_accessibility_name(TTRC("Replace:"));
- replace_text_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_replace_text_submitted));
- replace_text_line_edit->hide();
- gc->add_child(replace_text_line_edit);
-
- gc->add_child(memnew(Control)); // Space to maintain the grid alignment.
-
{
- HBoxContainer *hbc = memnew(HBoxContainer);
-
- whole_words_checkbox = memnew(CheckBox);
- whole_words_checkbox->set_text(TTRC("Whole Words"));
- hbc->add_child(whole_words_checkbox);
+ Label *find_label = memnew(Label);
+ find_label->set_text("Find");
+ find_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
+ vbc->add_child(find_label);
+
+ HBoxContainer *search_hbc = memnew(HBoxContainer);
+ search_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ vbc->add_child(search_hbc);
+
+ search_text_line_edit = memnew(LineEdit);
+ search_text_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ search_text_line_edit->set_accessibility_name(TTRC("Find"));
+ search_text_line_edit->set_placeholder(TTRC("Find"));
+ search_text_line_edit->set_keep_editing_on_text_submit(true);
+ search_text_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesSearchPanel::_on_search_modified).unbind(1));
+ search_text_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesSearchPanel::_on_search_submitted).unbind(1));
+ search_hbc->add_child(search_text_line_edit);
+
+ whole_words_checkbox = memnew(Button);
+ whole_words_checkbox->set_theme_type_variation(SceneStringName(FlatButton));
+ whole_words_checkbox->set_toggle_mode(true);
+ whole_words_checkbox->set_tooltip_text(TTRC("Whole Words"));
+ whole_words_checkbox->connect(SceneStringName(toggled), callable_mp(this, &FindInFilesSearchPanel::_on_search_modified).unbind(1));
+ search_hbc->add_child(whole_words_checkbox);
+
+ match_case_checkbox = memnew(Button);
+ match_case_checkbox->set_theme_type_variation(SceneStringName(FlatButton));
+ match_case_checkbox->set_toggle_mode(true);
+ match_case_checkbox->set_tooltip_text(TTRC("Match Case"));
+ match_case_checkbox->connect(SceneStringName(toggled), callable_mp(this, &FindInFilesSearchPanel::_on_search_modified).unbind(1));
+ search_hbc->add_child(match_case_checkbox);
+
+ toggle_replace_button = memnew(CheckBox);
+ toggle_replace_button->set_pressed(false);
+ toggle_replace_button->set_text(TTRC("Replace"));
+ toggle_replace_button->set_tooltip_text(TTRC("Toggle Replace Mode"));
+ toggle_replace_button->connect(SceneStringName(toggled), callable_mp(this, &FindInFilesSearchPanel::_toggle_replace_pressed));
+ vbc->add_child(toggle_replace_button);
+
+ replace_hbox = memnew(HBoxContainer);
+ replace_hbox->set_visible(toggle_replace_button->is_pressed());
+ vbc->add_child(replace_hbox);
- match_case_checkbox = memnew(CheckBox);
- match_case_checkbox->set_text(TTRC("Match Case"));
- hbc->add_child(match_case_checkbox);
+ replace_line_edit = memnew(LineEdit);
+ replace_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ replace_line_edit->set_accessibility_name(TTRC("Replace"));
+ replace_line_edit->set_placeholder(TTRC("Replace"));
+ replace_line_edit->set_keep_editing_on_text_submit(true);
+ replace_hbox->add_child(replace_line_edit);
+
+ VBoxContainer *confirm_vbox = memnew(VBoxContainer);
+ Label *replace_all_warning = memnew(Label);
+ replace_all_warning->set_text(TTRC("\"Replace all\" can't be undone."));
+ replace_all_warning->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
+ confirm_vbox->add_child(replace_all_warning);
+ dont_show_checkbox = memnew(CheckBox);
+ dont_show_checkbox->set_text(TTRC("Don't show again"));
+ dont_show_checkbox->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
+ confirm_vbox->add_child(dont_show_checkbox);
+
+ replace_all_confirm = memnew(ConfirmationDialog);
+ replace_all_confirm->add_child(confirm_vbox);
+ replace_all_confirm->set_flag(Window::FLAG_RESIZE_DISABLED, true);
+ replace_all_confirm->set_ok_button_text(TTRC("Replace all"));
+ replace_all_confirm->connect(SceneStringName(confirmed), callable_mp(this, &FindInFilesSearchPanel::_on_replace_all_clicked).bind(false));
+ add_child(replace_all_confirm);
- gc->add_child(hbc);
+ replace_all_button = memnew(Button);
+ replace_all_button->set_theme_type_variation(SceneStringName(FlatButton));
+ replace_all_button->set_tooltip_text(TTRC("Replace all"));
+ replace_all_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesSearchPanel::_on_replace_all_clicked).bind(true));
+ replace_hbox->add_child(replace_all_button);
}
- Label *folder_label = memnew(Label);
- folder_label->set_text(TTRC("Folder:"));
- gc->add_child(folder_label);
+ filters_label = memnew(Label);
+ filters_label->set_text(TTRC("Filters"));
+ vbc->add_child(filters_label);
+ additional_options_vbc = memnew(VBoxContainer);
+ additional_options_vbc->add_theme_constant_override("separation", 0);
+ vbc->add_child(additional_options_vbc);
{
HBoxContainer *hbc = memnew(HBoxContainer);
+ additional_options_vbc->add_child(hbc);
+
+ folder_hbc = memnew(HBoxContainer);
+ folder_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ hbc->add_child(folder_hbc);
Label *prefix_label = memnew(Label);
prefix_label->set_text("res://");
prefix_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
- hbc->add_child(prefix_label);
+ folder_hbc->add_child(prefix_label);
folder_line_edit = memnew(LineEdit);
folder_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- folder_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
- folder_line_edit->set_accessibility_name(TTRC("Folder:"));
- hbc->add_child(folder_line_edit);
+ folder_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesSearchPanel::_on_search_modified).unbind(1));
+ folder_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesSearchPanel::_on_search_submitted).unbind(1));
+ folder_line_edit->set_accessibility_name(TTRC("Folder"));
+ folder_line_edit->set_placeholder(TTRC("Folder"));
+ folder_line_edit->set_keep_editing_on_text_submit(true);
+ folder_hbc->add_child(folder_line_edit);
Button *folder_button = memnew(Button);
folder_button->set_accessibility_name(TTRC("Select Folder"));
folder_button->set_text("...");
- folder_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesDialog::_on_folder_button_pressed));
- hbc->add_child(folder_button);
+ folder_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesSearchPanel::_on_folder_button_pressed));
+ folder_hbc->add_child(folder_button);
folder_dialog = memnew(EditorFileDialog);
folder_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_DIR);
- folder_dialog->connect("dir_selected", callable_mp(this, &FindInFilesDialog::_on_folder_selected));
+ folder_dialog->connect("dir_selected", callable_mp(this, &FindInFilesSearchPanel::_on_folder_selected));
add_child(folder_dialog);
-
- gc->add_child(hbc);
}
- Label *includes_label = memnew(Label);
- includes_label->set_text(TTRC("Includes:"));
- includes_label->set_tooltip_text(TTRC("Include the files with the following expressions. Use \",\" to separate."));
- includes_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- gc->add_child(includes_label);
-
- includes_line_edit = memnew(LineEdit);
- includes_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- includes_line_edit->set_placeholder(TTRC("example: scripts,scenes/*/test.gd"));
- includes_line_edit->set_accessibility_name(TTRC("Includes:"));
- includes_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
- gc->add_child(includes_line_edit);
-
Label *excludes_label = memnew(Label);
- excludes_label->set_text(TTRC("Excludes:"));
+ excludes_label->set_text(TTRC("Excludes"));
excludes_label->set_tooltip_text(TTRC("Exclude the files with the following expressions. Use \",\" to separate."));
excludes_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- gc->add_child(excludes_label);
+ additional_options_vbc->add_child(excludes_label);
excludes_line_edit = memnew(LineEdit);
excludes_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- excludes_line_edit->set_placeholder(TTRC("example: res://addons,scenes/test/*.gd"));
- excludes_line_edit->set_accessibility_name(TTRC("Excludes:"));
- excludes_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
- gc->add_child(excludes_line_edit);
-
- Label *filter_label = memnew(Label);
- filter_label->set_text(TTRC("Filters:"));
- filter_label->set_tooltip_text(TTRC("Include the files with the following extensions. Add or remove them in EditorSettings:\n\"text_editor/behavior/general/find_in_file_extensions\"."));
- filter_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
- gc->add_child(filter_label);
+ excludes_line_edit->set_placeholder(TTRC("Example: res://addons,scenes/test/*.gd"));
+ excludes_line_edit->set_accessibility_name(TTRC("Excludes"));
+ excludes_line_edit->set_keep_editing_on_text_submit(true);
+ excludes_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesSearchPanel::_on_search_modified).unbind(1));
+ excludes_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesSearchPanel::_on_search_submitted).unbind(1));
+ additional_options_vbc->add_child(excludes_line_edit);
- filters_container = memnew(HBoxContainer);
- gc->add_child(filters_container);
+ Label *includes_label = memnew(Label);
+ includes_label->set_text(TTRC("Includes"));
+ includes_label->set_tooltip_text(TTRC("Include the files with the following expressions. Use \",\" to separate."));
+ includes_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+ additional_options_vbc->add_child(includes_label);
- find_button = add_button(TTRC("Find..."), false, "find");
- find_button->set_disabled(true);
+ includes_line_edit = memnew(LineEdit);
+ includes_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ includes_line_edit->set_placeholder(TTRC("Example: scripts,scenes/*/test.gd"));
+ includes_line_edit->set_accessibility_name(TTRC("Includes"));
+ includes_line_edit->set_keep_editing_on_text_submit(true);
+ includes_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesSearchPanel::_on_search_modified).unbind(1));
+ includes_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesSearchPanel::_on_search_submitted).unbind(1));
+ additional_options_vbc->add_child(includes_line_edit);
- replace_button = add_button(TTRC("Replace..."), false, "replace");
- replace_button->set_disabled(true);
+ filters_container = memnew(HFlowContainer);
+ additional_options_vbc->add_child(filters_container);
+ EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &FindInFilesSearchPanel::_update_file_extensions).bind(false));
+ _update_file_extensions(true);
- Button *cancel_button = get_ok_button();
- cancel_button->set_text(TTRC("Cancel"));
+ debounce_timer = memnew(Timer);
+ debounce_timer->set_one_shot(true);
+ debounce_timer->connect("timeout", callable_mp(this, &FindInFilesSearchPanel::_emit_find_requested));
+ add_child(debounce_timer);
}
//-----------------------------------------------------------------------------
-void FindInFilesPanel::set_with_replace(bool p_with_replace) {
+void FindInFilesResultsPanel::set_with_replace(bool p_with_replace) {
with_replace = p_with_replace;
- replace_container->set_visible(p_with_replace);
if (with_replace) {
// Results show checkboxes on their left so they can be opted out.
@@ -723,21 +766,17 @@ void FindInFilesPanel::set_with_replace(bool p_with_replace) {
}
}
-void FindInFilesPanel::set_replace_text(const String &p_text) {
- replace_line_edit->set_text(p_text);
-}
-
-bool FindInFilesPanel::is_keep_results() const {
- return keep_results_button->is_pressed();
+void FindInFilesResultsPanel::set_replace_text(const String &p_text) {
+ replace_text = p_text;
}
-void FindInFilesPanel::set_search_labels_visibility(bool p_visible) {
+void FindInFilesResultsPanel::set_search_labels_visibility(bool p_visible) {
find_label->set_visible(p_visible);
search_text_label->set_visible(p_visible);
- close_button->set_visible(p_visible);
+ progress_bar_placeholder->set_visible(!p_visible);
}
-void FindInFilesPanel::_clear() {
+void FindInFilesResultsPanel::_clear() {
file_items.clear();
file_items_results_count.clear();
result_items.clear();
@@ -745,7 +784,7 @@ void FindInFilesPanel::_clear() {
results_display->create_item(); // Root
}
-void FindInFilesPanel::start_search() {
+void FindInFilesResultsPanel::start_search() {
_clear();
status_label->set_text(TTRC("Searching..."));
@@ -760,22 +799,49 @@ void FindInFilesPanel::start_search() {
finder->start();
- _update_replace_buttons();
refresh_button->hide();
cancel_button->show();
}
-void FindInFilesPanel::stop_search() {
+void FindInFilesResultsPanel::stop_search() {
finder->stop();
status_label->set_text("");
- _update_replace_buttons();
progress_bar->set_visible(false);
refresh_button->show();
cancel_button->hide();
}
-void FindInFilesPanel::update_layout(EditorDock::DockLayout p_layout, int p_slot) {
+void FindInFilesResultsPanel::_remove_result(TreeItem *p_item) {
+ const String file_path = p_item->get_metadata(0);
+ result_items.erase(p_item);
+ if (file_items_results_count.has(p_item)) {
+ int match_count = p_item->get_child_count();
+
+ for (int i = 0; i < match_count; i++) {
+ TreeItem *child_item = p_item->get_child(i);
+ result_items.erase(child_item);
+ }
+
+ p_item->clear_children();
+ file_items.erase(file_path);
+ file_items_results_count.erase(p_item);
+ }
+
+ if (TreeItem *item_parent = p_item->get_parent()) {
+ if (file_items_results_count.has(item_parent)) {
+ file_items_results_count[item_parent]--;
+ }
+ if (file_items_results_count[item_parent] == 0 && item_parent != results_display->get_root()) {
+ file_items.erase(item_parent->get_metadata(0));
+ get_tree()->queue_delete(item_parent);
+ }
+ }
+ get_tree()->queue_delete(p_item);
+ _update_matches_text();
+}
+
+void FindInFilesResultsPanel::update_layout(EditorDock::DockLayout p_layout, int p_slot) {
if (p_slot != EditorDock::DOCK_SLOT_BOTTOM) {
results_display->set_theme_type_variation("NoBorderHorizontal");
results_display->set_scroll_hint_mode(Tree::SCROLL_HINT_MODE_BOTH);
@@ -785,7 +851,7 @@ void FindInFilesPanel::update_layout(EditorDock::DockLayout p_layout, int p_slot
}
}
-void FindInFilesPanel::_notification(int p_what) {
+void FindInFilesResultsPanel::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
_on_theme_changed();
@@ -820,7 +886,7 @@ void FindInFilesPanel::_notification(int p_what) {
}
}
-void FindInFilesPanel::_on_result_found(const String &p_fpath, int p_line_number, int p_begin, int p_end, const String &p_text) {
+void FindInFilesResultsPanel::_on_result_found(const String &p_fpath, int p_line_number, int p_begin, int p_end, const String &p_text) {
TreeItem *file_item;
Ref<Texture2D> remove_texture = get_editor_theme_icon(SNAME("Close"));
Ref<Texture2D> replace_texture = get_editor_theme_icon(SNAME("ReplaceText"));
@@ -865,7 +931,7 @@ void FindInFilesPanel::_on_result_found(const String &p_fpath, int p_line_number
String start = vformat("%3s: ", p_line_number);
item->set_text(text_index, start + trimmed_text);
- item->set_custom_draw_callback(text_index, callable_mp(this, &FindInFilesPanel::_draw_result_text));
+ item->set_custom_draw_callback(text_index, callable_mp(this, &FindInFilesResultsPanel::_draw_result_text));
Result r;
r.line_number = p_line_number;
@@ -885,7 +951,8 @@ void FindInFilesPanel::_on_result_found(const String &p_fpath, int p_line_number
}
}
-void FindInFilesPanel::_on_theme_changed() {
+void FindInFilesResultsPanel::_on_theme_changed() {
+ new_tab_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
results_display->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("source"), EditorStringName(EditorFonts)));
results_display->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("source_size"), EditorStringName(EditorFonts)));
@@ -917,7 +984,7 @@ void FindInFilesPanel::_on_theme_changed() {
}
}
-void FindInFilesPanel::_draw_result_text(Object *p_item_obj, const Rect2 &p_rect) {
+void FindInFilesResultsPanel::_draw_result_text(Object *p_item_obj, const Rect2 &p_rect) {
TreeItem *item = Object::cast_to<TreeItem>(p_item_obj);
if (!item) {
return;
@@ -934,7 +1001,7 @@ void FindInFilesPanel::_draw_result_text(Object *p_item_obj, const Rect2 &p_rect
Rect2 match_rect = p_rect;
match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 1;
- match_rect.size.x = font->get_string_size(search_text_label->get_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1;
+ match_rect.size.x = font->get_string_size(finder->get_search_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1;
match_rect.position.y += 1 * EDSCALE;
match_rect.size.y -= 2 * EDSCALE;
@@ -955,7 +1022,7 @@ void FindInFilesPanel::_draw_result_text(Object *p_item_obj, const Rect2 &p_rect
// Text is drawn by Tree already.
}
-void FindInFilesPanel::_on_item_edited() {
+void FindInFilesResultsPanel::_on_item_edited() {
TreeItem *item = results_display->get_selected();
// Change opacity to half if checkbox is checked, otherwise full.
@@ -966,27 +1033,22 @@ void FindInFilesPanel::_on_item_edited() {
item->set_custom_color(1, use_color);
}
-void FindInFilesPanel::_on_finished() {
+void FindInFilesResultsPanel::_on_finished() {
_update_matches_text();
- _update_replace_buttons();
progress_bar->set_visible(false);
refresh_button->show();
cancel_button->hide();
}
-void FindInFilesPanel::_on_refresh_button_clicked() {
+void FindInFilesResultsPanel::_on_refresh_button_clicked() {
start_search();
}
-void FindInFilesPanel::_on_cancel_button_clicked() {
+void FindInFilesResultsPanel::_on_cancel_button_clicked() {
stop_search();
}
-void FindInFilesPanel::_on_close_button_clicked() {
- emit_signal(SNAME("close_button_clicked"));
-}
-
-void FindInFilesPanel::_on_result_selected() {
+void FindInFilesResultsPanel::_on_result_selected() {
TreeItem *item = results_display->get_selected();
HashMap<TreeItem *, Result>::Iterator E = result_items.find(item);
@@ -1001,13 +1063,8 @@ void FindInFilesPanel::_on_result_selected() {
emit_signal(SNAME("result_selected"), fpath, r.line_number, r.begin, r.end);
}
-void FindInFilesPanel::_on_replace_text_changed(const String &p_text) {
- _update_replace_buttons();
-}
-
-void FindInFilesPanel::_on_replace_all_clicked() {
- String replace_text = _get_replace_text();
-
+void FindInFilesResultsPanel::replace_all() {
+ Vector<TreeItem *> replaced_items;
for (KeyValue<String, TreeItem *> &E : file_items) {
TreeItem *file_item = E.value;
String fpath = file_item->get_metadata(0);
@@ -1021,6 +1078,7 @@ void FindInFilesPanel::_on_replace_all_clicked() {
HashMap<TreeItem *, Result>::Iterator F = result_items.find(item);
ERR_FAIL_COND(!F);
locations.push_back(F->value);
+ replaced_items.push_back(item);
}
if (locations.size() != 0) {
@@ -1029,17 +1087,18 @@ void FindInFilesPanel::_on_replace_all_clicked() {
}
}
- // Hide replace bar so we can't trigger the action twice without doing a new search.
- replace_container->hide();
+ for (TreeItem *item : replaced_items) {
+ _remove_result(item);
+ }
emit_signal(SNAME("files_modified"));
}
-void FindInFilesPanel::_on_button_clicked(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index) {
+void FindInFilesResultsPanel::_on_button_clicked(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index) {
const String file_path = p_item->get_metadata(0);
if (p_id == FIND_BUTTON_REPLACE) {
- const String replace_text = _get_replace_text();
+ const String rt = replace_text;
Vector<Result> locations;
if (file_items.has(file_path)) {
for (TreeItem *item = p_item->get_first_child(); item; item = item->get_next()) {
@@ -1047,44 +1106,19 @@ void FindInFilesPanel::_on_button_clicked(TreeItem *p_item, int p_column, int p_
ERR_FAIL_COND(!F);
locations.push_back(F->value);
}
- _apply_replaces_in_file(file_path, locations, replace_text);
+ _apply_replaces_in_file(file_path, locations, rt);
} else {
locations.push_back(result_items.find(p_item)->value);
const String path = p_item->get_parent()->get_metadata(0);
- _apply_replaces_in_file(path, locations, replace_text);
+ _apply_replaces_in_file(path, locations, rt);
}
emit_signal(SNAME("files_modified"));
}
- result_items.erase(p_item);
- if (file_items_results_count.has(p_item)) {
- int match_count = p_item->get_child_count();
-
- for (int i = 0; i < match_count; i++) {
- TreeItem *child_item = p_item->get_child(i);
- result_items.erase(child_item);
- }
-
- p_item->clear_children();
- file_items.erase(file_path);
- file_items_results_count.erase(p_item);
- }
-
- TreeItem *item_parent = p_item->get_parent();
- if (item_parent) {
- if (file_items_results_count.has(item_parent)) {
- file_items_results_count[item_parent]--;
- }
- if (item_parent->get_child_count() < 2 && item_parent != results_display->get_root()) {
- file_items.erase(item_parent->get_metadata(0));
- get_tree()->queue_delete(item_parent);
- }
- }
- get_tree()->queue_delete(p_item);
- _update_matches_text();
+ _remove_result(p_item);
}
-void FindInFilesPanel::_apply_replaces_in_file(const String &p_fpath, const Vector<Result> &p_locations, const String &p_new_text) {
+void FindInFilesResultsPanel::_apply_replaces_in_file(const String &p_fpath, const Vector<Result> &p_locations, const String &p_new_text) {
CodeTextEditor *code_text_editor = get_code_edit(p_fpath);
CodeEdit *code_edit = nullptr;
if (code_text_editor) {
@@ -1145,17 +1179,7 @@ void FindInFilesPanel::_apply_replaces_in_file(const String &p_fpath, const Vect
}
}
-String FindInFilesPanel::_get_replace_text() {
- return replace_line_edit->get_text();
-}
-
-void FindInFilesPanel::_update_replace_buttons() {
- bool disabled = finder->is_searching();
-
- replace_all_button->set_disabled(disabled);
-}
-
-void FindInFilesPanel::_update_matches_text() {
+void FindInFilesResultsPanel::_update_matches_text() {
String results_text;
int result_count = result_items.size();
int file_count = file_items.size();
@@ -1178,7 +1202,7 @@ void FindInFilesPanel::_update_matches_text() {
}
}
-void FindInFilesPanel::_bind_methods() {
+void FindInFilesResultsPanel::_bind_methods() {
ADD_SIGNAL(MethodInfo("result_selected",
PropertyInfo(Variant::STRING, "path"),
PropertyInfo(Variant::INT, "line_number"),
@@ -1186,27 +1210,25 @@ void FindInFilesPanel::_bind_methods() {
PropertyInfo(Variant::INT, "end")));
ADD_SIGNAL(MethodInfo("files_modified"));
-
- ADD_SIGNAL(MethodInfo("close_button_clicked"));
}
-FindInFilesPanel::FindInFilesPanel() {
+FindInFilesResultsPanel::FindInFilesResultsPanel() {
finder = memnew(FindInFilesSearch);
- finder->connect("result_found", callable_mp(this, &FindInFilesPanel::_on_result_found));
- finder->connect(SceneStringName(finished), callable_mp(this, &FindInFilesPanel::_on_finished));
+ finder->connect("result_found", callable_mp(this, &FindInFilesResultsPanel::_on_result_found));
+ finder->connect(SceneStringName(finished), callable_mp(this, &FindInFilesResultsPanel::_on_finished));
add_child(finder);
VBoxContainer *vbc = memnew(VBoxContainer);
- vbc->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0);
- vbc->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
- vbc->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
- vbc->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
add_child(vbc);
{
HBoxContainer *hbc = memnew(HBoxContainer);
hbc->set_alignment(BoxContainer::ALIGNMENT_END);
+ new_tab_button = memnew(Button);
+ new_tab_button->set_tooltip_text(TTRC("Create a new Search Tab"));
+ hbc->add_child(new_tab_button);
+
find_label = memnew(Label);
find_label->set_text(TTRC("Find:"));
hbc->add_child(find_label);
@@ -1226,33 +1248,26 @@ FindInFilesPanel::FindInFilesPanel() {
progress_bar->set_visible(false);
hbc->add_child(progress_bar);
+ progress_bar_placeholder = memnew(Control);
+ progress_bar_placeholder->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ hbc->add_child(progress_bar_placeholder);
+
status_label = memnew(Label);
status_label->set_focus_mode(FOCUS_ACCESSIBILITY);
hbc->add_child(status_label);
- keep_results_button = memnew(CheckButton);
- keep_results_button->set_text(TTRC("Keep Results"));
- keep_results_button->set_tooltip_text(TTRC("Keep these results and show subsequent results in a new window"));
- keep_results_button->set_pressed(false);
- hbc->add_child(keep_results_button);
-
refresh_button = memnew(Button);
refresh_button->set_text(TTRC("Refresh"));
- refresh_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_refresh_button_clicked));
+ refresh_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesResultsPanel::_on_refresh_button_clicked));
refresh_button->hide();
hbc->add_child(refresh_button);
cancel_button = memnew(Button);
cancel_button->set_text(TTRC("Cancel"));
- cancel_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_cancel_button_clicked));
+ cancel_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesResultsPanel::_on_cancel_button_clicked));
cancel_button->hide();
hbc->add_child(cancel_button);
- close_button = memnew(Button);
- close_button->set_text(TTRC("Close"));
- close_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_close_button_clicked));
- hbc->add_child(close_button);
-
vbc->add_child(hbc);
}
@@ -1262,12 +1277,12 @@ FindInFilesPanel::FindInFilesPanel() {
vbc->add_child(results_mc);
results_display = memnew(Tree);
- results_display->set_accessibility_name(TTRC("Search Results"));
+ results_display->set_accessibility_name(TTRC("Find in Files"));
results_display->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
results_display->set_scroll_hint_mode(Tree::SCROLL_HINT_MODE_BOTH);
- results_display->connect(SceneStringName(item_selected), callable_mp(this, &FindInFilesPanel::_on_result_selected));
- results_display->connect("item_edited", callable_mp(this, &FindInFilesPanel::_on_item_edited));
- results_display->connect("button_clicked", callable_mp(this, &FindInFilesPanel::_on_button_clicked));
+ results_display->connect(SceneStringName(item_selected), callable_mp(this, &FindInFilesResultsPanel::_on_result_selected));
+ results_display->connect("item_edited", callable_mp(this, &FindInFilesResultsPanel::_on_item_edited));
+ results_display->connect("button_clicked", callable_mp(this, &FindInFilesResultsPanel::_on_button_clicked));
results_display->set_hide_root(true);
results_display->set_select_mode(Tree::SELECT_ROW);
results_display->set_allow_rmb_select(true);
@@ -1276,80 +1291,54 @@ FindInFilesPanel::FindInFilesPanel() {
results_display->add_theme_constant_override("inner_item_margin_right", 0);
results_display->create_item(); // Root
results_mc->add_child(results_display);
-
- {
- replace_container = memnew(HBoxContainer);
-
- Label *replace_label = memnew(Label);
- replace_label->set_text(TTRC("Replace:"));
- replace_container->add_child(replace_label);
-
- replace_line_edit = memnew(LineEdit);
- replace_line_edit->set_accessibility_name(TTRC("Replace:"));
- replace_line_edit->set_h_size_flags(SIZE_EXPAND_FILL);
- replace_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesPanel::_on_replace_text_changed));
- replace_container->add_child(replace_line_edit);
-
- replace_all_button = memnew(Button);
- replace_all_button->set_text(TTRC("Replace all (no undo)"));
- replace_all_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_replace_all_clicked));
- replace_container->add_child(replace_all_button);
-
- replace_container->hide();
-
- vbc->add_child(replace_container);
- }
}
//-----------------------------------------------------------------------------
-FindInFilesPanel *FindInFilesContainer::_create_new_panel() {
+FindInFilesResultsPanel *FindInFilesContainer::_create_new_panel() {
int index = tabs->get_current_tab();
- FindInFilesPanel *panel = memnew(FindInFilesPanel);
- tabs->add_child(panel);
- tabs->move_child(panel, index + 1); // New panel is added after the current activated panel.
+ FindInFilesResultsPanel *old_panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_current_tab_control());
+
+ FindInFilesResultsPanel *new_panel = memnew(FindInFilesResultsPanel);
+ tabs->add_child(new_panel);
+ tabs->move_child(new_panel, index + 1); // New panel is added after the current activated panel.
tabs->set_current_tab(index + 1);
_update_bar_visibility();
+ _update_current_title();
- panel->connect("result_selected", callable_mp(this, &FindInFilesContainer::_result_selected));
- panel->connect("files_modified", callable_mp(this, &FindInFilesContainer::_files_modified));
- panel->connect("close_button_clicked", callable_mp(this, &FindInFilesContainer::_close_panel).bind(panel));
- return panel;
-}
-
-FindInFilesPanel *FindInFilesContainer::_get_current_panel() {
- return Object::cast_to<FindInFilesPanel>(tabs->get_current_tab_control());
-}
+ new_panel->connect("result_selected", callable_mp(this, &FindInFilesContainer::_result_selected));
+ new_panel->connect("files_modified", callable_mp(this, &FindInFilesContainer::_files_modified));
+ new_panel->get_new_tab_button()->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesContainer::_create_new_panel));
-FindInFilesPanel *FindInFilesContainer::get_panel_for_results(const String &p_label) {
- FindInFilesPanel *panel = nullptr;
- // Prefer the current panel.
- if (_get_current_panel() && !_get_current_panel()->is_keep_results()) {
- panel = _get_current_panel();
- } else {
- // Find the first panel which does not keep results.
- for (int i = 0; i < tabs->get_tab_count(); i++) {
- FindInFilesPanel *p = Object::cast_to<FindInFilesPanel>(tabs->get_tab_control(i));
- if (p && !p->is_keep_results()) {
- panel = p;
- tabs->set_current_tab(i);
- break;
- }
- }
-
- if (!panel) {
- panel = _create_new_panel();
+ FindInFilesSearch *new_finder = new_panel->get_finder();
+ if (old_panel) {
+ if (FindInFilesSearch *old_finder = old_panel->get_finder()) {
+ new_finder->copy_from(old_finder);
}
+ search_control->set_replace_text(old_panel->get_replace_text());
}
- tabs->set_tab_title(tabs->get_current_tab(), p_label);
- return panel;
+ search_control->set_finder(new_finder, !old_panel);
+ search_control->set_search_text(new_finder->get_search_text());
+ return new_panel;
+}
+
+void FindInFilesContainer::_update_current_title() {
+ tabs->set_tab_title(tabs->get_current_tab(), vformat(TTR("Find: %s"), search_control->get_search_text()));
}
void FindInFilesContainer::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (is_visible() && tabs->get_tab_count() == 0) {
+ _create_new_panel();
+ }
+ } break;
case NOTIFICATION_POSTINITIALIZE: {
connect("closed", callable_mp(this, &FindInFilesContainer::_on_dock_closed));
} break;
+ case NOTIFICATION_THEME_CHANGED: {
+ new_tab_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
+ } break;
}
}
@@ -1363,6 +1352,14 @@ void FindInFilesContainer::_on_theme_changed() {
add_theme_constant_override("margin_bottom", -bottom_panel_style->get_margin(SIDE_BOTTOM));
end_bulk_theme_override();
}
+ hsplit->add_theme_style_override("split_bar_background", get_theme_stylebox(SceneStringName(panel), "ItemListSecondary"));
+}
+
+void FindInFilesContainer::_on_tab_changed() {
+ if (FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_current_tab_control())) {
+ search_control->set_replace_text(panel->get_replace_text());
+ search_control->set_finder(panel->get_finder(), false);
+ }
}
void FindInFilesContainer::_result_selected(const String &p_fpath, int p_line_number, int p_begin, int p_end) {
@@ -1373,7 +1370,7 @@ void FindInFilesContainer::_files_modified() {
emit_signal(SNAME("files_modified"));
}
-void FindInFilesContainer::_close_panel(FindInFilesPanel *p_panel) {
+void FindInFilesContainer::_close_panel(FindInFilesResultsPanel *p_panel) {
ERR_FAIL_COND_MSG(p_panel->get_parent() != tabs, "This panel is not a child!");
tabs->remove_child(p_panel);
p_panel->queue_free();
@@ -1393,12 +1390,31 @@ void FindInFilesContainer::_on_dock_closed() {
}
void FindInFilesContainer::_on_tab_close_pressed(int p_tab) {
- FindInFilesPanel *panel = Object::cast_to<FindInFilesPanel>(tabs->get_tab_control(p_tab));
- if (panel) {
+ if (FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_tab_control(p_tab))) {
_close_panel(panel);
}
}
+void FindInFilesContainer::_set_replace_text(String p_text) {
+ FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_current_tab_control());
+ panel->set_replace_text(p_text);
+}
+
+void FindInFilesContainer::_replace_all() {
+ FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_current_tab_control());
+ panel->replace_all();
+}
+
+void FindInFilesContainer::_start_find_in_files() {
+ if (search_control->get_search_text().is_empty()) {
+ return;
+ }
+ FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_current_tab_control());
+ panel->set_with_replace(search_control->is_replace_pressed());
+ _update_current_title();
+ panel->start_search();
+}
+
void FindInFilesContainer::_update_bar_visibility() {
if (!update_bar) {
return;
@@ -1410,9 +1426,10 @@ void FindInFilesContainer::_update_bar_visibility() {
// Hide or show the search labels based on the visibility of the bar, as the search terms are displayed in the title of each tab.
for (int i = 0; i < tabs->get_tab_count(); i++) {
- FindInFilesPanel *panel = Object::cast_to<FindInFilesPanel>(tabs->get_tab_control(i));
+ FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_tab_control(i));
if (panel) {
panel->set_search_labels_visibility(!bar_visible);
+ panel->get_new_tab_button()->set_visible(!bar_visible);
}
}
}
@@ -1425,9 +1442,9 @@ void FindInFilesContainer::_bar_menu_option(int p_option) {
} break;
case PANEL_CLOSE_OTHERS: {
update_bar = false;
- FindInFilesPanel *panel = Object::cast_to<FindInFilesPanel>(tabs->get_tab_control(tab_index));
+ FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(tabs->get_tab_control(tab_index));
for (int i = tabs->get_tab_count() - 1; i >= 0; i--) {
- FindInFilesPanel *p = Object::cast_to<FindInFilesPanel>(tabs->get_tab_control(i));
+ FindInFilesResultsPanel *p = Object::cast_to<FindInFilesResultsPanel>(tabs->get_tab_control(i));
if (p != panel) {
_close_panel(p);
}
@@ -1467,7 +1484,7 @@ void FindInFilesContainer::_bar_input(const Ref<InputEvent> &p_input) {
void FindInFilesContainer::update_layout(EditorDock::DockLayout p_layout, int p_slot) {
for (Node *node : tabs->iterate_children()) {
- FindInFilesPanel *panel = Object::cast_to<FindInFilesPanel>(node);
+ FindInFilesResultsPanel *panel = Object::cast_to<FindInFilesResultsPanel>(node);
if (panel) {
panel->update_layout(p_layout, p_slot);
}
@@ -1485,9 +1502,9 @@ void FindInFilesContainer::_bind_methods() {
}
FindInFilesContainer::FindInFilesContainer() {
- set_name(TTRC("Search Results"));
+ set_name(TTRC("Find in Files"));
set_icon_name("Search");
- set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_search_results_bottom_panel", TTRC("Toggle Search Results Bottom Panel")));
+ set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_search_results_bottom_panel", TTRC("Toggle Find in Files Bottom Panel")));
set_default_slot(EditorDock::DOCK_SLOT_BOTTOM);
set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
set_global(false);
@@ -1495,16 +1512,31 @@ FindInFilesContainer::FindInFilesContainer() {
set_closable(true);
set_custom_minimum_size(Size2(0, 200 * EDSCALE));
+ hsplit = memnew(HSplitContainer);
+ add_child(hsplit);
+
+ search_control = memnew(FindInFilesSearchPanel);
+ search_control->connect("find_requested", callable_mp(this, &FindInFilesContainer::_start_find_in_files));
+ search_control->connect("replace_all_requested", callable_mp(this, &FindInFilesContainer::_replace_all));
+ search_control->get_replace_line_edit()->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesContainer::_set_replace_text));
+ hsplit->add_child(search_control);
+
tabs = memnew(TabContainer);
tabs->set_tabs_visible(false);
- add_child(tabs);
+ hsplit->add_child(tabs);
tabs->set_drag_to_rearrange_enabled(true);
+ tabs->connect("tab_changed", callable_mp(this, &FindInFilesContainer::_on_tab_changed).unbind(1));
tabs->get_tab_bar()->set_select_with_rmb(true);
tabs->get_tab_bar()->set_tab_close_display_policy(TabBar::CLOSE_BUTTON_SHOW_ACTIVE_ONLY);
tabs->get_tab_bar()->connect("tab_close_pressed", callable_mp(this, &FindInFilesContainer::_on_tab_close_pressed));
tabs->get_tab_bar()->connect(SceneStringName(gui_input), callable_mp(this, &FindInFilesContainer::_bar_input));
+ new_tab_button = memnew(Button);
+ new_tab_button->set_flat(true);
+ new_tab_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesContainer::_create_new_panel));
+ tabs->get_internal_container()->add_child(new_tab_button);
+
tabs_context_menu = memnew(PopupMenu);
add_child(tabs_context_menu);
tabs_context_menu->add_item(TTRC("Close Tab"), PANEL_CLOSE);
@@ -1516,60 +1548,16 @@ FindInFilesContainer::FindInFilesContainer() {
EditorNode::get_singleton()->get_gui_base()->connect(SceneStringName(theme_changed), callable_mp(this, &FindInFilesContainer::_on_theme_changed));
}
-void FindInFiles::_start_search(bool p_with_replace) {
- FindInFilesPanel *panel = container->get_panel_for_results((p_with_replace ? TTR("Replace:") : TTR("Find:")) + " " + dialog->get_search_text());
- FindInFilesSearch *search = panel->get_finder();
-
- search->set_search_text(dialog->get_search_text());
- search->set_match_case(dialog->is_match_case());
- search->set_whole_words(dialog->is_whole_words());
- search->set_folder(dialog->get_folder());
- search->set_filter(dialog->get_filter());
- search->set_includes(dialog->get_includes());
- search->set_excludes(dialog->get_excludes());
-
- panel->set_with_replace(p_with_replace);
- panel->set_replace_text(dialog->get_replace_text());
- panel->start_search();
-
- container->make_visible();
-}
-
-void FindInFiles::open_dialog(const String &p_initial_text, bool p_replace) {
- dialog->set_replace_mode(p_replace);
- dialog->set_search_text(p_initial_text);
- if (p_replace) {
- dialog->set_replace_text(String());
- }
- dialog->popup_centered();
-}
-
-void FindInFiles::_result_selected(const String &p_fpath, int p_line_number, int p_begin, int p_end) {
- emit_signal(SNAME("result_selected"), p_fpath, p_line_number, p_begin, p_end);
-}
-
-void FindInFiles::_files_modified() {
- emit_signal(SNAME("files_modified"));
-}
-
-void FindInFiles::_bind_methods() {
- ADD_SIGNAL(MethodInfo("result_selected",
- PropertyInfo(Variant::STRING, "path"),
- PropertyInfo(Variant::INT, "line_number"),
- PropertyInfo(Variant::INT, "begin"),
- PropertyInfo(Variant::INT, "end")));
- ADD_SIGNAL(MethodInfo("files_modified"));
+void FindInFiles::open_dock(const String &p_initial_text, bool p_replace) {
+ FindInFilesSearchPanel *search_control = container->get_search_control();
+ EditorDockManager::get_singleton()->focus_dock(container);
+ search_control->set_search_text(p_initial_text);
+ search_control->set_replace(p_replace);
}
FindInFiles::FindInFiles() {
- dialog = memnew(FindInFilesDialog);
- dialog->connect("find_requested", callable_mp(this, &FindInFiles::_start_search).bind(false));
- dialog->connect("replace_requested", callable_mp(this, &FindInFiles::_start_search).bind(true));
- EditorNode::get_singleton()->get_gui_base()->add_child(dialog);
-
+ find_in_files = this;
container = memnew(FindInFilesContainer);
EditorDockManager::get_singleton()->add_dock(container);
container->close();
- container->connect("result_selected", callable_mp(this, &FindInFiles::_result_selected));
- container->connect("files_modified", callable_mp(this, &FindInFiles::_files_modified));
}
diff --git a/editor/script/find_in_files.h b/editor/script/find_in_files.h
index 8ed49945f5a..3f2550e94f4 100644
--- a/editor/script/find_in_files.h
+++ b/editor/script/find_in_files.h
@@ -32,7 +32,7 @@
#include "core/templates/hash_map.h"
#include "editor/docks/editor_dock.h"
-#include "scene/gui/dialogs.h"
+#include "scene/gui/scroll_container.h"
// Performs the actual search.
class FindInFilesSearch : public Node {
@@ -40,14 +40,16 @@ class FindInFilesSearch : public Node {
// Config.
String pattern;
+ String include_string;
+ String exclude_string;
HashSet<String> extension_filter;
- HashSet<String> include_wildcards;
- HashSet<String> exclude_wildcards;
String root_dir;
- bool whole_words = true;
- bool match_case = true;
+ bool whole_words = false;
+ bool match_case = false;
// State.
+ HashSet<String> include_wildcards;
+ HashSet<String> exclude_wildcards;
bool searching = false;
String current_dir;
Vector<PackedStringArray> folders_stack;
@@ -61,20 +63,31 @@ class FindInFilesSearch : public Node {
bool _is_file_matched(const HashSet<String> &p_wildcards, const String &p_file_path, bool p_case_sensitive) const;
+ void _calculate_wildcard(const String &p_text, HashSet<String> *r_hash_set);
+ String _validate_filter_wildcard(const String &p_expression) const;
+
protected:
void _notification(int p_what);
static void _bind_methods();
public:
+ void copy_from(const FindInFilesSearch *p_other);
+
void set_search_text(const String &p_pattern);
void set_whole_words(bool p_whole_word);
void set_match_case(bool p_match_case);
- void set_folder(const String &p_folder);
void set_filter(const HashSet<String> &p_exts);
- void set_includes(const HashSet<String> &p_include_wildcards);
- void set_excludes(const HashSet<String> &p_exclude_wildcards);
+ void set_includes(const String &p_include_wildcards);
+ void set_excludes(const String &p_exclude_wildcards);
+ void set_folder(const String &p_folder);
String get_search_text() const { return pattern; }
+ bool get_whole_words() { return whole_words; }
+ bool get_match_case() { return match_case; }
+ HashSet<String> *get_filter() { return &extension_filter; }
+ String get_includes() { return include_string; }
+ String get_excludes() { return exclude_string; }
+ String get_folder() { return root_dir; }
bool is_whole_words() const { return whole_words; }
bool is_match_case() const { return match_case; }
@@ -90,71 +103,87 @@ class LineEdit;
class CheckBox;
class FileDialog;
class HBoxContainer;
+class SpinBox;
+class Timer;
+class Button;
+class VBoxContainer;
+class HFlowContainer;
+class ConfirmationDialog;
// Prompts search parameters.
-class FindInFilesDialog : public AcceptDialog {
- GDCLASS(FindInFilesDialog, AcceptDialog);
+class FindInFilesSearchPanel : public ScrollContainer {
+ GDCLASS(FindInFilesSearchPanel, ScrollContainer);
void _on_folder_button_pressed();
void _on_folder_selected(String p_path);
- void _on_search_text_modified(const String &p_text);
- void _on_search_text_submitted(const String &p_text);
- void _on_replace_text_submitted(const String &p_text);
- String _validate_filter_wildcard(const String &p_expression) const;
+ void _on_search_modified();
+ void _on_search_submitted();
+ void _emit_find_requested();
+ void _toggle_replace_pressed(bool p_with_replace);
+ void _on_replace_all_clicked(bool p_dialog);
+ void _on_additional_options_toggled(bool p_toggled);
+ void _on_add_new_tab_clicked();
+ void _on_filter_toggled(bool p_pressed, const String &p_ext);
+ void _update_finder();
+ void _update_file_extensions(bool p_init);
+ void _highlight_search_text();
- bool extensions_dirty = true;
- bool replace_mode = false;
+ FindInFilesSearch *finder = nullptr;
+ Timer *debounce_timer = nullptr;
+ CheckBox *toggle_replace_button = nullptr;
LineEdit *search_text_line_edit = nullptr;
- Label *replace_label = nullptr;
- LineEdit *replace_text_line_edit = nullptr;
-
- LineEdit *folder_line_edit = nullptr;
- CheckBox *match_case_checkbox = nullptr;
- CheckBox *whole_words_checkbox = nullptr;
+ HBoxContainer *folder_hbc = nullptr;
+ Button *additional_options_button = nullptr;
+ VBoxContainer *additional_options_vbc = nullptr;
+ Button *match_case_checkbox = nullptr;
+ Button *whole_words_checkbox = nullptr;
Button *find_button = nullptr;
- Button *replace_button = nullptr;
+
+ HBoxContainer *replace_hbox = nullptr;
+ LineEdit *replace_line_edit = nullptr;
+ Button *replace_all_button = nullptr;
+ ConfirmationDialog *replace_all_confirm = nullptr;
+ CheckBox *dont_show_checkbox = nullptr;
+
+ Label *filters_label = nullptr;
FileDialog *folder_dialog = nullptr;
- HBoxContainer *filters_container = nullptr;
+ HFlowContainer *filters_container = nullptr;
+ HashMap<String, bool> filters_preferences;
+ LineEdit *folder_line_edit = nullptr;
LineEdit *includes_line_edit = nullptr;
LineEdit *excludes_line_edit = nullptr;
- HashMap<String, bool> filters_preferences;
-
protected:
void _notification(int p_what);
- virtual void custom_action(const String &p_action) override;
static void _bind_methods();
public:
+ void set_finder(FindInFilesSearch *p_finder, bool p_init);
+
void set_search_text(const String &p_text);
void set_replace_text(const String &p_text);
-
- void set_replace_mode(bool p_replace);
+ void set_replace(bool p_replace_mode);
String get_search_text() const;
- String get_replace_text() const;
- bool is_match_case() const;
- bool is_whole_words() const;
- String get_folder() const;
+ bool is_replace_pressed() const;
HashSet<String> get_filter() const;
- HashSet<String> get_includes() const;
- HashSet<String> get_excludes() const;
- FindInFilesDialog();
+ LineEdit *get_replace_line_edit() const { return replace_line_edit; }
+
+ FindInFilesSearchPanel();
};
class Button;
-class CheckButton;
class Tree;
class TreeItem;
class ProgressBar;
// Display search results.
-class FindInFilesPanel : public MarginContainer {
- GDCLASS(FindInFilesPanel, MarginContainer);
+class FindInFilesResultsPanel : public MarginContainer {
+ GDCLASS(FindInFilesResultsPanel, MarginContainer);
enum FindButtons {
FIND_BUTTON_REPLACE,
@@ -173,38 +202,32 @@ class FindInFilesPanel : public MarginContainer {
Label *search_text_label = nullptr;
Tree *results_display = nullptr;
Label *status_label = nullptr;
- CheckButton *keep_results_button = nullptr;
+ Button *new_tab_button = nullptr;
Button *refresh_button = nullptr;
Button *cancel_button = nullptr;
- Button *close_button = nullptr;
+ Control *progress_bar_placeholder = nullptr;
ProgressBar *progress_bar = nullptr;
HashMap<String, TreeItem *> file_items;
HashMap<TreeItem *, int> file_items_results_count;
HashMap<TreeItem *, Result> result_items;
bool with_replace = false;
- HBoxContainer *replace_container = nullptr;
- LineEdit *replace_line_edit = nullptr;
- Button *replace_all_button = nullptr;
+ String replace_text;
MarginContainer *results_mc = nullptr;
void _on_button_clicked(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index);
+ void _remove_result(TreeItem *p_item);
void _on_result_found(const String &p_fpath, int p_line_number, int p_begin, int p_end, const String &p_text);
void _on_theme_changed();
void _on_finished();
void _on_refresh_button_clicked();
void _on_cancel_button_clicked();
- void _on_close_button_clicked();
void _on_result_selected();
void _on_item_edited();
- void _on_replace_text_changed(const String &p_text);
- void _on_replace_all_clicked();
void _apply_replaces_in_file(const String &p_fpath, const Vector<Result> &p_locations, const String &p_new_text);
- void _update_replace_buttons();
void _update_matches_text();
- String _get_replace_text();
void _draw_result_text(Object *p_item_obj, const Rect2 &p_rect);
@@ -216,27 +239,29 @@ protected:
public:
FindInFilesSearch *get_finder() const { return finder; }
+ Button *get_new_tab_button() { return new_tab_button; }
+ String get_replace_text() { return replace_text; }
void set_with_replace(bool p_with_replace);
void set_replace_text(const String &p_text);
- bool is_keep_results() const;
void set_search_labels_visibility(bool p_visible);
void start_search();
void stop_search();
+ void replace_all();
void update_layout(EditorDock::DockLayout p_layout, int p_slot);
- FindInFilesPanel();
+ FindInFilesResultsPanel();
};
class PopupMenu;
class TabContainer;
+class HSplitContainer;
-// Contains several FindInFilesPanels. A FindInFilesPanel contains the results of a
-// `Find in Files` search or a `Replace in Files` search, while a
-// FindInFilesContainer can contain several FindInFilesPanels so that multiple search
-// results can remain at the same time.
+// Contains several FindInFilesResultsPanels. A FindInFilesResultsPanel contains the results of a
+// FindInFilesSearchPanel search, while a FindInFilesContainer can contain several FindInFilesResultsPanels
+// so that multiple search results can remain at the same time.
class FindInFilesContainer : public EditorDock {
GDCLASS(FindInFilesContainer, EditorDock);
@@ -247,23 +272,30 @@ class FindInFilesContainer : public EditorDock {
PANEL_CLOSE_ALL,
};
+ HSplitContainer *hsplit = nullptr;
+ FindInFilesSearchPanel *search_control = nullptr;
TabContainer *tabs = nullptr;
+ Button *new_tab_button = nullptr;
bool update_bar = true;
PopupMenu *tabs_context_menu = nullptr;
void _on_tab_close_pressed(int p_tab);
+ void _on_tab_changed();
void _update_bar_visibility();
void _bar_menu_option(int p_option);
void _bar_input(const Ref<InputEvent> &p_input);
void _on_theme_changed();
- FindInFilesPanel *_create_new_panel();
- FindInFilesPanel *_get_current_panel();
+ FindInFilesResultsPanel *_create_new_panel();
+ void _update_current_title();
void _result_selected(const String &p_fpath, int p_line_number, int p_begin, int p_end);
void _files_modified();
- void _close_panel(FindInFilesPanel *p_panel);
+ void _close_panel(FindInFilesResultsPanel *p_panel);
+ void _set_replace_text(String p_text);
+ void _replace_all();
void _on_dock_closed();
+ void _start_find_in_files();
protected:
void _notification(int p_what);
@@ -272,7 +304,7 @@ protected:
public:
virtual void update_layout(EditorDock::DockLayout p_layout, int p_slot) override;
- FindInFilesPanel *get_panel_for_results(const String &p_label);
+ FindInFilesSearchPanel *get_search_control() { return search_control; }
FindInFilesContainer();
};
@@ -280,18 +312,16 @@ public:
class FindInFiles : public Object {
GDCLASS(FindInFiles, Object);
- FindInFilesDialog *dialog = nullptr;
FindInFilesContainer *container = nullptr;
- void _start_search(bool p_with_replace);
- void _result_selected(const String &p_fpath, int p_line_number, int p_begin, int p_end);
- void _files_modified();
-
-protected:
- static void _bind_methods();
+ static inline FindInFiles *find_in_files = nullptr;
public:
- void open_dialog(const String &p_initial_text, bool p_replace = false);
+ static FindInFiles *get_singleton() { return find_in_files; }
+
+ FindInFilesContainer *get_container() { return container; }
+
+ void open_dock(const String &p_initial_text = "", bool p_replace = false);
FindInFiles();
};
diff --git a/editor/script/script_editor_base.cpp b/editor/script/script_editor_base.cpp
index be144e6d196..5548e7eeb8a 100644
--- a/editor/script/script_editor_base.cpp
+++ b/editor/script/script_editor_base.cpp
@@ -34,6 +34,7 @@
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "editor/editor_node.h"
+#include "editor/script/find_in_files.h"
#include "editor/script/script_editor_navigation_marker.h"
#include "editor/script/script_editor_plugin.h"
#include "editor/script/syntax_highlighters.h"
@@ -268,7 +269,7 @@ TextEditorBase::EditMenus::EditMenus(ScriptEditor *p_se) {
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
search_menu->get_popup()->add_separator();
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("editor/find_in_files"), SEARCH_IN_FILES);
- search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES);
+ search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("editor/replace_in_files"), REPLACE_IN_FILES);
search_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &EditMenus::_edit_option));
goto_menu = memnew(MenuButton);
@@ -512,13 +513,10 @@ bool TextEditorBase::_edit_option(int p_op) {
case SEARCH_REPLACE: {
code_editor->get_find_replace_bar()->popup_replace();
} break;
- case SEARCH_IN_FILES: {
- String selected_text = tx->get_selected_text();
- ScriptEditor::get_singleton()->open_find_in_files_dialog(selected_text);
- } break;
+ case SEARCH_IN_FILES:
case REPLACE_IN_FILES: {
String selected_text = tx->get_selected_text();
- ScriptEditor::get_singleton()->open_find_in_files_dialog(selected_text, true);
+ FindInFiles::get_singleton()->open_dock(selected_text, p_op == REPLACE_IN_FILES);
} break;
case SEARCH_GOTO_LINE: {
goto_line_popup->popup_find_line(code_editor);
diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp
index ca48143db53..2b4eda3ef5b 100644
--- a/editor/script/script_editor_plugin.cpp
+++ b/editor/script/script_editor_plugin.cpp
@@ -1715,12 +1715,10 @@ void ScriptEditor::_menu_option(int p_option) {
}
}
} break;
- case SEARCH_IN_FILES: {
- open_find_in_files_dialog("");
- } break;
+ case SEARCH_IN_FILES:
case REPLACE_IN_FILES: {
- open_find_in_files_dialog("", true);
- } break;
+ FindInFiles::get_singleton()->open_dock("", REPLACE_IN_FILES == p_option);
+ }; break;
case SEARCH_HELP: {
script_editor->help_search_dialog->popup_dialog();
} break;
@@ -2498,8 +2496,6 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
teb->connect("go_to_help", callable_mp(this, &ScriptEditor::_help_class_goto));
teb->connect("_request_save_new_history", callable_mp(this, &ScriptEditor::_save_new_history).bind(teb));
teb->connect("_request_save_previous_state", callable_mp(this, &ScriptEditor::_save_previous_state).bind(teb));
- teb->connect("search_in_files_requested", callable_mp(this, &ScriptEditor::open_find_in_files_dialog).bind(false));
- teb->connect("replace_in_files_requested", callable_mp(this, &ScriptEditor::open_find_in_files_dialog).bind(true));
teb->connect("go_to_method", callable_mp(this, &ScriptEditor::script_goto_method));
if (script_editor_cache->has_section(p_resource->get_path())) {
@@ -2775,10 +2771,6 @@ void ScriptEditor::_auto_format_text(ScriptEditorBase *p_seb) {
}
}
-void ScriptEditor::open_find_in_files_dialog(const String &p_initial_text, bool p_replace) {
- script_editor->find_in_files->open_dialog(p_initial_text, p_replace);
-}
-
void ScriptEditor::open_script_create_dialog(const String &p_base_name, const String &p_base_path) {
_menu_option(FILE_MENU_NEW_SCRIPT);
script_create_dialog->config(p_base_name, p_base_path);
@@ -3675,12 +3667,12 @@ void ScriptEditor::_update_selected_editor_menu() {
search_popup->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTRC("Find Previous"), KeyModifierMask::SHIFT | Key::F3), HELP_SEARCH_FIND_PREVIOUS);
search_popup->add_separator();
search_popup->add_shortcut(ED_GET_SHORTCUT("editor/find_in_files"), SEARCH_IN_FILES);
- search_popup->add_shortcut(ED_GET_SHORTCUT("script_editor/replace_in_files"), REPLACE_IN_FILES);
+ search_popup->add_shortcut(ED_GET_SHORTCUT("editor/replace_in_files"), REPLACE_IN_FILES);
script_search_menu->show();
} else {
if (tab_container->get_tab_count() == 0) {
search_popup->add_shortcut(ED_GET_SHORTCUT("editor/find_in_files"), SEARCH_IN_FILES);
- search_popup->add_shortcut(ED_GET_SHORTCUT("script_editor/replace_in_files"), REPLACE_IN_FILES);
+ search_popup->add_shortcut(ED_GET_SHORTCUT("editor/replace_in_files"), REPLACE_IN_FILES);
script_search_menu->show();
} else {
script_search_menu->hide();
@@ -4328,7 +4320,7 @@ ScriptEditor::ScriptEditor(const String &p_config_section, const String &p_cache
add_child(help_search_dialog);
help_search_dialog->connect("go_to_help", callable_mp(this, &ScriptEditor::_help_class_goto));
- find_in_files = memnew(FindInFiles);
+ FindInFilesContainer *find_in_files = FindInFiles::get_singleton()->get_container();
find_in_files->connect("result_selected", callable_mp(this, &ScriptEditor::_on_find_in_files_result_selected));
find_in_files->connect("files_modified", callable_mp(this, &ScriptEditor::_on_find_in_files_modified_files));
}
@@ -4360,9 +4352,6 @@ ScriptEditor::ScriptEditor(const String &p_config_section, const String &p_cache
ScriptEditor::~ScriptEditor() {
ScriptEditorNavigationMarker::release_singleton();
- if (this == script_editor) {
- memdelete(find_in_files);
- }
}
void ScriptEditorPlugin::_focus_another_editor() {
@@ -4594,7 +4583,6 @@ ScriptEditorPlugin::ScriptEditorPlugin() {
ED_SHORTCUT("script_editor/reopen_closed_script", TTRC("Reopen Closed Script"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::T);
ED_SHORTCUT("script_editor/clear_recent", TTRC("Clear Recent Scripts"));
- ED_SHORTCUT("script_editor/replace_in_files", TTRC("Replace in Files..."), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::R);
ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTRC("Uppercase"), KeyModifierMask::SHIFT | Key::F4);
ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTRC("Lowercase"), KeyModifierMask::SHIFT | Key::F5);
@@ -4603,6 +4591,7 @@ ScriptEditorPlugin::ScriptEditorPlugin() {
window_wrapper = memnew(WindowWrapper);
window_wrapper->set_margins_enabled(true);
+ memnew(FindInFiles);
script_editor = memnew(ScriptEditor("ScriptEditor", "script_editor_cache.cfg", window_wrapper));
script_editor->set_handled_resource_types({ "GDScript", "Script", "JSON" });
Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("script_editor/make_floating", TTRC("Make Floating"));
@@ -4615,3 +4604,7 @@ ScriptEditorPlugin::ScriptEditorPlugin() {
ScriptServer::set_reload_scripts_on_save(EDITOR_GET("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save"));
}
+
+ScriptEditorPlugin::~ScriptEditorPlugin() {
+ memdelete(FindInFiles::get_singleton());
+}
diff --git a/editor/script/script_editor_plugin.h b/editor/script/script_editor_plugin.h
index e5ac8156132..f8425fd4b44 100644
--- a/editor/script/script_editor_plugin.h
+++ b/editor/script/script_editor_plugin.h
@@ -272,8 +272,6 @@ class ScriptEditor : public PanelContainer {
Button *script_back = nullptr;
Button *script_forward = nullptr;
- FindInFiles *find_in_files = nullptr;
-
WindowWrapper *window_wrapper = nullptr;
#ifdef ANDROID_ENABLED
@@ -464,7 +462,6 @@ public:
bool is_files_panel_toggled();
void apply_scripts() const;
void reload_scripts(bool p_refresh_only = false);
- void open_find_in_files_dialog(const String &p_initial_text = "", bool p_replace = false);
void open_script_create_dialog(const String &p_base_name, const String &p_base_path);
void open_text_file_create_dialog(const String &p_base_path, const String &p_base_name = "");
Ref<Resource> open_file(const String &p_file);
@@ -571,4 +568,5 @@ public:
virtual void edited_scene_changed() override { script_editor->edited_scene_changed(); }
ScriptEditorPlugin();
+ ~ScriptEditorPlugin();
};
diff --git a/editor/script/script_text_editor.cpp b/editor/script/script_text_editor.cpp
index eabc2170d5b..38c16b1eab1 100644
--- a/editor/script/script_text_editor.cpp
+++ b/editor/script/script_text_editor.cpp
@@ -2570,8 +2570,6 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT_AND_COMMAND("script_text_editor/replace", TTRC("Replace..."), KeyModifierMask::CTRL | Key::R);
ED_SHORTCUT_OVERRIDE("script_text_editor/replace", "macos", KeyModifierMask::ALT | KeyModifierMask::META | Key::F);
- ED_SHORTCUT("script_text_editor/replace_in_files", TTRC("Replace in Files..."), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::R);
-
ED_SHORTCUT("script_text_editor/show_tooltip", TTRC("Show Tooltip"), KeyModifierMask::ALT | Key::SLASH, true);
ED_SHORTCUT("script_text_editor/contextual_help", TTRC("Contextual Help"), KeyModifierMask::ALT | Key::F1);
ED_SHORTCUT_OVERRIDE("script_text_editor/contextual_help", "macos", KeyModifierMask::ALT | KeyModifierMask::SHIFT | Key::SPACE);
diff --git a/editor/settings/editor_settings.cpp b/editor/settings/editor_settings.cpp
index 715fe8a145b..110ad08649f 100644
--- a/editor/settings/editor_settings.cpp
+++ b/editor/settings/editor_settings.cpp
@@ -1358,6 +1358,7 @@ void EditorSettings::_handle_setting_compatibility() {
_rename_shortcut("script_editor/window_move_up", "script_editor/move_document_up");
_rename_shortcut("script_editor/window_move_down", "script_editor/move_document_down");
_rename_shortcut("script_editor/window_sort", "script_editor/sort_documents");
+ _rename_shortcut("script_text_editor/replace_in_files", "editor/replace_in_files");
}
void EditorSettings::_rename_setting(const String &p_old_name, const String &p_new_name) {