From 0bc96905bf92de5e7bac88efde181d93d95998f1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 19 May 2019 14:27:10 +0200 Subject: Undo: make "delete dive computer" undoable Simply reuse the code for "move dive computer" by creating a DiveComputerBase base class. Signed-off-by: Berthold Stoeger --- core/dive.c | 18 +++++++++++++++--- core/dive.h | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/dive.c b/core/dive.c index e6b27e0bb..b8162edd0 100644 --- a/core/dive.c +++ b/core/dive.c @@ -4234,10 +4234,22 @@ static void delete_divecomputer(struct dive *d, int num) invalidate_dive_cache(d); } -/* always acts on the current dive */ -void delete_current_divecomputer(void) +/* Clone a dive and delete goven dive computer */ +struct dive *clone_delete_divecomputer(const struct dive *d, int dc_number) { - delete_divecomputer(current_dive, dc_number); + struct dive *res; + + /* copy the dive */ + res = alloc_dive(); + copy_dive(d, res); + + /* make a new unique id, since we still can't handle two equal ids */ + res->id = dive_getUniqID(); + invalidate_dive_cache(res); + + delete_divecomputer(res, dc_number); + + return res; } /* diff --git a/core/dive.h b/core/dive.h index ebc127bd7..e26e0e02e 100644 --- a/core/dive.h +++ b/core/dive.h @@ -436,7 +436,7 @@ extern timestamp_t dive_endtime(const struct dive *dive); extern struct dive *make_first_dc(const struct dive *d, int dc_number); extern unsigned int count_divecomputers(void); -extern void delete_current_divecomputer(void); +extern struct dive *clone_delete_divecomputer(const struct dive *d, int dc_number); void split_divecomputer(const struct dive *src, int num, struct dive **out1, struct dive **out2); /* -- cgit v1.2.3-70-g09d2