summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@lmu.de>2013-03-18 15:26:35 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-03-18 09:59:20 -0700
commit1e37fa99ed0c837e4579ac507212e21f5069732a (patch)
tree65e14f6816936b52d28ab2d8d10753e69935d5c0
parentdaac2d6e433d060a5e5830017b9b4cca74b0deee (diff)
downloadsubsurface-1e37fa99ed0c837e4579ac507212e21f5069732a.tar.gz
Manually add bookmarks in the profile context menu
Use the infrastructure created for manually adding gas change events to also be able to add bookmarks. [Dirk Hohndel: This combines two commits for clarity. I also cleaned up the indentation and changed the code to no longer print the exact same text twice.] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--gtk-gui.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index dfc4e31d6..2167cba46 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1974,6 +1974,43 @@ static void add_gas_change_cb(GtkWidget *menuitem, gpointer data)
}
}
+int confirm_bookmark(int when)
+{
+ GtkWidget *dialog, *vbox, *label;
+ int confirmed;
+ char buffer[256];
+
+ snprintf(buffer, sizeof(buffer), _("Add bookmark event at %d:%02u"), FRACTION(when, 60));
+ dialog = gtk_dialog_new_with_buttons(_("Add bookmark"),
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+ NULL);
+
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ label = gtk_label_new(buffer);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_widget_show_all(dialog);
+ confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
+
+ gtk_widget_destroy(dialog);
+
+ return confirmed;
+}
+
+static void add_bookmark_cb(GtkWidget *menuitem, gpointer data)
+{
+ double *x = data;
+ int when = x_to_time(*x);
+
+ if (confirm_bookmark(when)){
+ add_event(current_dc, when, 8, 0, 0, "bookmark");
+ mark_divelist_changed(TRUE);
+ report_dives(FALSE, FALSE);
+ }
+}
+
static void popup_profile_menu(GtkWidget *widget, GdkEventButton *event)
{
GtkWidget *menu, *menuitem, *image;
@@ -1988,6 +2025,12 @@ static void popup_profile_menu(GtkWidget *widget, GdkEventButton *event)
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
g_signal_connect(menuitem, "activate", G_CALLBACK(add_gas_change_cb), &x);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+ menuitem = gtk_image_menu_item_new_with_label(_("Add bookmark event here"));
+ image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
+ g_signal_connect(menuitem, "activate", G_CALLBACK(add_bookmark_cb), &x);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+
gtk_widget_show_all(menu);