From 755f185cfcbd3d61457df6fdff32bcf2118f0ab5 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 25 Nov 2019 19:00:38 +0100 Subject: Selection: move selection of "first" dive to core The DiveListView has a function to select the first dive. Move this to the core to be able to call it from all parts (not only desktop) of the code. Currently, this has a (small?) UI regression: when filtering dives and no selected dive is visible anymore, the old code would select the first dive in the list. The new code selects the newest dive, which might not be the first if some sort-criterion is active. To revert to the old behavior, it will be necessary to move the sorting function likewise to the core. Signed-off-by: Berthold Stoeger --- core/selection.cpp | 13 +++++++++++++ core/selection.h | 1 + 2 files changed, 14 insertions(+) (limited to 'core') diff --git a/core/selection.cpp b/core/selection.cpp index 92bb631fc..6b5dfe726 100644 --- a/core/selection.cpp +++ b/core/selection.cpp @@ -210,3 +210,16 @@ std::vector getDiveSelection() } return res; } + +// Select the first dive that is visible +extern "C" void select_newest_visible_dive() +{ + for (int i = dive_table.nr - 1; i >= 0; --i) { + dive *d = dive_table.dives[i]; + if (!d->hidden_by_filter) + return setSelection({ d }, d); + } + + // No visible dive -> deselect all + setSelection({}, nullptr); +} diff --git a/core/selection.h b/core/selection.h index e990a697c..a390f0dd7 100644 --- a/core/selection.h +++ b/core/selection.h @@ -19,6 +19,7 @@ extern void deselect_dive(struct dive *dive); extern struct dive *first_selected_dive(void); extern struct dive *last_selected_dive(void); extern bool consecutive_selected(void); +extern void select_newest_visible_dive(); #if DEBUG_SELECTION_TRACKING extern void dump_selection(void); -- cgit v1.2.3-70-g09d2