aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui-day.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui-day.c')
-rw-r--r--src/ui-day.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/ui-day.c b/src/ui-day.c
index 32e12bf..4b37a90 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -39,34 +39,35 @@
struct day_item day_cut[38] = { {0, 0, 0, {NULL}} };
/*
- * Return the selected item in the APP panel.
+ * Return the selected APP item.
+ * This is a pointer into the day vector and invalid after a day vector rebuild,
+ * but the (order, item) data may be used to refind the object.
*/
-struct day_item *ui_day_selitem(void)
+struct day_item *ui_day_get_sel(void)
{
if (day_item_count(0) <= 0)
- return NULL;
+ return &empty_day;
return day_get_item(listbox_get_sel(&lb_apt));
}
/*
- * Return the day (midnight) of the selected item in the APP panel.
+ * Set the selected item from the saved day_item.
*/
-time_t ui_day_selday(void)
+void ui_day_find_sel(void)
{
- return update_time_in_date(ui_day_selitem()->order, 0, 0);
-}
+ int n;
-void ui_day_set_selitem_by_aptev_ptr(union aptev_ptr p)
-{
- int n = day_get_position_by_aptev_ptr(p);
- if (n >= 0)
+ if ((n = day_sel_index()) != -1)
listbox_set_sel(&lb_apt, n);
}
-void ui_day_set_selitem(struct day_item *day)
+/*
+ * Return the date (midnight) of the selected item in the APP panel.
+ */
+time_t ui_day_sel_date(void)
{
- ui_day_set_selitem_by_aptev_ptr(day->item);
+ return update_time_in_date(ui_day_get_sel()->order, 0, 0);
}
/*
@@ -406,7 +407,7 @@ void ui_day_item_edit(void)
if (day_item_count(0) <= 0)
return;
- struct day_item *p = ui_day_selitem();
+ struct day_item *p = ui_day_get_sel();
switch (p->type) {
case RECUR_EVNT:
@@ -534,7 +535,7 @@ void ui_day_item_pipe(void)
if (day_item_count(0) <= 0)
return;
- struct day_item *p = ui_day_selitem();
+ struct day_item *p = ui_day_get_sel();
status_mesg(_("Pipe item to external command:"), "");
if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
@@ -590,7 +591,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 = ui_day_selday(), end, saved = start;
+ time_t start = ui_day_sel_date(), end, saved = start;
unsigned dur;
int is_appointment = 1;
union aptev_ptr item;
@@ -683,9 +684,11 @@ 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_get_nb());
- ui_day_load_items();
- ui_day_set_selitem_by_aptev_ptr(item);
+ /* Set the selected APP item. */
+ struct day_item d = empty_day;
+ d.order = start;
+ d.item = item;
+ day_set_sel_data(&d);
}
ui_calendar_monthly_view_cache_set_invalid();
@@ -715,7 +718,7 @@ void ui_day_item_delete(unsigned reg)
if (day_item_count(0) <= 0)
return;
- struct day_item *p = ui_day_selitem();
+ struct day_item *p = ui_day_get_sel();
if (conf.confirm_delete) {
if (status_ask_bool(del_app_str) != 1) {
@@ -745,12 +748,10 @@ void ui_day_item_delete(unsigned reg)
break;
case 2:
if (p->type == RECUR_EVNT) {
- date = get_slctd_day();
- day_item_add_exc(p, date);
+ day_item_add_exc(p, ui_day_sel_date());
} else {
- date = update_time_in_date(p->start, 0, 0);
recur_apoint_find_occurrence(p->item.rapt,
- date,
+ ui_day_sel_date(),
&occurrence);
day_item_add_exc(p, occurrence);
}
@@ -900,21 +901,25 @@ void ui_day_item_repeat(void)
}
date = get_slctd_day();
+ /* Set the selected APP item. */
+ struct day_item d = empty_day;
if (p->type == EVNT) {
struct event *ev = p->item.ev;
- recur_event_new(ev->mesg, ev->note, ev->day, ev->id, type,
- freq, until, NULL);
+ d.item.rev = recur_event_new(ev->mesg, ev->note, ev->day,
+ ev->id, type, freq, until, NULL);
} else if (p->type == APPT) {
struct apoint *apt = p->item.apt;
- ra = recur_apoint_new(apt->mesg, apt->note, apt->start,
- apt->dur, apt->state, type, freq,
- until, NULL);
+ d.item.rapt = ra = recur_apoint_new(apt->mesg, apt->note,
+ apt->start, apt->dur,
+ apt->state, type, freq,
+ until, NULL);
if (notify_bar())
notify_check_repeated(ra);
} else {
EXIT(_("wrong item type"));
/* NOTREACHED */
}
+ day_set_sel_data(&d);
ui_day_item_cut_free(REG_BLACK_HOLE);
p = day_cut_item(date, item_nb);
@@ -960,7 +965,7 @@ void ui_day_item_copy(unsigned reg)
if (day_item_count(0) <= 0 || reg == REG_BLACK_HOLE)
return;
- struct day_item *item = ui_day_selitem();
+ struct day_item *item = ui_day_get_sel();
ui_day_item_cut_free(reg);
day_item_fork(item, &day_cut[reg]);
}
@@ -968,15 +973,15 @@ void ui_day_item_copy(unsigned reg)
/* Paste a previously cut item. */
void ui_day_item_paste(unsigned reg)
{
- struct day_item day;
+ struct day_item day = empty_day;
if (reg == REG_BLACK_HOLE || !day_cut[reg].type)
return;
day_item_fork(&day_cut[reg], &day);
- day_paste_item(&day, ui_day_selday());
+ day_paste_item(&day, ui_day_sel_date());
+ day_set_sel_data(&day);
io_set_modified();
-
ui_calendar_monthly_view_cache_set_invalid();
}
@@ -1071,7 +1076,7 @@ void ui_day_popup_item(void)
if (day_item_count(0) <= 0)
return;
- struct day_item *item = ui_day_selitem();
+ struct day_item *item = ui_day_get_sel();
day_popup_item(item);
}
@@ -1080,7 +1085,7 @@ void ui_day_flag(void)
if (day_item_count(0) <= 0)
return;
- struct day_item *item = ui_day_selitem();
+ struct day_item *item = ui_day_get_sel();
day_item_switch_notify(item);
io_set_modified();
}
@@ -1090,7 +1095,7 @@ void ui_day_view_note(void)
if (day_item_count(0) <= 0)
return;
- struct day_item *item = ui_day_selitem();
+ struct day_item *item = ui_day_get_sel();
day_view_note(item, conf.pager);
}
@@ -1099,7 +1104,7 @@ void ui_day_edit_note(void)
if (day_item_count(0) <= 0)
return;
- struct day_item *item = ui_day_selitem();
+ struct day_item *item = ui_day_get_sel();
day_edit_note(item, conf.editor);
io_set_modified();
}