diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-09-02 21:48:30 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-09-02 21:50:43 -0700 |
commit | f6e8903a528a65f0e0fd050c203c95d57afd2db9 (patch) | |
tree | 48752b81acfd112e62ecb1bd7618f0ad2cf76bf8 | |
parent | 22ff8df880461c6e66d45fa8eaba9c9c26edb1bd (diff) | |
download | subsurface-f6e8903a528a65f0e0fd050c203c95d57afd2db9.tar.gz |
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 <dirk@hohndel.org>
-rw-r--r-- | divelist.c | 40 | ||||
-rw-r--r-- | divelist.h | 1 | ||||
-rw-r--r-- | gtk-gui.c | 17 |
3 files changed, 55 insertions, 3 deletions
diff --git a/divelist.c b/divelist.c index 5f45e900b..64b392f54 100644 --- a/divelist.c +++ b/divelist.c @@ -970,11 +970,16 @@ static void fill_dive_list(void) /* allocate new trip - all fields default to 0 and get filled in further down */ dive_trip = create_and_hookup_trip_from_dive(dive); + dive_trip->tripflag = IN_TRIP; /* this marks an autogen trip */ trip = FIND_TRIP(dive_trip->when); } } else if (DIVE_IN_TRIP(dive)) { trip = find_matching_trip(dive->when); dive_trip = DIVE_TRIP(trip); + } else { + /* dive is not in a trip and we aren't autogrouping */ + dive_trip = NULL; + parent_ptr = NULL; } /* update dive as part of dive_trip and * (if necessary) update dive_trip time and location */ @@ -1427,7 +1432,7 @@ static void remove_from_trip_cb(GtkWidget *menuitem, GtkTreePath *path) dive->divetrip = NULL; } -void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath) +void remove_trip(GtkTreePath *trippath, gboolean force_no_trip) { GtkTreeIter newiter, parent, child, *lastiter = &parent; struct dive *dive, *dive_trip = NULL; @@ -1450,7 +1455,10 @@ void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath) dive = get_dive(idx); if (dive->selected) gtk_tree_selection_select_iter(selection, &newiter); - dive->tripflag = NO_TRIP; + if (force_no_trip) + dive->tripflag = NO_TRIP; + else + dive->tripflag = TF_NONE; if (!dive_trip) dive_trip = dive->divetrip; dive->divetrip = NULL; @@ -1464,6 +1472,11 @@ void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath) free(dive_trip); } +void remove_trip_cb(GtkWidget *menuitem, GtkTreePath *trippath) +{ + remove_trip(trippath, TRUE); +} + void merge_trips_cb(GtkWidget *menuitem, GtkTreePath *trippath) { GtkTreePath *prevpath; @@ -1784,3 +1797,26 @@ int unsaved_changes() { return dive_list.changed; } + +void remove_autogen_trips() +{ + GtkTreeIter iter; + GtkTreePath *path; + time_t when; + int idx; + GList *trip; + + /* start with the first top level entry and walk all of them */ + path = gtk_tree_path_new_from_string("0"); + while(gtk_tree_model_get_iter(TREEMODEL(dive_list), &iter, path)) { + gtk_tree_model_get(TREEMODEL(dive_list), &iter, DIVE_INDEX, &idx, DIVE_DATE, &when, -1); + if (idx < 0) { + trip = FIND_TRIP(when); + if (DIVE_TRIP(trip)->tripflag == IN_TRIP) { /* this was autogen */ + remove_trip(path, FALSE); + continue; + } + } + gtk_tree_path_next(path); + } +} diff --git a/divelist.h b/divelist.h index c170941db..45c1a18f8 100644 --- a/divelist.h +++ b/divelist.h @@ -10,4 +10,5 @@ extern void flush_divelist(struct dive *); extern void update_cylinder_related_info(struct dive *); extern void mark_divelist_changed(int); extern int unsaved_changes(void); +extern void remove_autogen_trips(void); #endif @@ -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 = " \ <ui> \ <menubar name=\"MainMenu\"> \ @@ -779,6 +792,7 @@ static const gchar* ui_string = " \ <menuitem name=\"Add Dive\" action=\"AddDive\" /> \ <separator name=\"Separator\"/> \ <menuitem name=\"Renumber\" action=\"Renumber\" /> \ + <menuitem name=\"Autogroup\" action=\"Autogroup\" /> \ <menuitem name=\"Toggle Zoom\" action=\"ToggleZoom\" /> \ <menu name=\"View\" action=\"ViewMenuAction\"> \ <menuitem name=\"List\" action=\"ViewList\" /> \ @@ -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; |