summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-24 08:27:42 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-24 08:27:42 -0700
commitba1c4fcec1760748846ff6ad14127409bed0a783 (patch)
treec0e4b16c620ccfd420459605c1e7e4f5caf8b75f /divelist.c
parent2a88a72f1aeae6a0dd9713d9c4779d8d009f9335 (diff)
downloadsubsurface-ba1c4fcec1760748846ff6ad14127409bed0a783.tar.gz
Add some helper functions
First step towards getting the "add to trip" logic in the divelist context menu to be consistent and correct. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c
index 1daf0f5ac..a3207b02c 100644
--- a/divelist.c
+++ b/divelist.c
@@ -578,6 +578,44 @@ void find_new_trip_start_time(dive_trip_t *trip)
trip->when = when;
}
+/* check if we have a trip right before / after this dive */
+bool is_trip_before_after(struct dive *dive, bool before)
+{
+ int idx = get_idx_by_uniq_id(dive->id);
+ if (before) {
+ if (idx > 0 && get_dive(idx - 1)->divetrip)
+ return true;
+ } else {
+ if (idx < dive_table.nr - 1 && get_dive(idx + 1)->divetrip)
+ return true;
+ }
+ return false;
+}
+
+struct dive *first_selected_dive()
+{
+ int idx;
+ struct dive *d;
+
+ for_each_dive (idx, d) {
+ if (d->selected)
+ return d;
+ }
+ return NULL;
+}
+
+struct dive *last_selected_dive()
+{
+ int idx;
+ struct dive *d, *ret = NULL;
+
+ for_each_dive (idx, d) {
+ if (d->selected)
+ ret = d;
+ }
+ return ret;
+}
+
void remove_dive_from_trip(struct dive *dive, short was_autogen)
{
struct dive *next, **pprev;