Select the first project when searching in the project manager

This makes the project manager usable for opening existing projects
without ever touching the mouse. Just enter text in the autofocused
search box and press Enter.

This partially addresses #8149.
This commit is contained in:
Hugo Locurcio 2020-01-17 22:07:11 +01:00
parent 94a9cdb3b0
commit 2897918426
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C

View file

@ -1029,6 +1029,7 @@ public:
void sort_projects();
int get_project_count() const;
void select_project(int p_index);
void select_first_visible_project();
void erase_selected_projects();
Vector<Item> get_selected_projects() const;
const Set<String> &get_selected_project_keys() const;
@ -1618,6 +1619,23 @@ void ProjectList::select_project(int p_index) {
toggle_select(p_index);
}
void ProjectList::select_first_visible_project() {
bool found = false;
for (int i = 0; i < _projects.size(); i++) {
if (_projects[i].control->is_visible()) {
select_project(i);
found = true;
break;
}
}
if (!found) {
// Deselect all projects if there are no visible projects in the list.
_selected_project_keys.clear();
}
}
inline void sort(int &a, int &b) {
if (a > b) {
int temp = a;
@ -2336,6 +2354,12 @@ void ProjectManager::_on_order_option_changed() {
void ProjectManager::_on_filter_option_changed() {
_project_list->set_search_term(project_filter->get_search_term());
_project_list->sort_projects();
// Select the first visible project in the list.
// This makes it possible to open a project without ever touching the mouse,
// as the search field is automatically focused on startup.
_project_list->select_first_visible_project();
_update_project_buttons();
}
void ProjectManager::_bind_methods() {