mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Make the selection logic more robust
In commit 304526850c91 ("Don't deselect all dives on all selection "change" events") the handling of "selected_dive" is incorrect. We ended up with non-sensical values for the selected dive, including dives that Gtk didn't think were selected. This commit tries to be smart about what to do when the dive that we currently consider selected is unselected (we have this weird notion of many dives being selected, but one of them is shown in the profile and that is the "selected_dive"). As long as there are others selected, we pick one of them (first walking to earlier dives and if there are none that are selected, looking for a later dive) as the new selected dive. This appears to give us a rather intuitive behavior when playing with multiple selected dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4b5b732f2c
commit
468d3f28f9
1 changed files with 16 additions and 2 deletions
18
divelist.c
18
divelist.c
|
@ -2611,8 +2611,22 @@ static void deselect_dive(int idx)
|
|||
if (dive && dive->selected) {
|
||||
dive->selected = 0;
|
||||
amount_selected--;
|
||||
if (selected_dive > idx)
|
||||
selected_dive--;
|
||||
if (selected_dive == idx && amount_selected > 0) {
|
||||
/* pick a different dive as selected */
|
||||
while(--selected_dive >= 0) {
|
||||
dive = get_dive(selected_dive);
|
||||
if (dive && dive->selected)
|
||||
return;
|
||||
}
|
||||
selected_dive = idx;
|
||||
while(++selected_dive < dive_table.nr) {
|
||||
dive = get_dive(selected_dive);
|
||||
if (dive && dive->selected)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (amount_selected == 0)
|
||||
selected_dive = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue