diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-05-29 16:58:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 16:58:28 +0200 |
commit | 62c9af4072860168a475ab95a0e1f5bcca348017 (patch) | |
tree | 44b3ef109e1286473fc91a7c0e2d92af86cba391 | |
parent | b374a9ff69d272e472c619417bf3ed251037eb19 (diff) | |
parent | c4eb974a8a73eabc29dd3be47b09969a4348fa20 (diff) |
Merge pull request #25647 from QbieShay/fix_25440
Added a setting for files in which the editor should search (project specific)
-rw-r--r-- | core/project_settings.cpp | 9 | ||||
-rw-r--r-- | editor/find_in_files.cpp | 48 | ||||
-rw-r--r-- | editor/find_in_files.h | 5 |
3 files changed, 38 insertions, 24 deletions
diff --git a/core/project_settings.cpp b/core/project_settings.cpp index c86d1567dd..2fd22d4789 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -1007,6 +1007,15 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("audio/default_bus_layout", "res://default_bus_layout.tres"); custom_prop_info["audio/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"); + PoolStringArray extensions = PoolStringArray(); + extensions.push_back("gd"); + if (Engine::get_singleton()->has_singleton("GodotSharp")) + extensions.push_back("cs"); + extensions.push_back("shader"); + + GLOBAL_DEF("editor/search_in_file_extensions", extensions); + custom_prop_info["editor/search_in_file_extensions"] = PropertyInfo(Variant::POOL_STRING_ARRAY, "editor/search_in_file_extensions"); + action = Dictionary(); action["deadzone"] = Variant(0.5f); events = Array(); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 11af9fc2eb..e1ab5c62a7 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -367,28 +367,11 @@ FindInFilesDialog::FindInFilesDialog() { Label *filter_label = memnew(Label); filter_label->set_text(TTR("Filters:")); + filter_label->set_tooltip(TTR("Include the files with the following extensions. Add or remove them in ProjectSettings.")); gc->add_child(filter_label); - { - HBoxContainer *hbc = memnew(HBoxContainer); - - // TODO: Unhardcode this. - Vector<String> exts; - exts.push_back("gd"); - 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); - cb->set_text(exts[i]); - cb->set_pressed(true); - hbc->add_child(cb); - _filters.push_back(cb); - } - - gc->add_child(hbc); - } + _filters_container = memnew(HBoxContainer); + gc->add_child(_filters_container); _find_button = add_button(TTR("Find..."), false, "find"); _find_button->set_disabled(true); @@ -424,11 +407,12 @@ String FindInFilesDialog::get_folder() const { } Set<String> FindInFilesDialog::get_filter() const { + // could check the _filters_preferences but it might not have been generated yet. Set<String> filters; - for (int i = 0; i < _filters.size(); ++i) { - CheckBox *cb = _filters[i]; + for (int i = 0; i < _filters_container->get_child_count(); ++i) { + CheckBox *cb = (CheckBox *)_filters_container->get_child(i); if (cb->is_pressed()) { - filters.insert(_filters[i]->get_text()); + filters.insert(cb->get_text()); } } return filters; @@ -440,6 +424,20 @@ void FindInFilesDialog::_notification(int p_what) { // Doesn't work more than once if not deferred... _search_text_line_edit->call_deferred("grab_focus"); _search_text_line_edit->select_all(); + // Extensions might have changed in the meantime, we clean them and instance them again. + for (int i = 0; i < _filters_container->get_child_count(); i++) { + _filters_container->get_child(i)->queue_delete(); + } + Array exts = ProjectSettings::get_singleton()->get("editor/search_in_file_extensions"); + for (int i = 0; i < exts.size(); ++i) { + CheckBox *cb = memnew(CheckBox); + cb->set_text(exts[i]); + if (!_filters_preferences.has(exts[i])) { + _filters_preferences[exts[i]] = true; + } + cb->set_pressed(_filters_preferences[exts[i]]); + _filters_container->add_child(cb); + } } } } @@ -449,6 +447,10 @@ void FindInFilesDialog::_on_folder_button_pressed() { } void FindInFilesDialog::custom_action(const String &p_action) { + for (int i = 0; i < _filters_container->get_child_count(); ++i) { + CheckBox *cb = (CheckBox *)_filters_container->get_child(i); + _filters_preferences[cb->get_text()] = cb->is_pressed(); + } if (p_action == "find") { emit_signal(SIGNAL_FIND_REQUESTED); hide(); diff --git a/editor/find_in_files.h b/editor/find_in_files.h index 220f8cc136..5f728a104b 100644 --- a/editor/find_in_files.h +++ b/editor/find_in_files.h @@ -31,6 +31,7 @@ #ifndef FIND_IN_FILES_H #define FIND_IN_FILES_H +#include "core/hash_map.h" #include "scene/gui/dialogs.h" // Performs the actual search @@ -88,6 +89,7 @@ private: class LineEdit; class CheckBox; class FileDialog; +class HBoxContainer; // Prompts search parameters class FindInFilesDialog : public AcceptDialog { @@ -120,12 +122,13 @@ private: LineEdit *_search_text_line_edit; LineEdit *_folder_line_edit; - Vector<CheckBox *> _filters; CheckBox *_match_case_checkbox; CheckBox *_whole_words_checkbox; Button *_find_button; Button *_replace_button; FileDialog *_folder_dialog; + HBoxContainer *_filters_container; + HashMap<String, bool> _filters_preferences; }; class Button; |