Remove the need for the "day_saved_item" struct

Do not store the currently selected item in day_write_pad() -- use
day_get_item() and apoint_hilt() in day_popup_item() instead.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-06-25 12:54:28 +02:00
parent 920875d7cb
commit 75d0c4dc17
2 changed files with 24 additions and 34 deletions

View File

@ -42,16 +42,7 @@
#include "calcurse.h" #include "calcurse.h"
struct day_saved_item {
char start[BUFSIZ];
char end[BUFSIZ];
char state;
char type;
char *mesg;
};
static llist_t day_items; static llist_t day_items;
static struct day_saved_item day_saved_item;
static void day_free(struct day_item *day) static void day_free(struct day_item *day)
{ {
@ -406,14 +397,11 @@ display_item(struct day_item *day, int incolor, int width, int y, int x)
/* /*
* Write the appointments and events for the selected day in a pad. * Write the appointments and events for the selected day in a pad.
* An horizontal line is drawn between events and appointments, and the * An horizontal line is drawn between events and appointments, and the
* item selected by user is highlighted. This item is also saved inside * item selected by user is highlighted.
* structure (pointed by day_saved_item), to be later displayed in a
* popup window if requested.
*/ */
void day_write_pad(long date, int width, int length, int incolor) void day_write_pad(long date, int width, int length, int incolor)
{ {
llist_item_t *i; llist_item_t *i;
struct apoint a;
int line, item_number; int line, item_number;
const int x_pos = 0; const int x_pos = 0;
unsigned draw_line = 0; unsigned draw_line = 0;
@ -426,10 +414,6 @@ void day_write_pad(long date, int width, int length, int incolor)
/* First print the events for current day. */ /* First print the events for current day. */
if (day->type < RECUR_APPT) { if (day->type < RECUR_APPT) {
item_number++; item_number++;
if (item_number - incolor == 0) {
day_saved_item.type = day->type;
day_saved_item.mesg = day_item_get_mesg(day);
}
display_item(day, item_number - incolor, width - 7, line, x_pos); display_item(day, item_number - incolor, width - 7, line, x_pos);
line++; line++;
draw_line = 1; draw_line = 1;
@ -442,11 +426,6 @@ void day_write_pad(long date, int width, int length, int incolor)
} }
/* Last print the appointments for current day. */ /* Last print the appointments for current day. */
item_number++; item_number++;
if (item_number - incolor == 0) {
day_saved_item.type = day->type;
day_saved_item.mesg = day_item_get_mesg(day);
apoint_sec2str(&a, date, day_saved_item.start, day_saved_item.end);
}
display_item_date(day, item_number - incolor, date, line + 1, x_pos); display_item_date(day, item_number - incolor, date, line + 1, x_pos);
display_item(day, item_number - incolor, width - 7, line + 2, x_pos); display_item(day, item_number - incolor, width - 7, line + 2, x_pos);
line += 3; line += 3;
@ -457,15 +436,26 @@ void day_write_pad(long date, int width, int length, int incolor)
/* Display an item inside a popup window. */ /* Display an item inside a popup window. */
void day_popup_item(void) void day_popup_item(void)
{ {
if (day_saved_item.type == EVNT || day_saved_item.type == RECUR_EVNT) struct day_item *day = day_get_item(apoint_hilt());
item_in_popup(NULL, NULL, day_saved_item.mesg, _("Event :"));
else if (day_saved_item.type == APPT || day_saved_item.type == RECUR_APPT) if (day->type == EVNT || day->type == RECUR_EVNT) {
item_in_popup(day_saved_item.start, day_saved_item.end, item_in_popup(NULL, NULL, day_item_get_mesg(day), _("Event :"));
day_saved_item.mesg, _("Appointment :")); } else if (day->type == APPT || day->type == RECUR_APPT) {
else char a_st[100], a_end[100];
/* FIXME: Redesign apoint_sec2str() and remove the need for a temporary
* appointment item here. */
struct apoint apt_tmp;
apt_tmp.start = day->start;
apt_tmp.dur = day_item_get_duration(day);
apoint_sec2str(&apt_tmp, calendar_get_slctd_day_sec(), a_st, a_end);
item_in_popup(a_st, a_end, day_item_get_mesg(day), _("Appointment :"));
} else {
EXIT(_("unknown item type")); EXIT(_("unknown item type"));
/* NOTREACHED */ /* NOTREACHED */
} }
}
/* /*
* Need to know if there is an item for the current selected day inside * Need to know if there is an item for the current selected day inside

View File

@ -492,8 +492,8 @@ draw_scrollbar(WINDOW * win, int y, int x, int length,
* long to fit in its corresponding panel window. * long to fit in its corresponding panel window.
*/ */
void void
item_in_popup(const char *saved_a_start, const char *saved_a_end, item_in_popup(const char *a_start, const char *a_end, const char *msg,
const char *msg, const char *pop_title) const char *pop_title)
{ {
WINDOW *popup_win, *pad; WINDOW *popup_win, *pad;
const int margin_left = 4, margin_top = 4; const int margin_left = 4, margin_top = 4;
@ -502,9 +502,9 @@ item_in_popup(const char *saved_a_start, const char *saved_a_end,
pad = newpad(padl, padw); pad = newpad(padl, padw);
popup_win = popup(winl, winw, 1, 2, pop_title, NULL, 1); popup_win = popup(winl, winw, 1, 2, pop_title, NULL, 1);
if (strcmp(pop_title, _("Appointment")) == 0) { if (a_start && a_end) {
mvwprintw(popup_win, margin_top, margin_left, "- %s -> %s", mvwprintw(popup_win, margin_top, margin_left, "- %s -> %s", a_start,
saved_a_start, saved_a_end); a_end);
} }
mvwaddstr(pad, 0, margin_left, msg); mvwaddstr(pad, 0, margin_left, msg);
wmove(win[STA].p, 0, 0); wmove(win[STA].p, 0, 0);