Gases in divelist

Dirk Hohndel dirk at hohndel.org
Mon Mar 18 10:09:22 PDT 2013


"Robert C. Helling" <helling at lmu.de> writes:

> On Mon, 18 Mar 2013, Dirk Hohndel wrote:
>
>> Can you please remove the value printout from the tooltip and the entry
>> from your widget? Have the widget instead confirm the time (like I do in
>> the gas change one) and offer ok/cancel to set a bookmark at that time.
>
> Voilà.

Ok, based on Miika's change I decided to push this, but I had to clean
things up a bit - so this is what just went out...

Your patches didn't really have reasonable commit messages. They were
whitespace hell-holes... ok, let's just say they didn't follow my ideas
of coding standard. And introducing the value and then taking it away in
the next patch... "git rebase -i HEAD~2" is your friend...

Given the relatively low volume of patches on this list I am willing to
do the cleanup - but git really makes it easy to create nice clean
patches with great commit messages and it even sends them out for you if
your regular mail setup is not up to par.

So maybe take it as a challenge (now that you've written your first gtk
widget) to have a nicely indented patch with beautiful commit message
next time... 

Something that I can just pipe into "git am -3 -s --whitespace=fix" 
(the latter just for the small stuff it can fix... it doesn't deal with
spaces for indentation for example) :-)

Thanks

/D

PS: just for the record - with this commit you are now in the top ten
all time Subsurface contributors!! 
And you are in fifth place (one patch behind a certain Linus T.) in
commits since 3.0  :-)



>From 1e37fa99ed0c837e4579ac507212e21f5069732a Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <helling at lmu.de>
Date: Mon, 18 Mar 2013 15:26:35 +0100
Subject: [PATCH] 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 at atdotde.de>
Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
---
 gtk-gui.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/gtk-gui.c b/gtk-gui.c
index dfc4e31..2167cba 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);
 
-- 
1.8.0.rc0.18.gf84667d




More information about the subsurface mailing list