summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-07 13:09:29 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-07 13:09:29 -0700
commitd0867a79d48d6fcb894ac7385fdfb2b7e599021f (patch)
tree933441541d9aa3bde9a45a9773b411b28bba2f9b /divelist.c
parent42bff28e47b549ebb1002152182879fd5af823a0 (diff)
downloadsubsurface-d0867a79d48d6fcb894ac7385fdfb2b7e599021f.tar.gz
Implement delete dive option
With this we can delete a dive from the context menu. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c
index 22caa85c4..77538b78f 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1704,6 +1704,53 @@ void merge_trips_cb(GtkWidget *menuitem, GtkTreePath *trippath)
gtk_tree_store_remove(STORE(dive_list), &thistripiter);
}
+/* this gets called with path pointing to a dive, either in the top level
+ * or as part of a trip */
+static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
+{
+ GtkTreeIter iter;
+ int idx, i;
+ struct dive *dive, *pdive, *ndive;
+ GtkTreeView *tree_view = GTK_TREE_VIEW(dive_list.tree_view);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
+
+ gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
+ gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
+ dive = get_dive(idx);
+ if (dive->divetrip) {
+ /* we could be displaying the list model, in which case we can't find out
+ * if this is part of a trip and the only dive in that trip from the model,
+ * so let's do this the manual way */
+ pdive = get_dive(idx - 1);
+ ndive = get_dive(idx + 1);
+ if (! (pdive && pdive->divetrip == dive->divetrip) &&
+ ! (ndive && ndive->divetrip == dive->divetrip)) {
+ /* if this is the only dive in the trip, remove the trip - the
+ * dive list update below will deal with making sure the treemodel
+ * is correct */
+ GList *trip = find_matching_trip(dive->when);
+ delete_trip(trip);
+ free(dive->divetrip);
+ }
+ }
+ /* simply remove the dive and recreate the divelist
+ * (we can't just manipulate the tree_view as the indices for dives change) */
+ for (i = idx; i < dive_table.nr - 1; i++)
+ dive_table.dives[i] = dive_table.dives[i+1];
+ dive_table.nr--;
+ free(dive);
+ dive_list_update_dives();
+ /* now make sure the same dives stay selected and if necessary their trips are expanded */
+ for_each_dive(i, dive) {
+ if (dive->selected) {
+ GtkTreePath *path = get_path_from(dive);
+ if (MODEL(dive_list) == TREEMODEL(dive_list))
+ gtk_tree_view_expand_to_path(tree_view, path);
+ gtk_tree_selection_select_path(selection, path);
+ }
+ }
+}
+
static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int button, GdkEventButton *event)
{
GtkWidget *menu, *menuitem, *image;
@@ -1754,6 +1801,9 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int
g_signal_connect(menuitem, "activate", G_CALLBACK(remove_trip_cb), path);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
} else {
+ menuitem = gtk_menu_item_new_with_label("Delete Dive");
+ g_signal_connect(menuitem, "activate", G_CALLBACK(delete_dive_cb), path);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
dive = get_dive(idx);
/* if we right click on selected dive(s), edit those */
if (dive->selected) {