From 95151e3f0c2a9935abe6e498fd056a57075ea0c5 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Wed, 7 Oct 2020 19:51:18 +0200 Subject: Add p(revious) command The p(rev) command finds the previous occurrence of a recurrent item, analogous to the n(ext) command. A bug in the next command is corrected.. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/calcurse.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'src/calcurse.c') diff --git a/src/calcurse.c b/src/calcurse.c index 8a65fba..3083f86 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -557,7 +557,8 @@ static inline void key_generic_cmd(void) int valid = 0, force = 0, ret; char *error_msg; - status_mesg(_("Command: [ h(elp) | w(rite)(!) | q(uit)(!) | wq(!) | n(ext) ]"), ""); + status_mesg(_("Command: " + "[ h(elp) | w(rite)(!) | q(uit)(!) | wq(!) | n(ext) | p(rev) ]"), ""); if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID) goto cleanup; cmd_name = strtok(cmd, " "); @@ -638,17 +639,62 @@ static inline void key_generic_cmd(void) goto cleanup; } if (!more) { - error_msg = _("Last repetition."); + error_msg = _("Last occurrence."); warnbox(error_msg); goto cleanup; } - item->start = next; + item->order = next; ui_calendar_set_slctd_day(sec2date(next)); day_set_sel_data(item); do_storage(1); valid = 1; } + if (!strcmp(cmd_name, "prev") || !strcmp(cmd_name, "p")) { + struct day_item *item; + time_t day, prev; + struct recur_apoint *rapt; + struct recur_event *rev; + int more = 0; + + if (wins_slctd() != APP) { + error_msg = _("Select a repeating item in the" + " appointments panel."); + warnbox(error_msg); + goto cleanup; + } + item = ui_day_get_sel(); + /* + * The selected day need not be the (item) start day + * for multi-day occurrences. + */ + day = update_time_in_date(item->start, 0, 0); + if (item->type == RECUR_EVNT) { + rev = item->item.rev; + more = recur_prev_occurrence(rev->day, -1, rev->rpt, + &rev->exc, day, &prev); + } else if (item->type == RECUR_APPT) { + rapt = item->item.rapt; + more = recur_prev_occurrence(rapt->start, rapt->dur, + rapt->rpt, &rapt->exc, + day, &prev); + } else { + error_msg = _("Not a repeating item."); + warnbox(error_msg); + goto cleanup; + } + if (!more) { + error_msg = _("First occurrence."); + warnbox(error_msg); + goto cleanup; + } + item->order = prev; + ui_calendar_set_slctd_day(sec2date(prev)); + day_set_sel_data(item); + do_storage(1); + + valid = 1; + } if (!valid) { asprintf(&error_msg, _("No such command: %s"), cmd); -- cgit v1.2.3-54-g00ecf