summaryrefslogtreecommitdiffstats
path: root/info.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-04-02 19:19:01 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-04-02 19:19:01 -0700
commit1cbe2444cc6c0c8da9e730561914986506d83770 (patch)
treedc9e16169410158163dc52fc72b77288f9ad575f /info.c
parent3a7d577ff1109c701656854ceb23ed690c340fbc (diff)
downloadsubsurface-1cbe2444cc6c0c8da9e730561914986506d83770.tar.gz
Add the ugliest 'delete dive' model ever
This interface works the same way the "edit dive" menu item does: it's a text entry meny item on the dive text entries (ie buddy/divemaster/notes sections). Except you pick the "Delete" entry rather than the "Edit" entry. It kind of works, but it really is a pretty horrible interface. I'll need to add a top-level dive menu entry for just deleting all selected dives instead. And it would be good to be able to get a drop-down menu from the divelist instead of having to do it from the dive text entries, which is just insane. But that requires gtk work. I'm not quite ready to get back into that. Thus the "exact same insane interface as the explicit 'Edit' mode". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'info.c')
-rw-r--r--info.c45
1 files changed, 42 insertions, 3 deletions
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;