Add support for moving items to another day
When moving an item (or when changing the start time of an item), allow for optionally specifying a date. If both date and time are entered, the item is updated to start on the given date and time. If only a date is entered, the item is modified to start on the given date, keeping the current start time. If only a time is entered, the item is modified to start on the current date and the new start time. Fixes GitHub issue #12. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
1003be18df
commit
1f39b5c668
38
src/ui-day.c
38
src/ui-day.c
@ -61,26 +61,42 @@ void ui_day_set_selitem(struct day_item *day)
|
|||||||
/* Request the user to enter a new time. */
|
/* Request the user to enter a new time. */
|
||||||
static int day_edit_time(int time)
|
static int day_edit_time(int time)
|
||||||
{
|
{
|
||||||
char *timestr = date_sec2date_str(time, "%H:%M");
|
char *input = date_sec2date_str(time, "%H:%M");
|
||||||
const char *msg_time =
|
const char *msg_time =
|
||||||
_("Enter start time ([hh:mm] or [hhmm]):");
|
_("Enter start time ([hh:mm] or [hhmm]) or date:");
|
||||||
const char *enter_str = _("Press [Enter] to continue");
|
const char *enter_str = _("Press [Enter] to continue");
|
||||||
const char *fmt_msg =
|
const char *fmt_msg =
|
||||||
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
|
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
|
||||||
int hour, minute;
|
unsigned int hour, minute;
|
||||||
|
int year, month, day;
|
||||||
|
struct date new_date;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
status_mesg(msg_time, "");
|
status_mesg(msg_time, "");
|
||||||
if (updatestring(win[STA].p, ×tr, 0, 1) !=
|
if (updatestring(win[STA].p, &input, 0, 1) != GETSTRING_VALID)
|
||||||
GETSTRING_VALID)
|
|
||||||
return 0;
|
return 0;
|
||||||
if (parse_time(timestr, &hour, &minute) == 1) {
|
char *inputcpy = mem_strdup(input);
|
||||||
mem_free(timestr);
|
char *p = strtok(inputcpy, " ");
|
||||||
return update_time_in_date(time, hour, minute);
|
while (p) {
|
||||||
} else {
|
if (parse_date(p, conf.input_datefmt, &year, &month,
|
||||||
status_mesg(fmt_msg, enter_str);
|
&day, ui_calendar_get_slctd_day())) {
|
||||||
wgetch(win[KEY].p);
|
new_date.dd = day;
|
||||||
|
new_date.mm = month;
|
||||||
|
new_date.yyyy = year;
|
||||||
|
time = date2sec(new_date, 0, 0) +
|
||||||
|
get_item_time(time);
|
||||||
|
} else if (parse_time(p, &hour, &minute) == 1) {
|
||||||
|
time = update_time_in_date(time, hour, minute);
|
||||||
|
} else {
|
||||||
|
status_mesg(fmt_msg, enter_str);
|
||||||
|
wgetch(win[KEY].p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p = strtok(NULL, " ");
|
||||||
}
|
}
|
||||||
|
mem_free(inputcpy);
|
||||||
|
if (!p)
|
||||||
|
return time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user