Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically start searching in the asset library when entering text #42402

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions editor/plugins/asset_library_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,11 @@ void EditorAssetLibrary::_search(int p_page) {
_api_request("asset", REQUESTING_SEARCH, args);
}

void EditorAssetLibrary::_search_text_entered(const String &p_text) {
void EditorAssetLibrary::_search_text_changed(const String &p_text) {
filter_debounce_timer->start();
}

void EditorAssetLibrary::_filter_debounce_timer_timeout() {
_search();
}

Expand Down Expand Up @@ -1299,10 +1303,15 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
filter = memnew(LineEdit);
search_hb->add_child(filter);
Calinou marked this conversation as resolved.
Show resolved Hide resolved
filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
filter->connect("text_entered", callable_mp(this, &EditorAssetLibrary::_search_text_entered));
search = memnew(Button(TTR("Search")));
search->connect("pressed", callable_mp(this, &EditorAssetLibrary::_search), make_binds(0));
search_hb->add_child(search);
filter->connect("text_changed", callable_mp(this, &EditorAssetLibrary::_search_text_changed));

// Perform a search automatically if the user hasn't entered any text for a certain duration.
// This way, the user doesn't need to press Enter to initiate their search.
filter_debounce_timer = memnew(Timer);
filter_debounce_timer->set_one_shot(true);
filter_debounce_timer->set_wait_time(0.25);
filter_debounce_timer->connect("timeout", callable_mp(this, &EditorAssetLibrary::_filter_debounce_timer_timeout));
search_hb->add_child(filter_debounce_timer);

if (!p_templates_only) {
search_hb->add_child(memnew(VSeparator));
Expand Down
4 changes: 3 additions & 1 deletion editor/plugins/asset_library_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ class EditorAssetLibrary : public PanelContainer {
Label *library_loading;
Label *library_error;
LineEdit *filter;
Timer *filter_debounce_timer;
OptionButton *categories;
OptionButton *repository;
OptionButton *sort;
Button *search;
HBoxContainer *error_hb;
TextureRect *error_tr;
Label *error_label;
Expand Down Expand Up @@ -280,10 +280,12 @@ class EditorAssetLibrary : public PanelContainer {

void _search(int p_page = 0);
void _rerun_search(int p_ignore);
void _search_text_changed(const String &p_text = "");
void _search_text_entered(const String &p_text = "");
void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = "");
void _http_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);
void _http_download_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);
void _filter_debounce_timer_timeout();

void _repository_changed(int p_repository_id);
void _support_toggled(int p_support);
Expand Down