diff options
Diffstat (limited to 'editor/find_in_files.cpp')
-rw-r--r-- | editor/find_in_files.cpp | 119 |
1 files changed, 39 insertions, 80 deletions
diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 11d0b67bd6..6ebe8cfe2c 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -29,8 +29,10 @@ /*************************************************************************/ #include "find_in_files.h" + #include "core/os/dir_access.h" #include "core/os/os.h" +#include "editor_node.h" #include "editor_scale.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" @@ -42,8 +44,6 @@ #include "scene/gui/progress_bar.h" #include "scene/gui/tree.h" -#define ROOT_PREFIX "res://" - const char *FindInFiles::SIGNAL_RESULT_FOUND = "result_found"; const char *FindInFiles::SIGNAL_FINISHED = "finished"; @@ -87,9 +87,6 @@ static bool find_next(const String &line, String pattern, int from, bool match_c //-------------------------------------------------------------------------------- FindInFiles::FindInFiles() { - _root_prefix = ROOT_PREFIX; - _extension_filter.insert("gd"); - _extension_filter.insert("cs"); _searching = false; _whole_words = true; _match_case = true; @@ -182,7 +179,7 @@ void FindInFiles::_iterate() { _current_dir = _current_dir.plus_file(folder_name); PoolStringArray sub_dirs; - _scan_dir(_root_prefix + _current_dir, sub_dirs); + _scan_dir("res://" + _current_dir, sub_dirs); _folders_stack.push_back(sub_dirs); @@ -300,9 +297,8 @@ const char *FindInFilesDialog::SIGNAL_REPLACE_REQUESTED = "replace_requested"; FindInFilesDialog::FindInFilesDialog() { - set_custom_minimum_size(Size2(400, 190)); - set_resizable(true); - set_title(TTR("Find in files")); + set_custom_minimum_size(Size2(500 * EDSCALE, 0)); + set_title(TTR("Find in Files")); VBoxContainer *vbc = memnew(VBoxContainer); vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); @@ -316,7 +312,7 @@ FindInFilesDialog::FindInFilesDialog() { vbc->add_child(gc); Label *find_label = memnew(Label); - find_label->set_text(TTR("Find: ")); + find_label->set_text(TTR("Find:")); gc->add_child(find_label); _search_text_line_edit = memnew(LineEdit); @@ -325,36 +321,31 @@ FindInFilesDialog::FindInFilesDialog() { _search_text_line_edit->connect("text_entered", this, "_on_search_text_entered"); gc->add_child(_search_text_line_edit); - { - Control *placeholder = memnew(Control); - gc->add_child(placeholder); - } + gc->add_child(memnew(Control)); // Space to mantain the grid aligned. { HBoxContainer *hbc = memnew(HBoxContainer); _whole_words_checkbox = memnew(CheckBox); - _whole_words_checkbox->set_text(TTR("Whole words")); - _whole_words_checkbox->set_pressed(true); + _whole_words_checkbox->set_text(TTR("Whole Words")); hbc->add_child(_whole_words_checkbox); _match_case_checkbox = memnew(CheckBox); - _match_case_checkbox->set_text(TTR("Match case")); - _match_case_checkbox->set_pressed(true); + _match_case_checkbox->set_text(TTR("Match Case")); hbc->add_child(_match_case_checkbox); gc->add_child(hbc); } Label *folder_label = memnew(Label); - folder_label->set_text(TTR("Folder: ")); + folder_label->set_text(TTR("Folder:")); gc->add_child(folder_label); { HBoxContainer *hbc = memnew(HBoxContainer); Label *prefix_label = memnew(Label); - prefix_label->set_text(ROOT_PREFIX); + prefix_label->set_text("res://"); hbc->add_child(prefix_label); _folder_line_edit = memnew(LineEdit); @@ -375,15 +366,18 @@ FindInFilesDialog::FindInFilesDialog() { } Label *filter_label = memnew(Label); - filter_label->set_text(TTR("Filter: ")); + filter_label->set_text(TTR("Filters:")); gc->add_child(filter_label); { HBoxContainer *hbc = memnew(HBoxContainer); + // TODO: Unhardcode this. Vector<String> exts; exts.push_back("gd"); - exts.push_back("cs"); + if (Engine::get_singleton()->has_singleton("GodotSharp")) + exts.push_back("cs"); + exts.push_back("shader"); for (int i = 0; i < exts.size(); ++i) { CheckBox *cb = memnew(CheckBox); @@ -396,47 +390,14 @@ FindInFilesDialog::FindInFilesDialog() { gc->add_child(hbc); } - { - Control *placeholder = memnew(Control); - placeholder->set_custom_minimum_size(Size2(0, EDSCALE * 16)); - vbc->add_child(placeholder); - } - - { - HBoxContainer *hbc = memnew(HBoxContainer); - hbc->set_alignment(HBoxContainer::ALIGN_CENTER); - - _find_button = memnew(Button); - _find_button->set_text(TTR("Find...")); - _find_button->connect("pressed", this, "_on_find_button_pressed"); - _find_button->set_disabled(true); - hbc->add_child(_find_button); - - { - Control *placeholder = memnew(Control); - placeholder->set_custom_minimum_size(Size2(EDSCALE * 16, 0)); - hbc->add_child(placeholder); - } - - _replace_button = memnew(Button); - _replace_button->set_text(TTR("Replace...")); - _replace_button->connect("pressed", this, "_on_replace_button_pressed"); - _replace_button->set_disabled(true); - hbc->add_child(_replace_button); + _find_button = add_button(TTR("Find..."), false, "find"); + _find_button->set_disabled(true); - { - Control *placeholder = memnew(Control); - placeholder->set_custom_minimum_size(Size2(EDSCALE * 16, 0)); - hbc->add_child(placeholder); - } + _replace_button = add_button(TTR("Replace..."), false, "replace"); + _replace_button->set_disabled(true); - Button *cancel_button = memnew(Button); - cancel_button->set_text(TTR("Cancel")); - cancel_button->connect("pressed", this, "hide"); - hbc->add_child(cancel_button); - - vbc->add_child(hbc); - } + Button *cancel_button = get_ok(); + cancel_button->set_text(TTR("Cancel")); } void FindInFilesDialog::set_search_text(String text) { @@ -487,14 +448,14 @@ void FindInFilesDialog::_on_folder_button_pressed() { _folder_dialog->popup_centered_ratio(); } -void FindInFilesDialog::_on_find_button_pressed() { - emit_signal(SIGNAL_FIND_REQUESTED); - hide(); -} - -void FindInFilesDialog::_on_replace_button_pressed() { - emit_signal(SIGNAL_REPLACE_REQUESTED); - hide(); +void FindInFilesDialog::custom_action(const String &p_action) { + if (p_action == "find") { + emit_signal(SIGNAL_FIND_REQUESTED); + hide(); + } else if (p_action == "replace") { + emit_signal(SIGNAL_REPLACE_REQUESTED); + hide(); + } } void FindInFilesDialog::_on_search_text_modified(String text) { @@ -509,7 +470,7 @@ void FindInFilesDialog::_on_search_text_modified(String text) { void FindInFilesDialog::_on_search_text_entered(String text) { // This allows to trigger a global search without leaving the keyboard if (!_find_button->is_disabled()) - _on_find_button_pressed(); + custom_action("find"); } void FindInFilesDialog::_on_folder_selected(String path) { @@ -522,8 +483,6 @@ void FindInFilesDialog::_on_folder_selected(String path) { void FindInFilesDialog::_bind_methods() { ClassDB::bind_method("_on_folder_button_pressed", &FindInFilesDialog::_on_folder_button_pressed); - ClassDB::bind_method("_on_find_button_pressed", &FindInFilesDialog::_on_find_button_pressed); - ClassDB::bind_method("_on_replace_button_pressed", &FindInFilesDialog::_on_replace_button_pressed); ClassDB::bind_method("_on_folder_selected", &FindInFilesDialog::_on_folder_selected); ClassDB::bind_method("_on_search_text_modified", &FindInFilesDialog::_on_search_text_modified); ClassDB::bind_method("_on_search_text_entered", &FindInFilesDialog::_on_search_text_entered); @@ -558,7 +517,7 @@ FindInFilesPanel::FindInFilesPanel() { hbc->add_child(find_label); _search_text_label = memnew(Label); - _search_text_label->add_font_override("font", get_font("source", "EditorFonts")); + _search_text_label->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("source", "EditorFonts")); hbc->add_child(_search_text_label); _progress_bar = memnew(ProgressBar); @@ -572,14 +531,14 @@ FindInFilesPanel::FindInFilesPanel() { _cancel_button = memnew(Button); _cancel_button->set_text(TTR("Cancel")); _cancel_button->connect("pressed", this, "_on_cancel_button_clicked"); - _cancel_button->set_disabled(true); + _cancel_button->hide(); hbc->add_child(_cancel_button); vbc->add_child(hbc); } _results_display = memnew(Tree); - _results_display->add_font_override("font", get_font("source", "EditorFonts")); + _results_display->add_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_font("source", "EditorFonts")); _results_display->set_v_size_flags(SIZE_EXPAND_FILL); _results_display->connect("item_selected", this, "_on_result_selected"); _results_display->connect("item_edited", this, "_on_item_edited"); @@ -651,7 +610,7 @@ void FindInFilesPanel::start_search() { _finder->start(); update_replace_buttons(); - _cancel_button->set_disabled(false); + _cancel_button->show(); } void FindInFilesPanel::stop_search() { @@ -661,7 +620,7 @@ void FindInFilesPanel::stop_search() { _status_label->set_text(""); update_replace_buttons(); set_progress_visible(false); - _cancel_button->set_disabled(true); + _cancel_button->hide(); } void FindInFilesPanel::_notification(int p_what) { @@ -697,7 +656,7 @@ void FindInFilesPanel::_on_result_found(String fpath, int line_number, int begin // Do this first because it resets properties of the cell... item->set_cell_mode(text_index, TreeItem::CELL_MODE_CUSTOM); - String item_text = String::num_int64(line_number) + ": " + text.replace("\t", " "); + String item_text = vformat("%3s: %s", line_number, text.replace("\t", " ")); item->set_text(text_index, item_text); item->set_custom_draw(text_index, this, "_draw_result_text"); @@ -712,7 +671,7 @@ void FindInFilesPanel::_on_result_found(String fpath, int line_number, int begin r.begin = begin; r.end = end; r.draw_begin = (item_text_width - raw_text_width) + font->get_string_size(text.left(r.begin)).x; - r.draw_width = font->get_string_size(text.substr(r.begin, r.end - r.begin + 1)).x; + r.draw_width = font->get_string_size(text.substr(r.begin, r.end - r.begin)).x; _result_items[item] = r; if (_with_replace) { @@ -763,7 +722,7 @@ void FindInFilesPanel::_on_finished() { _status_label->set_text(TTR("Search complete")); update_replace_buttons(); set_progress_visible(false); - _cancel_button->set_disabled(true); + _cancel_button->hide(); } void FindInFilesPanel::_on_cancel_button_clicked() { |