selection: avoid select_dive() and deselect_dive calls in dive list

Each of these calls recalculates the current dive and divecomputer.
Instead, collect the dives to be selected/deselected and (de)select
them at once.

This needs some code refactoring in the core, because we need a
function that
1) doesn't send a signal by itself.
2) doesn't clear the trip-selection.

This contains some reorganization of the selection functions
signatures: The filter code is the only caller that keeps the
selected dive and the only caller that cares about whether the
current dive changed. So let only the function that keeps the
selected dive return whether the current dive changed.

It's all very fragile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-05-21 20:38:17 +02:00 committed by bstoeger
parent 6df1c62dfc
commit 487974ea91
6 changed files with 76 additions and 57 deletions

View file

@ -287,26 +287,6 @@ dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *fr
return NULL;
}
void deselect_dives_in_trip(struct dive_trip *trip)
{
if (!trip)
return;
for (int i = 0; i < trip->dives.nr; ++i)
deselect_dive(trip->dives.dives[i]);
}
void select_dives_in_trip(struct dive_trip *trip)
{
struct dive *dive;
if (!trip)
return;
for (int i = 0; i < trip->dives.nr; ++i) {
dive = trip->dives.dives[i];
if (!dive->hidden_by_filter)
select_dive(dive);
}
}
/* Out of two strings, copy the string that is not empty (if any). */
static char *copy_non_empty_string(const char *a, const char *b)
{