summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-31 22:21:53 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-31 22:31:58 +1100
commitde7d5b2d5b441b3c8efa29a6b64a7685ef835768 (patch)
treeaf5d6154f084b1b84dd2695b44ca73b62bdaf211
parentb93f2ec6c3511ce9d0fc6d990ba97af7b8cc440d (diff)
downloadsubsurface-de7d5b2d5b441b3c8efa29a6b64a7685ef835768.tar.gz
Make sure that the planned dive is selected
With the changes to the selection logic the selected_dive variable didn't get updated at the end of planning a dive. With an empty dive list that could cause selected_dive to be -1 which would subsequently cause a SIGSEGV when trying to edit the newly created dive. With this commit we use the shared go_to_iter() function and also make sure that selected_dive is set correctly. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c31
-rw-r--r--info.c3
2 files changed, 17 insertions, 17 deletions
diff --git a/divelist.c b/divelist.c
index 26ccd3de4..50e279550 100644
--- a/divelist.c
+++ b/divelist.c
@@ -2856,6 +2856,19 @@ static void scroll_to_selected(GtkTreeIter *iter)
gtk_tree_path_free(treepath);
}
+static void go_to_iter(GtkTreeSelection *selection, GtkTreeIter *iter)
+{
+ GtkTreePath *path;
+
+ scroll_to_selected(iter);
+ gtk_tree_selection_unselect_all(selection);
+ gtk_tree_selection_select_iter(selection, iter);
+
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(dive_list.model), iter);
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(dive_list.tree_view), path, NULL, FALSE);
+ gtk_tree_path_free(path);
+}
+
void show_and_select_dive(struct dive *dive)
{
GtkTreeSelection *selection;
@@ -2869,26 +2882,12 @@ void show_and_select_dive(struct dive *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;
+ selected_dive = divenr;
dive->selected = TRUE;
- gtk_tree_selection_select_iter(selection, iter);
- scroll_to_selected(iter);
-}
-
-static void go_to_iter(GtkTreeSelection *selection, GtkTreeIter *iter)
-{
- GtkTreePath *path;
-
- scroll_to_selected(iter);
- gtk_tree_selection_unselect_all(selection);
- gtk_tree_selection_select_iter(selection, iter);
-
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(dive_list.model), iter);
- gtk_tree_view_set_cursor(GTK_TREE_VIEW(dive_list.tree_view), path, NULL, FALSE);
- gtk_tree_path_free(path);
+ go_to_iter(selection, iter);
}
void select_next_dive(void)
diff --git a/info.c b/info.c
index 2916c0eaf..5e47a2590 100644
--- a/info.c
+++ b/info.c
@@ -906,7 +906,8 @@ int edit_multi_dive_info(struct dive *single_dive)
master = single_dive;
if (!master)
master = current_dive;
-
+ if (!master)
+ return 0;
/* See if we should use multi dive mode */
multi = FALSE;
if (!single_dive) {