diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-09-03 20:36:46 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-09-03 20:46:09 -0700 |
commit | 70d254ab844ca5d4129eebdadd0b8729acd0d1e8 (patch) | |
tree | 8bc98169c2856cf15c9f0432b19fe6ffd1939938 /divelist.c | |
parent | 2a1d7a510c60ad26e456b40e4f34caeb145339e3 (diff) | |
download | subsurface-70d254ab844ca5d4129eebdadd0b8729acd0d1e8.tar.gz |
Use the infrastructure for moving dives in more places
Instead of using our generic helper function the code in
remove_from_trip_cb tried to implement the special case - and got it
wrong. This fixes yet another crash that Henrik found.
Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/divelist.c b/divelist.c index de7304520..90b3f693d 100644 --- a/divelist.c +++ b/divelist.c @@ -1398,7 +1398,7 @@ static void insert_trip_before_cb(GtkWidget *menuitem, GtkTreePath *path) static void remove_from_trip_cb(GtkWidget *menuitem, GtkTreePath *path) { - GtkTreeIter iter, newiter, parent; + GtkTreeIter iter, nextiter, *newiter, parent; GtkTreePath *nextpath; struct dive *dive; int idx; @@ -1411,26 +1411,28 @@ static void remove_from_trip_cb(GtkWidget *menuitem, GtkTreePath *path) in two right after this dive */ nextpath = gtk_tree_path_copy(path); gtk_tree_path_next(nextpath); - if (gtk_tree_model_get_iter(MODEL(dive_list), &newiter, nextpath)) + if (gtk_tree_model_get_iter(MODEL(dive_list), &nextiter, nextpath)) insert_trip_before(nextpath); - /* now create a new node as sibling right after the current parent */ - gtk_tree_store_insert_after(STORE(dive_list), &newiter, NULL, &parent); - copy_tree_node(&iter, &newiter); - - gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1); + /* now move the dive to the top level, as sibling after its former parent */ + newiter = move_dive_between_trips(&iter, &parent, NULL, &parent, FALSE); + gtk_tree_model_get(MODEL(dive_list), newiter, DIVE_INDEX, &idx, -1); dive = get_dive(idx); if (dive->selected) { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view)); - gtk_tree_selection_select_iter(selection, &newiter); + gtk_tree_selection_select_iter(selection, newiter); } - gtk_tree_store_remove(STORE(dive_list), &iter); /* if this was the last dive on the trip, remove the trip */ if (! gtk_tree_model_iter_has_child(MODEL(dive_list), &parent)) { gtk_tree_store_remove(STORE(dive_list), &parent); delete_trip(FIND_TRIP(dive->divetrip->when)); + free(dive->divetrip); } + /* mark the dive as intentionally at the top level */ dive->tripflag = NO_TRIP; dive->divetrip = NULL; +#ifdef DEBUG_TRIP + dump_trip_list(); +#endif } void remove_trip(GtkTreePath *trippath, gboolean force_no_trip) @@ -1471,6 +1473,9 @@ void remove_trip(GtkTreePath *trippath, gboolean force_no_trip) gtk_tree_store_remove(STORE(dive_list), &parent); delete_trip(FIND_TRIP(dive_trip->when)); free(dive_trip); +#ifdef DEBUG_TRIP + dump_trip_list(); +#endif } void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath) |