mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Undo: make "move dive computer to front" undoable
Instead of the elegant solution that just modifies the dive, keep two copies and add either the old or the new copy. This is primitive, but it trivially keeps the dives in the right order. The order might change on renumbering the dive computers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f0307abf50
commit
eba6e76b96
7 changed files with 106 additions and 23 deletions
43
core/dive.c
43
core/dive.c
|
|
@ -4151,27 +4151,42 @@ bool dive_remove_picture(struct dive *d, const char *filename)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* this always acts on the current divecomputer of the current dive */
|
||||
void make_first_dc()
|
||||
/* clones a dive and moves given dive computer to front */
|
||||
struct dive *make_first_dc(const struct dive *d, int dc_number)
|
||||
{
|
||||
struct divecomputer *dc = ¤t_dive->dc;
|
||||
struct divecomputer *newdc = malloc(sizeof(*newdc));
|
||||
struct divecomputer *cur_dc = current_dc; /* needs to be in a local variable so the macro isn't re-executed */
|
||||
struct dive *res;
|
||||
struct divecomputer *dc, *newdc, *old_dc;
|
||||
|
||||
/* 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);
|
||||
|
||||
if (dc_number == 0)
|
||||
return res;
|
||||
|
||||
dc = &res->dc;
|
||||
newdc = malloc(sizeof(*newdc));
|
||||
old_dc = get_dive_dc(res, dc_number);
|
||||
|
||||
/* skip the current DC in the linked list */
|
||||
while (dc && dc->next != cur_dc)
|
||||
dc = dc->next;
|
||||
for (dc = &res->dc; dc && dc->next != old_dc; dc = dc->next)
|
||||
;
|
||||
if (!dc) {
|
||||
free(newdc);
|
||||
fprintf(stderr, "data inconsistent: can't find the current DC");
|
||||
return;
|
||||
return res;
|
||||
}
|
||||
dc->next = cur_dc->next;
|
||||
*newdc = current_dive->dc;
|
||||
current_dive->dc = *cur_dc;
|
||||
current_dive->dc.next = newdc;
|
||||
free(cur_dc);
|
||||
invalidate_dive_cache(current_dive);
|
||||
dc->next = old_dc->next;
|
||||
*newdc = res->dc;
|
||||
res->dc = *old_dc;
|
||||
res->dc.next = newdc;
|
||||
free(old_dc);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* always acts on the current dive */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue