viscal

cairo/gtk vi-like timeblocking calendar
git clone git://jb55.com/viscal
Log | Files | Refs | README | LICENSE

commit 2516e186b57e66b7c9f1dc037e1fb704057f1504
parent acf974adf51d6b30e5b8be0cf429bdcda64b1155
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  3 Dec 2018 08:30:07 -0800

pushmove down with C-j

Diffstat:
Mviscal.c | 48++++++++++++++++++++++++++++++++++++------------
1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/viscal.c b/viscal.c @@ -570,7 +570,10 @@ static struct event *get_target(struct cal *cal) { static icaltimetype icaltime_from_timet_ours(time_t time, int is_date, struct cal *cal) { - return icaltime_from_timet_with_zone(time, is_date, cal->tz); + icaltimezone *tz; + tz = cal == NULL ? g_cal_tz : cal->tz; + + return icaltime_from_timet_with_zone(time, is_date, tz); } static void calendar_drop(struct cal *cal, double mx, double my) { @@ -1079,10 +1082,8 @@ static void zoom_out(struct cal *cal) { zoom(cal, zoom_amt); } - static void push_down(struct cal *cal, int from, int ind, time_t push_to) { - icaltimetype dtstart, dtend; time_t f_st, from_event_et, st, et, new_et; struct event *ev, *fromev; @@ -1100,13 +1101,7 @@ static void push_down(struct cal *cal, int from, int ind, time_t push_to) return; new_et = et + (push_to - st); - - dtstart = icaltime_from_timet_ours(push_to, 0, cal); - dtend = icaltime_from_timet_ours(new_et, 0, cal); - - // TODO: undo - icalcomponent_set_dtstart(ev->vevent, dtstart); - icalcomponent_set_dtend(ev->vevent, dtend); + move_event_to(ev, push_to); if (ind + 1 > cal->nevents - 1) return; @@ -1115,6 +1110,29 @@ static void push_down(struct cal *cal, int from, int ind, time_t push_to) push_down(cal, ind, ind+1, new_et); } +static void pushmove_down(struct cal *cal) { + time_t st, et, push_to, new_st; + struct event *ev; + + ev = get_selected_event(cal); + + if (ev == NULL) + return; + + vevent_span_timet(ev->vevent, &st, &et); + + // TODO: configurable? + static const int adjust = SMALLEST_TIMEBLOCK * 60; + + new_st = st + adjust; + push_to = new_st + (et - st); + + move_event_to(ev, new_st); + + push_down(cal, cal->selected_event_ind, cal->selected_event_ind+1, + push_to); +} + static void open_below(struct cal *cal) { time_t st, et; @@ -1463,6 +1481,9 @@ static gboolean on_keypress (GtkWidget *widget, GdkEvent *event, switch (event->type) { case GDK_KEY_PRESS: + printf("DEBUG keystring %x %d\n", + *event->key.string, event->key.state); + if (cal->flags & CAL_CHANGING) { state_changed = on_edit_keypress(cal, &event->key); debug_edit_buffer(&event->key); @@ -1502,8 +1523,6 @@ static gboolean on_keypress (GtkWidget *widget, GdkEvent *event, break; } - printf("DEBUG keystring %x\n", *event->key.string); - switch (key) { // Ctrl-d @@ -1557,6 +1576,11 @@ static gboolean on_keypress (GtkWidget *widget, GdkEvent *event, move_event_action(cal, 1); break; + // Ctrl-j + case 0xa: + pushmove_down(cal); + break; + case 'j': move_down(cal, cal->repeat); break;