Treat recurrence item parameters as a unit

An edit session, and in particular, a cancelled edit session should encompass
all parameters.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2019-06-10 21:48:16 +02:00 committed by Lukas Fleischer
parent f374737171
commit cc86516f64
3 changed files with 43 additions and 23 deletions

View File

@ -1022,7 +1022,7 @@ void pcal_export_data(FILE *);
/* recur.c */
extern llist_ts_t recur_alist_p;
extern llist_t recur_elist;
void recur_update_exc(llist_t *, char *);
int recur_update_exc(llist_t *, char *);
char *recur_exc2str(llist_t *);
struct recur_event *recur_event_dup(struct recur_event *);
struct recur_apoint *recur_apoint_dup(struct recur_apoint *);

View File

@ -106,8 +106,9 @@ char *recur_exc2str(llist_t *exc)
* Update the list of exceptions from a string of days. Any positive number of
* spaces are allowed before, between and after the days.
*/
void recur_update_exc(llist_t *exc, char *days)
int recur_update_exc(llist_t *exc, char *days)
{
int updated = 0;
char *d;
time_t t = get_today();
llist_t nexc;
@ -131,8 +132,10 @@ void recur_update_exc(llist_t *exc, char *days)
}
free_exc_list(exc);
exc_dup(exc, &nexc);
updated = 1;
cleanup:
free_exc_list(&nexc);
return updated;
}
struct recur_event *recur_event_dup(struct recur_event *in)

View File

@ -272,7 +272,38 @@ static void update_desc(char **desc)
updatestring(win[STA].p, desc, 0, 1);
}
static void update_rept(struct rpt **rpt, const long start)
/* Edit the list of exception days for a recurrent item. */
static int update_exc(llist_t *exc)
{
int updated = 0;
if (!exc->head)
return updated;
char *days;
enum getstr ret;
status_mesg(_("Exception days:"), "");
days = recur_exc2str(exc);
while (1) {
ret = updatestring(win[STA].p, &days, 0, 1);
if (ret == GETSTRING_VALID || ret == GETSTRING_RET) {
if (recur_update_exc(exc, days)) {
updated = 1;
break;
} else {
status_mesg(_("Invalid date format - try again:."), "");
mem_free(days);
days = recur_exc2str(exc);
}
} else if (ret == GETSTRING_ESC)
break;
}
mem_free(days);
return updated;
}
static void update_rept(struct rpt **rpt, const time_t start, llist_t *exc)
{
/* Pointers to dynamically allocated memory. */
char *msg_rpt_current = NULL;
@ -412,6 +443,10 @@ static void update_rept(struct rpt **rpt, const long start)
keys_wgetch(win[KEY].p);
}
/* Update exception list. */
if (!update_exc(exc))
goto cleanup;
(*rpt)->type = recur_char2def(newtype);
(*rpt)->freq = newfreq;
(*rpt)->until = newuntil;
@ -424,22 +459,6 @@ cleanup:
mem_free(outstr);
}
/* Edit the list of exception days for a recurrent item. */
static void update_exc(llist_t *exc)
{
if (!exc->head)
return;
char *days;
enum getstr ret;
status_mesg(_("Exception days:"), "");
days = recur_exc2str(exc);
ret = updatestring(win[STA].p, &days, 0, 1);
if (ret == GETSTRING_VALID || ret == GETSTRING_RET)
recur_update_exc(exc, days);
mem_free(days);
}
/* Edit an already existing item. */
void ui_day_item_edit(void)
{
@ -468,8 +487,7 @@ void ui_day_item_edit(void)
io_set_modified();
break;
case 2:
update_rept(&re->rpt, re->day);
update_exc(&re->exc);
update_rept(&re->rpt, re->day, &re->exc);
io_set_modified();
break;
default:
@ -510,8 +528,7 @@ void ui_day_item_edit(void)
break;
case 4:
need_check_notify = 1;
update_rept(&ra->rpt, ra->start);
update_exc(&ra->exc);
update_rept(&ra->rpt, ra->start, &ra->exc);
io_set_modified();
break;
case 5: