mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
core: split add_event() in two parts
add_event() creates and adds an event from the given parameters. For undo, we want to do these separately, therefore split this function in two parts: create_event() and add_event_to_dc(). Keep the add_event() function for convenience. Moreover, keep the remember_event() call in there, so that undo-commands can call remember_event() once, not on every undo/redo action. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e7b5955be0
commit
2417a54675
2 changed files with 23 additions and 3 deletions
24
core/dive.c
24
core/dive.c
|
@ -125,10 +125,10 @@ int event_is_gaschange(const struct event *ev)
|
|||
ev->type == SAMPLE_EVENT_GASCHANGE2;
|
||||
}
|
||||
|
||||
struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name)
|
||||
struct event *create_event(unsigned int time, int type, int flags, int value, const char *name)
|
||||
{
|
||||
int gas_index = -1;
|
||||
struct event *ev, **p;
|
||||
struct event *ev;
|
||||
unsigned int size, len = strlen(name);
|
||||
|
||||
size = sizeof(*ev) + len + 1;
|
||||
|
@ -163,13 +163,31 @@ struct event *add_event(struct divecomputer *dc, unsigned int time, int type, in
|
|||
break;
|
||||
}
|
||||
|
||||
return ev;
|
||||
}
|
||||
|
||||
void add_event_to_dc(struct divecomputer *dc, struct event *ev)
|
||||
{
|
||||
struct event **p;
|
||||
|
||||
p = &dc->events;
|
||||
|
||||
/* insert in the sorted list of events */
|
||||
while (*p && (*p)->time.seconds <= time)
|
||||
while (*p && (*p)->time.seconds <= ev->time.seconds)
|
||||
p = &(*p)->next;
|
||||
ev->next = *p;
|
||||
*p = ev;
|
||||
}
|
||||
|
||||
struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name)
|
||||
{
|
||||
struct event *ev = create_event(time, type, flags, value, name);
|
||||
|
||||
if (!ev)
|
||||
return NULL;
|
||||
|
||||
add_event_to_dc(dc, ev);
|
||||
|
||||
remember_event(name);
|
||||
return ev;
|
||||
}
|
||||
|
|
|
@ -377,6 +377,8 @@ extern void copy_samples(const struct divecomputer *s, struct divecomputer *d);
|
|||
extern bool is_cylinder_used(const struct dive *dive, int idx);
|
||||
extern bool is_cylinder_prot(const struct dive *dive, int idx);
|
||||
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
|
||||
extern struct event *create_event(unsigned int time, int type, int flags, int value, const char *name);
|
||||
extern void add_event_to_dc(struct divecomputer *dc, struct event *ev);
|
||||
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
|
||||
extern void remove_event(struct event *event);
|
||||
extern void update_event_name(struct dive *d, struct event *event, const char *name);
|
||||
|
|
Loading…
Add table
Reference in a new issue