diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-02-10 11:16:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-10 11:16:47 +0100 |
commit | 1ceba5a653048b0d27b46264fb8be993eeab67d3 (patch) | |
tree | 4b05649ba959b1db3b5cde4a1de75e414e3dba6b | |
parent | 0ead0eeabb360df8b3a333cb58410bd52e2f33c1 (diff) | |
parent | 28979184266c7d27c2f91facaaed3b35eb0c0c9e (diff) |
Merge pull request #35260 from Calinou/project-manager-enter-open-first
Select the first project when searching in the project manager
-rw-r--r-- | editor/project_manager.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index ee434aaac2..d1a2a5fe2b 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -1037,6 +1037,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; @@ -1629,6 +1630,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; @@ -2347,6 +2365,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() { |