mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
22ff8df880
commit
f6e8903a52
3 changed files with 55 additions and 3 deletions
40
divelist.c
40
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue