From 066df02cbf44d58a9b1e3a30b1310dc0f460e4c4 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Mon, 17 Dec 2018 10:42:13 +0100 Subject: Introduce multiple days in the appointments panel Overview of existing implementation ----------------------------------- The APP panel displays the 'day_items' vector in the 'lb_apt' listbox. A listbox consists of a scrollwin (structure) in which a number of items is displayed. The listbox keeps track of: - the number of items - the selected item - the type of each item in an array type[] - the height of each item (ie. how many screen lines) in an array ch[] - how to display an item (on the screen) The latter three are handled by functions fn_type(), fn_height(), fn_draw(). The first two are used to fill in the corresponding array entry, type[] or ch[], for item number i, the third draws item number i. The items are taken from the global variables vector_t day_items int day_items_nb in day.c. Items include captions (DAY_HEADING, DAY_SEPARATOR). Everything is sorted for display (DAY_HEADING, events, DAY_SEPARATOR, appts). These are filled in ("stored") [by day_store_items() for the selected day in the calendar], before being "loaded" into the listbox. See do_storage() in calcurse.c and ui_day_item_add() in ui-day.c. New APP panel design -------------------- Several days are displayed in the APP panel by loading them with day_store_items(). With several days come several headings and separators. DAY_SEPARATOR is reinterpreted to separate days, and a new separator, EVNT_SEPARATOR, separates events from appointments. To sort everything, an 'order' member of type time_t is added to the day_item structure. It is set for headings and separators as well as for appointments and events as follows: item order --------------------- DAY_HEADING BGNOFDAY (= midnight) EVNT_SEPARATOR BGNOFDAY DAY_SEPARATOR ENDOFDAY event start time (midnight) appointment start time (first day) BGNOFDAY (following days, if any) The sort function day_cmp() (used by vector_sort) is extended to sort by order first. The order field always indicates the day to which an item belongs. This comes in handy, because with several days in the APP panel it is necessary to distinguish between the selected day in the calendar and the selected day in the APP panel. This raises the question which day should actions (commands) operate on: the one selected in the calendar or the one selected in the APP panel? Unquestionably the one on the APP panel which is the one tacitly implied. In most cases it is not a problem, though, because actions work on the selected item and the selected day does not come into play. But in some cases it does: delete item When deleting an occurrence of a repeated item, the selected day is the exception day to add. view item day_popup_item() needs the day of the selected item for display of correct start/end times. cut/paste item Paste needs the selected day in which to paste. add item The day of the new item is taken from the calendar. Instead a dummy event is inserted in an empty day. This makes the day selectable, which is otherwise impossible with only the DAY_HEADING displayed. The dummy event is selectable but cannot be edited or deleted (but viewed or piped). With more than one day in the day_items vecter, an appointment spanning more than one day may occur more than once in the vector (with start/end times suitably adjusted for display). A day_item is no longer (always) identified by the aptev_ptr (item) value. Instead the combination (order, item.) is used; order is roughly the day. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/ui-day.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/ui-day.c') diff --git a/src/ui-day.c b/src/ui-day.c index bb5063f..32e12bf 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -36,8 +36,11 @@ #include "calcurse.h" -struct day_item day_cut[38] = { {0, 0, {NULL}} }; +struct day_item day_cut[38] = { {0, 0, 0, {NULL}} }; +/* + * Return the selected item in the APP panel. + */ struct day_item *ui_day_selitem(void) { if (day_item_count(0) <= 0) @@ -46,6 +49,14 @@ struct day_item *ui_day_selitem(void) return day_get_item(listbox_get_sel(&lb_apt)); } +/* + * Return the day (midnight) of the selected item in the APP panel. + */ +time_t ui_day_selday(void) +{ + return update_time_in_date(ui_day_selitem()->order, 0, 0); +} + void ui_day_set_selitem_by_aptev_ptr(union aptev_ptr p) { int n = day_get_position_by_aptev_ptr(p); @@ -579,7 +590,7 @@ void ui_day_item_add(void) const char *enter_str = _("Press [Enter] to continue"); char item_time[LTIME] = ""; char item_mesg[BUFSIZ] = ""; - time_t start = date2sec(*ui_calendar_get_slctd_day(), 0, 0), end, saved = start; + time_t start = ui_day_selday(), end, saved = start; unsigned dur; int is_appointment = 1; union aptev_ptr item; @@ -672,7 +683,7 @@ void ui_day_item_add(void) item.ev = event_new(item_mesg, 0L, start, 1); } io_set_modified(); - day_store_items(get_slctd_day(), 1); + day_store_items(get_slctd_day(), 1, day_get_nb()); ui_day_load_items(); ui_day_set_selitem_by_aptev_ptr(item); } @@ -963,7 +974,7 @@ void ui_day_item_paste(unsigned reg) return; day_item_fork(&day_cut[reg], &day); - day_paste_item(&day, get_slctd_day()); + day_paste_item(&day, ui_day_selday()); io_set_modified(); ui_calendar_monthly_view_cache_set_invalid(); @@ -998,9 +1009,9 @@ static char *fmt_day_heading(time_t date) /* Display appointments in the corresponding panel. */ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) { - struct date slctd_date = *ui_calendar_get_slctd_day(); - time_t date = date2sec(slctd_date, 0, 0); struct day_item *item = day_get_item(n); + /* The item order always indicates the date. */ + time_t date = update_time_in_date(item->order, 0, 0); int width = lb_apt.sw.w - 2; hilt = hilt && (wins_slctd() == APP); @@ -1019,7 +1030,7 @@ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) (width - utf8_strwidth(buf)) / 2, "%s", buf); custom_remove_attr(win, ATTR_HIGHEST); mem_free(buf); - } else if (item->type == DAY_SEPARATOR) { + } else if (item->type == EVNT_SEPARATOR) { wmove(win, y, 0); whline(win, 0, width); } @@ -1029,7 +1040,9 @@ enum listbox_row_type ui_day_row_type(int n, void *cb_data) { struct day_item *item = day_get_item(n); - if (item->type == DAY_HEADING || item->type == DAY_SEPARATOR) + if (item->type == DAY_HEADING || + item->type == EVNT_SEPARATOR || + item->type == DAY_SEPARATOR) return LISTBOX_ROW_CAPTION; else return LISTBOX_ROW_TEXT; @@ -1041,6 +1054,8 @@ int ui_day_height(int n, void *cb_data) if (item->type == APPT || item->type == RECUR_APPT) return 3; + else if (item->type == DAY_SEPARATOR) + return 2; else return 1; } -- cgit v1.2.3