From cc86516f64fefc565c5b2477b4696085a297e5a0 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Mon, 10 Jun 2019 21:48:16 +0200 Subject: 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 Signed-off-by: Lukas Fleischer --- src/ui-day.c | 59 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/ui-day.c') diff --git a/src/ui-day.c b/src/ui-day.c index fa106c8..30e7540 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -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: -- cgit v1.2.3-54-g00ecf