mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Scroll the divelist to show the planned dive
Just put the code to do so in a function and reuse that function elsewhere as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
1ea445102e
commit
e0b53a5d31
1 changed files with 14 additions and 11 deletions
25
divelist.c
25
divelist.c
|
|
@ -2771,6 +2771,15 @@ static GtkTreeIter *get_iter_from_idx(int idx)
|
||||||
return iteridx.iter;
|
return iteridx.iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scroll_to_selected(GtkTreeIter *iter)
|
||||||
|
{
|
||||||
|
GtkTreePath *treepath;
|
||||||
|
treepath = gtk_tree_model_get_path(MODEL(dive_list), iter);
|
||||||
|
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
||||||
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
||||||
|
gtk_tree_path_free(treepath);
|
||||||
|
}
|
||||||
|
|
||||||
void show_and_select_dive(struct dive *dive)
|
void show_and_select_dive(struct dive *dive)
|
||||||
{
|
{
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
|
|
@ -2790,6 +2799,7 @@ void show_and_select_dive(struct dive *dive)
|
||||||
amount_selected = 1;
|
amount_selected = 1;
|
||||||
dive->selected = TRUE;
|
dive->selected = TRUE;
|
||||||
gtk_tree_selection_select_iter(selection, iter);
|
gtk_tree_selection_select_iter(selection, iter);
|
||||||
|
scroll_to_selected(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_next_dive(void)
|
void select_next_dive(void)
|
||||||
|
|
@ -2797,7 +2807,6 @@ void select_next_dive(void)
|
||||||
GtkTreeIter *nextiter, *parent;
|
GtkTreeIter *nextiter, *parent;
|
||||||
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
|
GtkTreeIter *iter = get_iter_from_idx(selected_dive);
|
||||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
|
||||||
GtkTreePath *treepath;
|
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
if (!iter)
|
if (!iter)
|
||||||
|
|
@ -2820,12 +2829,9 @@ void select_next_dive(void)
|
||||||
if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
|
if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
treepath = gtk_tree_model_get_path(MODEL(dive_list), nextiter);
|
scroll_to_selected(nextiter);
|
||||||
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
|
||||||
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
|
||||||
gtk_tree_selection_unselect_all(selection);
|
gtk_tree_selection_unselect_all(selection);
|
||||||
gtk_tree_selection_select_iter(selection, nextiter);
|
gtk_tree_selection_select_iter(selection, nextiter);
|
||||||
gtk_tree_path_free(treepath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void select_prev_dive(void)
|
void select_prev_dive(void)
|
||||||
|
|
@ -2861,12 +2867,9 @@ void select_prev_dive(void)
|
||||||
gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
|
gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
|
||||||
goto free_path;
|
goto free_path;
|
||||||
}
|
}
|
||||||
gtk_tree_path_free(treepath);
|
scroll_to_selected(&previter);
|
||||||
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
|
|
||||||
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dive_list.tree_view), treepath);
|
|
||||||
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(dive_list.tree_view), treepath, NULL, FALSE, 0, 0);
|
|
||||||
gtk_tree_selection_unselect_all(selection);
|
gtk_tree_selection_unselect_all(selection);
|
||||||
gtk_tree_selection_select_iter(selection, &previter);
|
gtk_tree_selection_select_iter(selection, &previter);
|
||||||
free_path:
|
free_path:
|
||||||
gtk_tree_path_free(treepath);
|
gtk_tree_path_free(treepath);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue