mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: detangle unregister_dive() and delete_single_dive()
These two functions were called in different contexts: - unregister_dive(): from the undo-commands to remove the dive from the global dive table, but not delete it. The dive was already removed from its trip. - delete_single_dive(): from non-undo code. Most of it not in use and removed in a sibling-commit. Here, the dive is supposed to be removed from its trip and a new selection is calculated. delete_single_dive() calls unregister_dive(), which removes the dive from its trip. Move remove_dive_from_trip() from the former to the latter and make both functions independent. Instead of deleting the dive explicitly in delete_single_dive(), call the delete_dive_from_table() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
dfd7f98129
commit
c64c9c923b
1 changed files with 8 additions and 9 deletions
|
|
@ -1075,16 +1075,15 @@ void delete_dive_from_table(struct dive_table *table, int idx)
|
||||||
unregister_dive_from_table(table, idx);
|
unregister_dive_from_table(table, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this removes a dive from the dive table and trip-list but doesn't
|
/* This removes a dive from the global dive table but doesn't free the
|
||||||
* free the resources associated with the dive. It returns a pointer
|
* resources associated with the dive. The caller must removed the dive
|
||||||
* to the unregistered dive. The returned dive has the selection-
|
* from the trip-list. Returns a pointer to the unregistered dive.
|
||||||
* and hidden-flags cleared. */
|
* The unregistered dive has the selection- and hidden-flags cleared. */
|
||||||
struct dive *unregister_dive(int idx)
|
struct dive *unregister_dive(int idx)
|
||||||
{
|
{
|
||||||
struct dive *dive = get_dive(idx);
|
struct dive *dive = get_dive(idx);
|
||||||
if (!dive)
|
if (!dive)
|
||||||
return NULL; /* this should never happen */
|
return NULL; /* this should never happen */
|
||||||
remove_dive_from_trip(dive, false);
|
|
||||||
unregister_dive_from_table(&dive_table, idx);
|
unregister_dive_from_table(&dive_table, idx);
|
||||||
if (dive->selected)
|
if (dive->selected)
|
||||||
amount_selected--;
|
amount_selected--;
|
||||||
|
|
@ -1092,8 +1091,8 @@ struct dive *unregister_dive(int idx)
|
||||||
return dive;
|
return dive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this implements the mechanics of removing the dive from the table,
|
/* this implements the mechanics of removing the dive from the global
|
||||||
* but doesn't deal with updating dive trips, etc */
|
* dive table and the trip, but doesn't deal with updating dive trips, etc */
|
||||||
void delete_single_dive(int idx)
|
void delete_single_dive(int idx)
|
||||||
{
|
{
|
||||||
struct dive *dive = get_dive(idx);
|
struct dive *dive = get_dive(idx);
|
||||||
|
|
@ -1101,8 +1100,8 @@ void delete_single_dive(int idx)
|
||||||
return; /* this should never happen */
|
return; /* this should never happen */
|
||||||
if (dive->selected)
|
if (dive->selected)
|
||||||
deselect_dive(dive);
|
deselect_dive(dive);
|
||||||
dive = unregister_dive(idx);
|
remove_dive_from_trip(dive, false);
|
||||||
free_dive(dive);
|
delete_dive_from_table(&dive_table, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dive **grow_dive_table(struct dive_table *table)
|
struct dive **grow_dive_table(struct dive_table *table)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue