From 6ec87ed1ed84a44c092937f69e3ba887314034bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Fri, 7 Aug 2020 00:01:30 +0200 Subject: [PATCH] Improve select all saves feature (fixes #725) Ctrl+A no longer selects all saves if any of the textboxes in the view are in focus, as a ctrl+A in that case is expected to select everything in the textbox, not in the save browser. This change also makes the shortcut deselect all saves if all saves are selected. And no, I'm not making events cancellable just for this. --- src/gui/search/SearchModel.cpp | 14 ++++++++++++-- src/gui/search/SearchView.cpp | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gui/search/SearchModel.cpp b/src/gui/search/SearchModel.cpp index b921971d1..3208de8e6 100644 --- a/src/gui/search/SearchModel.cpp +++ b/src/gui/search/SearchModel.cpp @@ -201,9 +201,19 @@ void SearchModel::SelectSave(int saveID) void SearchModel::SelectAllSaves() { - for (int i = 0; i < saveList.size(); i++) + if (selected.size() == saveList.size()) { - SelectSave(saveList[i]->id); + for (auto &save : saveList) + { + DeselectSave(save->id); + } + } + else + { + for (auto &save : saveList) + { + SelectSave(save->id); + } } } diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index 449d2399c..d890c0cfb 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -654,7 +654,7 @@ void SearchView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctr return; if (key == SDLK_ESCAPE) c->Exit(); - else if (key == SDLK_a && ctrl) + else if ((focusedComponent_ != pageTextbox && focusedComponent_ != searchField) && scan == SDL_SCANCODE_A && ctrl) c->SelectAllSaves(); else if (key == SDLK_LCTRL || key == SDLK_RCTRL) c->InstantOpen(true);