diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-01-13 21:10:52 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-13 21:36:50 -0800 |
commit | e0b53a5d319bfdd0411348c8a6907a881df2fc85 (patch) | |
tree | a93664bd58fd7c3a7262426edba4d3782e88f09e /divelist.c | |
parent | 1ea445102ed34b704345b4fd3b0ac00fa8380b06 (diff) | |
download | subsurface-e0b53a5d319bfdd0411348c8a6907a881df2fc85.tar.gz |
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>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/divelist.c b/divelist.c index 57d41a389..8537de62b 100644 --- a/divelist.c +++ b/divelist.c @@ -2771,6 +2771,15 @@ static GtkTreeIter *get_iter_from_idx(int idx) 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) { GtkTreeSelection *selection; @@ -2790,6 +2799,7 @@ void show_and_select_dive(struct dive *dive) amount_selected = 1; dive->selected = TRUE; gtk_tree_selection_select_iter(selection, iter); + scroll_to_selected(iter); } void select_next_dive(void) @@ -2797,7 +2807,6 @@ void select_next_dive(void) GtkTreeIter *nextiter, *parent; GtkTreeIter *iter = get_iter_from_idx(selected_dive); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view)); - GtkTreePath *treepath; int idx; if (!iter) @@ -2820,12 +2829,9 @@ void select_next_dive(void) if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent)) return; } - treepath = gtk_tree_model_get_path(MODEL(dive_list), 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); + scroll_to_selected(nextiter); gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, nextiter); - gtk_tree_path_free(treepath); } 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)) goto free_path; } - gtk_tree_path_free(treepath); - 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); + scroll_to_selected(&previter); gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &previter); - free_path: - gtk_tree_path_free(treepath); +free_path: + gtk_tree_path_free(treepath); } |