mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Correctly show the planned dive in the divelist
Previously we would simply show the first dive in the divelist - which worked fine in the default sort by trip setting and assuming that there are no dives from the future in the divelist. With this commit we actually find the correct dive in the divelist and select it instead. If you sort by depth you will see the dive move around in the divelist, but it will stay selected and visible in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
c8a9986451
commit
1ea445102e
3 changed files with 33 additions and 29 deletions
56
divelist.c
56
divelist.c
|
@ -841,6 +841,14 @@ static void add_dive_to_deco(struct dive *dive)
|
|||
}
|
||||
}
|
||||
|
||||
static int get_divenr(struct dive *dive)
|
||||
{
|
||||
int divenr = -1;
|
||||
while (++divenr < dive_table.nr && get_dive(divenr) != dive)
|
||||
;
|
||||
return divenr;
|
||||
}
|
||||
|
||||
static struct gasmix air = { .o2.permille = 209 };
|
||||
|
||||
/* take into account previous dives until there is a 48h gap between dives */
|
||||
|
@ -854,8 +862,7 @@ double init_decompression(struct dive *dive)
|
|||
|
||||
if (!dive)
|
||||
return 0.0;
|
||||
while (++divenr < dive_table.nr && get_dive(divenr) != dive)
|
||||
;
|
||||
divenr = get_divenr(dive);
|
||||
when = dive->when;
|
||||
i = divenr;
|
||||
while (i && --i) {
|
||||
|
@ -1323,30 +1330,6 @@ static void clear_trip_indexes(void)
|
|||
trip->index = 0;
|
||||
}
|
||||
|
||||
void select_last_dive(void)
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeIter iter;
|
||||
struct dive *dive;
|
||||
int i;
|
||||
|
||||
/* select the last dive (and make sure it's an actual dive that is selected) */
|
||||
/* WARNING - this only works when sorted by date!!!
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
gtk_tree_model_get_iter_first(MODEL(dive_list), &iter);
|
||||
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
for_each_dive(i, dive)
|
||||
dive->selected = FALSE;
|
||||
amount_selected = 0;
|
||||
gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &selected_dive, -1);
|
||||
first_leaf(MODEL(dive_list), &iter, &selected_dive);
|
||||
gtk_tree_selection_select_iter(selection, &iter);
|
||||
}
|
||||
|
||||
static void fill_dive_list(void)
|
||||
{
|
||||
int i, trip_index = 0;
|
||||
|
@ -2788,6 +2771,27 @@ static GtkTreeIter *get_iter_from_idx(int idx)
|
|||
return iteridx.iter;
|
||||
}
|
||||
|
||||
void show_and_select_dive(struct dive *dive)
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeIter *iter;
|
||||
struct dive *odive;
|
||||
int i, divenr;
|
||||
|
||||
divenr = get_divenr(dive);
|
||||
if (divenr < 0)
|
||||
/* we failed to find the dive */
|
||||
return;
|
||||
iter = get_iter_from_idx(divenr);
|
||||
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
for_each_dive(i, odive)
|
||||
odive->selected = FALSE;
|
||||
amount_selected = 1;
|
||||
dive->selected = TRUE;
|
||||
gtk_tree_selection_select_iter(selection, iter);
|
||||
}
|
||||
|
||||
void select_next_dive(void)
|
||||
{
|
||||
GtkTreeIter *nextiter, *parent;
|
||||
|
|
|
@ -15,6 +15,6 @@ extern void remember_tree_state(void);
|
|||
extern void restore_tree_state(void);
|
||||
extern void select_next_dive(void);
|
||||
extern void select_prev_dive(void);
|
||||
extern void select_last_dive(void);
|
||||
extern void show_and_select_dive(struct dive *dive);
|
||||
extern double init_decompression(struct dive * dive);
|
||||
#endif
|
||||
|
|
|
@ -504,9 +504,9 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep)
|
|||
record_dive(dive);
|
||||
stopidx--;
|
||||
}
|
||||
/* now make the dive visible as last dive of the dive list */
|
||||
/* now make the dive visible in the dive list */
|
||||
report_dives(FALSE, FALSE);
|
||||
select_last_dive();
|
||||
show_and_select_dive(dive);
|
||||
free(stoplevels);
|
||||
free(gaschanges);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue