summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-10-06 14:48:18 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-10-21 08:58:53 +0200
commit28c98f7d0136b4a533e26f076886aa242c709f1c (patch)
treecedf2e865eefc9d605203d0b7f3c119a51f66ad8
parente9b4f82fbf67ac6c91950ac3e906f0d8ab7176ac (diff)
downloadcalcurse-28c98f7d0136b4a533e26f076886aa242c709f1c.tar.gz
calcurse-28c98f7d0136b4a533e26f076886aa242c709f1c.zip
src/day.c: Allow editing an item's duration
We have the option to enter either an end time or a duration when creating an item - the same choice should be available when editing an item. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/day.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/day.c b/src/day.c
index af59303..b264887 100644
--- a/src/day.c
+++ b/src/day.c
@@ -596,6 +596,50 @@ day_edit_time (int time, unsigned *new_hour, unsigned *new_minute)
}
}
+/* Request the user to enter a new time or duration. */
+static int
+day_edit_duration (int start, int dur, unsigned *new_duration)
+{
+ char *timestr = date_sec2date_str (start + dur, "%H:%M");
+ char *msg_time = _("Enter the new time ([hh:mm]) or duration ([+hh:mm]): ");
+ char *enter_str = _("Press [Enter] to continue");
+ char *fmt_msg = _("You entered an invalid time, should be [hh:mm]");
+ long newtime;
+ unsigned hr, mn;
+
+ for (;;)
+ {
+ status_mesg (msg_time, "");
+ if (updatestring (win[STA].p, &timestr, 0, 1) == GETSTRING_VALID)
+ {
+ if (*timestr == '+' && parse_duration (timestr + 1,
+ new_duration) == 1)
+ {
+ *new_duration *= MININSEC;
+ break;
+ }
+ else if (parse_time (timestr, &hr, &mn) == 1)
+ {
+ newtime = update_time_in_date (start + dur, hr, mn);
+ *new_duration = (newtime > start) ? newtime - start :
+ DAYINSEC + newtime - start;
+ break;
+ }
+ else
+ {
+ status_mesg (fmt_msg, enter_str);
+ (void)wgetch (win[STA].p);
+ }
+ }
+ else
+ return 0;
+ }
+
+ mem_free (timestr);
+ return 1;
+}
+
+/* Request the user to enter a new end time or duration. */
static void
update_start_time (long *start, long *dur)
{
@@ -628,12 +672,10 @@ update_start_time (long *start, long *dur)
static void
update_duration (long *start, long *dur)
{
- long newtime;
- unsigned hr, mn;
+ unsigned newdur;
- day_edit_time (*start + *dur, &hr, &mn);
- newtime = update_time_in_date (*start, hr, mn);
- *dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start;
+ day_edit_duration (*start, *dur, &newdur);
+ *dur = newdur;
}
static void