From f6e8903a528a65f0e0fd050c203c95d57afd2db9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 2 Sep 2012 21:48:30 -0700 Subject: Add autogen menu command This adds the ability to auto create trips from the menu. It's a toggle entry (and while at it, we made the zoom toggle a toggle entry as well). We can therfore switch back and forth between auto generated trips. There is one bug. Assume you have no trips. You manually create a trip from some dives out of a group of trips that autogen would turn into a trip. Now you turn on autogen and this trip gets expanded with all the dives that would normally be grouped together. If you turn off autogen again, all those dives are still part of the remaining (initially manually created) trip. Working around this issue seemed a lot more work than the likelihood of anyone running into it seemed worth. Signed-off-by: Dirk Hohndel --- gtk-gui.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'gtk-gui.c') diff --git a/gtk-gui.c b/gtk-gui.c index 7db777ab9..03d2862c1 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -634,6 +634,14 @@ static void selectevents_dialog(GtkWidget *w, gpointer data) gtk_widget_destroy(dialog); } +static void autogroup_cb(GtkWidget *w, gpointer data) +{ + autogroup = !autogroup; + if (! autogroup) + remove_autogen_trips(); + dive_list_update_dives(); +} + static void renumber_dialog(GtkWidget *w, gpointer data) { int result; @@ -757,10 +765,15 @@ static GtkActionEntry menu_items[] = { { "ViewProfile", NULL, "Profile", CTRLCHAR "2", NULL, G_CALLBACK(view_profile) }, { "ViewInfo", NULL, "Info", CTRLCHAR "3", NULL, G_CALLBACK(view_info) }, { "ViewThree", NULL, "Three", CTRLCHAR "4", NULL, G_CALLBACK(view_three) }, - { "ToggleZoom", NULL, "Toggle Zoom", CTRLCHAR "0", NULL, G_CALLBACK(toggle_zoom) }, }; static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); +static GtkToggleActionEntry toggle_items[] = { + { "Autogroup", NULL, "Autogroup", NULL, NULL, G_CALLBACK(autogroup_cb), FALSE }, + { "ToggleZoom", NULL, "Toggle Zoom", CTRLCHAR "0", NULL, G_CALLBACK(toggle_zoom), FALSE }, +}; +static gint ntoggle_items = sizeof (toggle_items) / sizeof (toggle_items[0]); + static const gchar* ui_string = " \ \ \ @@ -779,6 +792,7 @@ static const gchar* ui_string = " \ \ \ \ + \ \ \ \ @@ -801,6 +815,7 @@ static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager) { GtkActionGroup *action_group = gtk_action_group_new("Menu"); gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0); + gtk_action_group_add_toggle_actions(action_group, toggle_items, ntoggle_items, 0); gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); GError* error = 0; -- cgit v1.2.3-70-g09d2 From 8b021de8d9838f4591b50cb15fc8774c31f8ed14 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 3 Sep 2012 08:01:21 -0700 Subject: Correctly initialize the toggle state of the autogroup menu entry If we move to Linus' tri-state variable we need to separate those two items, anyway. But for now this fixes the obvious bug. Reported-by: Henrik Brautaset Aronsen Signed-off-by: Dirk Hohndel --- gtk-gui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'gtk-gui.c') diff --git a/gtk-gui.c b/gtk-gui.c index 03d2862c1..a2f130ac2 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -815,6 +815,7 @@ static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager) { GtkActionGroup *action_group = gtk_action_group_new("Menu"); gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0); + toggle_items[0].is_active = autogroup; gtk_action_group_add_toggle_actions(action_group, toggle_items, ntoggle_items, 0); gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); -- cgit v1.2.3-70-g09d2