diff options
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/divelist.c b/divelist.c index 32f5f44a3..f2e678181 100644 --- a/divelist.c +++ b/divelist.c @@ -2740,7 +2740,7 @@ static GtkTreeIter *get_iter_from_idx(int idx) void select_next_dive(void) { - GtkTreeIter *nextiter; + 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; @@ -2750,31 +2750,33 @@ void select_next_dive(void) return; nextiter = gtk_tree_iter_copy(iter); if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) { - if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter)) + if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter)) { /* we're at the last top level node */ return; - if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) + } + if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) { /* last trip */ return; - gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1); - if (idx < 0) { - /* need the first child */ - GtkTreeIter *parent = gtk_tree_iter_copy(nextiter); - if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent)) - return; } } + gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1); + if (idx < 0) { + /* need the first child */ + parent = gtk_tree_iter_copy(nextiter); + 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); + gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, nextiter); - gtk_tree_selection_unselect_iter(selection, iter); gtk_tree_path_free(treepath); } void select_prev_dive(void) { - GtkTreeIter previter; + GtkTreeIter previter, *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; @@ -2786,29 +2788,31 @@ void select_prev_dive(void) if (!gtk_tree_path_prev(treepath)) { if (!gtk_tree_model_iter_parent(MODEL(dive_list), &previter, iter)) /* we're at the last top level node */ - return; + goto free_path; + gtk_tree_path_free(treepath); treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter); if (!gtk_tree_path_prev(treepath)) /* first trip */ - return; - if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath)) - return; - gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1); - if (idx < 0) { - /* need the last child */ - GtkTreeIter *parent = gtk_tree_iter_copy(&previter); - if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent, - gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1)) - return; - } - treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter); - } else { + goto free_path; if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath)) - return; + goto free_path; } + if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath)) + goto free_path; + gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1); + if (idx < 0) { + /* need the last child */ + parent = gtk_tree_iter_copy(&previter); + if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent, + 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); + gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &previter); - gtk_tree_selection_unselect_iter(selection, iter); - gtk_tree_path_free(treepath); + free_path: + gtk_tree_path_free(treepath); } |