aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/calcurse.c8
-rw-r--r--src/calcurse.h4
-rw-r--r--src/day.c2
-rw-r--r--src/ui-calendar.c6
-rw-r--r--src/ui-day.c23
-rw-r--r--src/utils.c13
6 files changed, 43 insertions, 13 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index 6313818..a72ce6f 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -418,9 +418,8 @@ static inline void key_move_up(void)
ui_calendar_move(DAY_PREV, 1);
do_storage(1);
ui_day_sel_dayend();
- wins_update(FLAG_CAL);
}
- wins_update(FLAG_APP);
+ wins_update(FLAG_APP | FLAG_CAL);
} else if (wins_slctd() == TOD) {
ui_todo_sel_move(-1);
wins_update(FLAG_TOD);
@@ -440,12 +439,11 @@ static inline void key_move_down(void)
key_generic_next_week();
} else if (wins_slctd() == APP) {
if (!ui_day_sel_move(1)) {
- ui_calendar_move(DAY_NEXT, 1);
+ ui_calendar_move(DAY_PREV, day_get_days() - 2);
do_storage(1);
ui_day_sel_daybegin(day_get_days() - 1);
- wins_update(FLAG_CAL);
}
- wins_update(FLAG_APP);
+ wins_update(FLAG_APP | FLAG_CAL);
} else if (wins_slctd() == TOD) {
ui_todo_sel_move(1);
wins_update(FLAG_TOD);
diff --git a/src/calcurse.h b/src/calcurse.h
index 3429ee2..f14b0bb 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -781,6 +781,7 @@ unsigned ui_calendar_week_begins_on_monday(void);
void ui_calendar_store_current_date(struct date *);
void ui_calendar_init_slctd_day(void);
struct date *ui_calendar_get_slctd_day(void);
+void ui_calendar_set_slctd_day(struct date);
void ui_calendar_monthly_view_cache_set_invalid(void);
void ui_calendar_update_panel(void);
void ui_calendar_goto_today(void);
@@ -825,7 +826,7 @@ void day_write_stdout(time_t, const char *, const char *, const char *,
void day_popup_item(struct day_item *);
int day_check_if_item(struct date);
unsigned day_chk_busy_slices(struct date, int, int *);
-struct day_item *day_cut_item(time_t, int);
+struct day_item *day_cut_item(int);
int day_paste_item(struct day_item *, time_t);
struct day_item *day_get_item(int);
unsigned day_item_count(int);
@@ -1176,6 +1177,7 @@ int get_item_hour(time_t);
int get_item_min(time_t);
struct tm date2tm(struct date, unsigned, unsigned);
time_t date2sec(struct date, unsigned, unsigned);
+struct date sec2date(time_t);
time_t utcdate2sec(struct date, unsigned, unsigned);
int date_cmp(struct date *, struct date *);
int date_cmp_day(time_t, time_t);
diff --git a/src/day.c b/src/day.c
index 44f9540..b454c85 100644
--- a/src/day.c
+++ b/src/day.c
@@ -719,7 +719,7 @@ unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices)
}
/* Cut an item so it can be pasted somewhere else later. */
-struct day_item *day_cut_item(time_t date, int item_number)
+struct day_item *day_cut_item(int item_number)
{
struct day_item *p = day_get_item(item_number);
diff --git a/src/ui-calendar.c b/src/ui-calendar.c
index e4e1b4d..97cabf4 100644
--- a/src/ui-calendar.c
+++ b/src/ui-calendar.c
@@ -208,6 +208,12 @@ static int ui_calendar_get_wday(struct date *date)
return t.tm_wday;
}
+/* Set the selected day in the calendar. */
+void ui_calendar_set_slctd_day(struct date day)
+{
+ slctd_day = day;
+}
+
void ui_calendar_monthly_view_cache_set_invalid(void)
{
monthly_view_cache_valid = 0;
diff --git a/src/ui-day.c b/src/ui-day.c
index f7fddef..b959c07 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -39,6 +39,14 @@
struct day_item day_cut[38] = { {0, 0, 0, {NULL}} };
/*
+ * Set the selected day in the calendar from the selected item in the APP panel.
+ */
+static void set_slctd_day(void)
+{
+ ui_calendar_set_slctd_day(sec2date(ui_day_get_sel()->order));
+}
+
+/*
* 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.
@@ -52,7 +60,7 @@ struct day_item *ui_day_get_sel(void)
}
/*
- * Set the selected item from the saved day_item.
+ * Set the selected item and day from the saved day_item.
*/
void ui_day_find_sel(void)
{
@@ -60,6 +68,7 @@ void ui_day_find_sel(void)
if ((n = day_sel_index()) != -1)
listbox_set_sel(&lb_apt, n);
+ set_slctd_day();
}
/*
@@ -107,6 +116,7 @@ static void daybegin(int dir)
leave:
listbox_set_sel(&lb_apt, sel);
listbox_item_in_view(&lb_apt, sel);
+ set_slctd_day();
}
/*
@@ -752,7 +762,7 @@ void ui_day_item_delete(unsigned reg)
"Delete (i)tem or just its (n)ote?");
const char *note_choices = _("[in]");
const int nb_note_choices = 2;
- time_t date = 0, occurrence;
+ time_t occurrence;
if (day_item_count(0) <= 0)
return;
@@ -808,7 +818,7 @@ void ui_day_item_delete(unsigned reg)
}
ui_day_item_cut_free(reg);
- p = day_cut_item(date, listbox_get_sel(&lb_apt));
+ p = day_cut_item(listbox_get_sel(&lb_apt));
day_cut[reg].type = p->type;
day_cut[reg].item = p->item;
/* Keep the selection on the same day. */
@@ -853,7 +863,7 @@ void ui_day_item_repeat(void)
int item_nb;
struct day_item *p;
struct recur_apoint *ra;
- time_t until, date;
+ time_t until;
unsigned days;
if (day_item_count(0) <= 0)
@@ -944,7 +954,6 @@ void ui_day_item_repeat(void)
keys_wgetch(win[KEY].p);
}
- date = get_slctd_day();
/* Set the selected APP item. */
struct day_item d = empty_day;
if (p->type == EVNT) {
@@ -966,7 +975,7 @@ void ui_day_item_repeat(void)
day_set_sel_data(&d);
ui_day_item_cut_free(REG_BLACK_HOLE);
- p = day_cut_item(date, item_nb);
+ p = day_cut_item(item_nb);
day_cut[REG_BLACK_HOLE].type = p->type;
day_cut[REG_BLACK_HOLE].item = p->item;
io_set_modified();
@@ -1040,6 +1049,7 @@ void ui_day_sel_reset(void)
/* Make the day visible. */
if (lb_apt.item_sel)
listbox_item_in_view(&lb_apt, lb_apt.item_sel - 1);
+ set_slctd_day();
}
int ui_day_sel_move(int delta)
@@ -1050,6 +1060,7 @@ int ui_day_sel_move(int delta)
/* When moving up, make the line above visible. */
if (delta < 0 && ret && lb_apt.item_sel)
listbox_item_in_view(&lb_apt, lb_apt.item_sel - 1);
+ set_slctd_day();
return ret;
}
diff --git a/src/utils.c b/src/utils.c
index 8bd72e6..c04c0a6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -408,6 +408,19 @@ time_t date2sec(struct date day, unsigned hour, unsigned min)
return t;
}
+/* Return the (calcurse) date of a (Unix) time in seconds. */
+struct date sec2date(time_t t)
+{
+ struct tm tm;
+ struct date d;
+
+ localtime_r(&t, &tm);
+ d.dd = tm.tm_mday;
+ d.mm = tm.tm_mon + 1;
+ d.yyyy = tm.tm_year + 1900;
+ return d;
+}
+
time_t utcdate2sec(struct date day, unsigned hour, unsigned min)
{
char *tz;