aboutsummaryrefslogtreecommitdiffstats
path: root/src/calcurse.c
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2020-10-07 19:51:18 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2020-10-11 09:59:35 -0400
commit95151e3f0c2a9935abe6e498fd056a57075ea0c5 (patch)
treea989360f2c061902c363a92e00c233f77f735822 /src/calcurse.c
parent4d9d50722a57be05bd3ba296721e0faf935c5b59 (diff)
downloadcalcurse-95151e3f0c2a9935abe6e498fd056a57075ea0c5.tar.gz
calcurse-95151e3f0c2a9935abe6e498fd056a57075ea0c5.zip
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 <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/calcurse.c')
-rw-r--r--src/calcurse.c52
1 files changed, 49 insertions, 3 deletions
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);