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>
This commit is contained in:
Robert C. Helling 2013-03-18 15:26:35 +01:00 committed by Dirk Hohndel
parent daac2d6e43
commit 1e37fa99ed

View file

@ -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);