aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2019-06-10 21:48:16 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2019-06-16 15:03:02 -0400
commitcc86516f64fefc565c5b2477b4696085a297e5a0 (patch)
tree598dcf21dac39daf111edb643c39d9606c5d512d /src
parentf37473717108863ffc9ade89c478e119977088f4 (diff)
downloadcalcurse-cc86516f64fefc565c5b2477b4696085a297e5a0.tar.gz
calcurse-cc86516f64fefc565c5b2477b4696085a297e5a0.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h2
-rw-r--r--src/recur.c5
-rw-r--r--src/ui-day.c59
3 files changed, 43 insertions, 23 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index d32c534..98b1f71 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -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 *);
diff --git a/src/recur.c b/src/recur.c
index 46f669d..fc1d538 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -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)
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: