summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.h1
-rw-r--r--info.c45
-rw-r--r--parse-xml.c23
3 files changed, 66 insertions, 3 deletions
diff --git a/dive.h b/dive.h
index 39f203738..89f790122 100644
--- a/dive.h
+++ b/dive.h
@@ -299,6 +299,7 @@ extern time_t utc_mktime(struct tm *tm);
extern struct dive *alloc_dive(void);
extern void record_dive(struct dive *dive);
+extern void delete_dive(struct dive *dive);
extern struct sample *prepare_sample(struct dive **divep);
extern void finish_sample(struct dive *dive);
diff --git a/info.c b/info.c
index 6a4a296b0..f1afc0574 100644
--- a/info.c
+++ b/info.c
@@ -100,19 +100,58 @@ void show_dive_info(struct dive *dive)
dive && dive->notes ? dive->notes : "", -1);
}
+static int delete_dive_info(struct dive *dive)
+{
+ int success;
+ GtkWidget *dialog;
+
+ if (!dive)
+ return 0;
+
+ dialog = gtk_dialog_new_with_buttons("Delete Dive",
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ NULL);
+
+ gtk_widget_show_all(dialog);
+ success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+ if (success) {
+ delete_dive(dive);
+ mark_divelist_changed(TRUE);
+ dive_list_update_dives();
+ }
+
+ gtk_widget_destroy(dialog);
+
+ return success;
+}
+
static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
{
edit_dive_info(current_dive);
}
-static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
+static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data)
{
- GtkWidget *item = gtk_menu_item_new_with_label("Edit");
- g_signal_connect(item, "activate", G_CALLBACK(info_menu_edit_cb), NULL);
+ delete_dive_info(current_dive);
+}
+
+static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuItem *, gpointer))
+{
+ GtkWidget *item = gtk_menu_item_new_with_label(label);
+ g_signal_connect(item, "activate", G_CALLBACK(cb), NULL);
gtk_widget_show(item); /* Yes, really */
gtk_menu_prepend(menu, item);
}
+static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
+{
+ add_menu_item(menu, "Delete", info_menu_delete_cb);
+ add_menu_item(menu, "Edit", info_menu_edit_cb);
+}
+
static GtkEntry *text_value(GtkWidget *box, const char *label)
{
GtkWidget *widget;
diff --git a/parse-xml.c b/parse-xml.c
index e920a11f6..552786b7a 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -39,6 +39,29 @@ void record_dive(struct dive *dive)
dive_table.nr = nr+1;
}
+/*
+ * Remove a dive from the dive_table array
+ */
+void delete_dive(struct dive *dive)
+{
+ int nr = dive_table.nr, i;
+ struct dive **dives = dive_table.dives;
+
+ /*
+ * Stupid. We know the dive table is sorted by date,
+ * we could do a binary lookup. Sue me.
+ */
+ for (i = 0; i < nr; i++) {
+ struct dive *d = dives[i];
+ if (d != dive)
+ continue;
+ memmove(dives+i, dives+i+1, sizeof(struct dive *)*(nr-i-1));
+ dives[nr] = NULL;
+ dive_table.nr = nr-1;
+ break;
+ }
+}
+
static void start_match(const char *type, const char *name, char *buffer)
{
if (verbose > 2)