From 65b699f7708eba7c504d8593be749fa4e0cd57c3 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 16 Feb 2016 07:48:25 +0100 Subject: Make automatic selection of appointments/events smarter Keep item selection when an item is moved (e.g. by changing the start time or description). Signed-off-by: Lukas Fleischer --- src/calcurse.c | 4 ++++ src/calcurse.h | 3 +++ src/day.c | 15 +++++++++++++++ src/ui-day.c | 15 +++++++++++++++ 4 files changed, 37 insertions(+) (limited to 'src') diff --git a/src/calcurse.c b/src/calcurse.c index e550b76..c0d9624 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -48,11 +48,15 @@ int count, reg; */ static void do_storage(int day_changed) { + struct day_item *day = ui_day_selitem(); + day_process_storage(ui_calendar_get_slctd_day(), day_changed); ui_day_load_items(); if (day_changed) ui_day_sel_reset(); + else if (day) + ui_day_set_selitem(day); } static inline void key_generic_change_view(void) diff --git a/src/calcurse.h b/src/calcurse.h index 9ee8be0..e59ea59 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -772,6 +772,7 @@ int day_check_if_item(struct date); unsigned day_chk_busy_slices(struct date, int, int *); struct day_item *day_cut_item(long, int); int day_paste_item(struct day_item *, long); +int day_get_position(struct day_item *); struct day_item *day_get_item(int); unsigned day_item_count(int); void day_edit_note(struct day_item *, const char *); @@ -1042,6 +1043,8 @@ void todo_init_list(void); void todo_free_list(void); /* ui-day.c */ +struct day_item *ui_day_selitem(void); +void ui_day_set_selitem(struct day_item *); void ui_day_item_add(void); void ui_day_item_delete(unsigned); void ui_day_item_edit(void); diff --git a/src/day.c b/src/day.c index 2a98706..fa59abb 100644 --- a/src/day.c +++ b/src/day.c @@ -700,6 +700,21 @@ int day_paste_item(struct day_item *p, long date) return p->type; } +/* Returns the position corresponding to a given item. */ +int day_get_position(struct day_item *needle) +{ + int n = 0; + + VECTOR_FOREACH(&day_items, n) { + struct day_item *p = VECTOR_NTH(&day_items, n); + /* Compare pointers. */ + if (p->item.ev == needle->item.ev) + return n; + } + + return -1; +} + /* Returns a structure containing the selected item. */ struct day_item *day_get_item(int item_number) { diff --git a/src/ui-day.c b/src/ui-day.c index 84beb77..4b004f7 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -38,6 +38,21 @@ struct day_item day_cut[38] = { {0, 0, {NULL}} }; +struct day_item *ui_day_selitem(void) +{ + if (day_item_count(0) <= 0) + return NULL; + + return day_get_item(listbox_get_sel(&lb_apt)); +} + +void ui_day_set_selitem(struct day_item *day) +{ + int n = day_get_position(day); + if (n >= 0) + listbox_set_sel(&lb_apt, n); +} + /* Request the user to enter a new time. */ static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute) -- cgit v1.2.3