From 2f9960f20b292a2fa8c01da4a0c4600c71f4fc3a Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 15 Dec 2012 20:40:16 -1000 Subject: [PATCH] Deal with some trip issues when editing dive timestamps The idea behind editing timestamps had of course been the typical "oops, I forgot to set my time correctly" which shifts a dive (or a few of them) by a few hours but keeps the overall order of dives the same). But reasonable people might argue that they can envision a scenario where more dramatic changes are being made. And we need to deal with the impact this has on dive trips. Here we handle a couple of simple cases: - this is the only dive in a trip; just update the trip (this can still cause problems if the new time is in the middle of an existing trip). - this dives moves before the start of the trip it is in; let's remove it from that trip (this response is a bit simplistic - but as I tried to say, I don't expect this to be a common use case; and removing it at least doesn't lead to entirely unexpected behavior). - this dive moves past the end of this trip into the range of a different trip (in this case we remove the dive from the current trip and allow it to interrupt the trip it is moving into). Signed-off-by: Dirk Hohndel --- divelist.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/divelist.c b/divelist.c index a917889c4..19ee031c6 100644 --- a/divelist.c +++ b/divelist.c @@ -1441,6 +1441,14 @@ void edit_dive_when_cb(GtkWidget *menuitem, struct dive *dive) gtk_widget_destroy(dialog); when = utc_mktime(&tm); if (dive->when != when) { + /* if this is the only dive in the trip, just change the trip time */ + if (dive->divetrip && dive->divetrip->nrdives == 1) + dive->divetrip->when = when; + /* if this is suddenly before the start of the trip, remove it from the trip */ + else if (dive->divetrip && dive->divetrip->when > when) + remove_dive_from_trip(dive); + else if (find_matching_trip(when) != dive->divetrip) + remove_dive_from_trip(dive); dive->when = when; mark_divelist_changed(TRUE); remember_tree_state();