src/calendar.c: Add a count parameter to calendar_move()
Allows for moving more than one step forward/backward. This is not used anywhere yet but a key binding will likely be added in one of the following patches. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
6bdc36b15a
commit
2d5ce0d95c
@ -478,7 +478,7 @@ main (int argc, char **argv)
|
|||||||
case KEY_MOVE_RIGHT:
|
case KEY_MOVE_RIGHT:
|
||||||
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY)
|
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY)
|
||||||
{
|
{
|
||||||
calendar_move (RIGHT);
|
calendar_move (RIGHT, 1);
|
||||||
inday = do_storage (1);
|
inday = do_storage (1);
|
||||||
wins_update (FLAG_CAL | FLAG_APP);
|
wins_update (FLAG_CAL | FLAG_APP);
|
||||||
}
|
}
|
||||||
@ -488,7 +488,7 @@ main (int argc, char **argv)
|
|||||||
case KEY_MOVE_LEFT:
|
case KEY_MOVE_LEFT:
|
||||||
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY)
|
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY)
|
||||||
{
|
{
|
||||||
calendar_move (LEFT);
|
calendar_move (LEFT, 1);
|
||||||
inday = do_storage (1);
|
inday = do_storage (1);
|
||||||
wins_update (FLAG_CAL | FLAG_APP);
|
wins_update (FLAG_CAL | FLAG_APP);
|
||||||
}
|
}
|
||||||
@ -498,7 +498,7 @@ main (int argc, char **argv)
|
|||||||
case KEY_MOVE_UP:
|
case KEY_MOVE_UP:
|
||||||
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK)
|
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK)
|
||||||
{
|
{
|
||||||
calendar_move (UP);
|
calendar_move (UP, 1);
|
||||||
inday = do_storage (1);
|
inday = do_storage (1);
|
||||||
wins_update (FLAG_CAL | FLAG_APP);
|
wins_update (FLAG_CAL | FLAG_APP);
|
||||||
}
|
}
|
||||||
@ -521,7 +521,7 @@ main (int argc, char **argv)
|
|||||||
case KEY_MOVE_DOWN:
|
case KEY_MOVE_DOWN:
|
||||||
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK)
|
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK)
|
||||||
{
|
{
|
||||||
calendar_move (DOWN);
|
calendar_move (DOWN, 1);
|
||||||
inday = do_storage (1);
|
inday = do_storage (1);
|
||||||
wins_update (FLAG_CAL | FLAG_APP);
|
wins_update (FLAG_CAL | FLAG_APP);
|
||||||
}
|
}
|
||||||
@ -544,7 +544,7 @@ main (int argc, char **argv)
|
|||||||
case KEY_START_OF_WEEK:
|
case KEY_START_OF_WEEK:
|
||||||
if (wins_slctd () == CAL)
|
if (wins_slctd () == CAL)
|
||||||
{
|
{
|
||||||
calendar_move (WEEK_START);
|
calendar_move (WEEK_START, 1);
|
||||||
inday = do_storage (1);
|
inday = do_storage (1);
|
||||||
wins_update (FLAG_CAL | FLAG_APP);
|
wins_update (FLAG_CAL | FLAG_APP);
|
||||||
}
|
}
|
||||||
@ -553,7 +553,7 @@ main (int argc, char **argv)
|
|||||||
case KEY_END_OF_WEEK:
|
case KEY_END_OF_WEEK:
|
||||||
if (wins_slctd () == CAL)
|
if (wins_slctd () == CAL)
|
||||||
{
|
{
|
||||||
calendar_move (WEEK_END);
|
calendar_move (WEEK_END, 1);
|
||||||
inday = do_storage (1);
|
inday = do_storage (1);
|
||||||
wins_update (FLAG_CAL | FLAG_APP);
|
wins_update (FLAG_CAL | FLAG_APP);
|
||||||
}
|
}
|
||||||
|
@ -611,7 +611,7 @@ long calendar_get_slctd_day_sec (void);
|
|||||||
void calendar_update_panel (struct window *);
|
void calendar_update_panel (struct window *);
|
||||||
void calendar_goto_today (void);
|
void calendar_goto_today (void);
|
||||||
void calendar_change_day (int);
|
void calendar_change_day (int);
|
||||||
void calendar_move (enum move);
|
void calendar_move (enum move, int);
|
||||||
long calendar_start_of_year (void);
|
long calendar_start_of_year (void);
|
||||||
long calendar_end_of_year (void);
|
long calendar_end_of_year (void);
|
||||||
char *calendar_get_pom (time_t);
|
char *calendar_get_pom (time_t);
|
||||||
|
@ -665,7 +665,7 @@ calendar_change_day (int datefmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
calendar_move (enum move move)
|
calendar_move (enum move move, int count)
|
||||||
{
|
{
|
||||||
int ret, days_to_remove, days_to_add;
|
int ret, days_to_remove, days_to_add;
|
||||||
struct tm t;
|
struct tm t;
|
||||||
@ -681,25 +681,25 @@ calendar_move (enum move move)
|
|||||||
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
|
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
|
||||||
&& (slctd_day.yyyy == 1902))
|
&& (slctd_day.yyyy == 1902))
|
||||||
return;
|
return;
|
||||||
ret = date_change (&t, 0, -WEEKINDAYS);
|
ret = date_change (&t, 0, -count * WEEKINDAYS);
|
||||||
break;
|
break;
|
||||||
case DOWN:
|
case DOWN:
|
||||||
if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
|
if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
|
||||||
&& (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
|
&& (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
|
||||||
return;
|
return;
|
||||||
ret = date_change (&t, 0, WEEKINDAYS);
|
ret = date_change (&t, 0, count * WEEKINDAYS);
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
|
if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
|
||||||
&& (slctd_day.yyyy == 1902))
|
&& (slctd_day.yyyy == 1902))
|
||||||
return;
|
return;
|
||||||
ret = date_change (&t, 0, -1);
|
ret = date_change (&t, 0, -count);
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
|
if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
|
||||||
&& (slctd_day.yyyy == 2037))
|
&& (slctd_day.yyyy == 2037))
|
||||||
return;
|
return;
|
||||||
ret = date_change (&t, 0, 1);
|
ret = date_change (&t, 0, count);
|
||||||
break;
|
break;
|
||||||
case WEEK_START:
|
case WEEK_START:
|
||||||
/* Normalize struct tm to get week day number. */
|
/* Normalize struct tm to get week day number. */
|
||||||
@ -708,7 +708,8 @@ calendar_move (enum move move)
|
|||||||
days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1);
|
days_to_remove = ((t.tm_wday == 0) ? WEEKINDAYS - 1 : t.tm_wday - 1);
|
||||||
else
|
else
|
||||||
days_to_remove = ((t.tm_wday == 0) ? 0 : t.tm_wday);
|
days_to_remove = ((t.tm_wday == 0) ? 0 : t.tm_wday);
|
||||||
ret = date_change (&t, 0, 0 - days_to_remove);
|
days_to_remove += (count - 1) * WEEKINDAYS;
|
||||||
|
ret = date_change (&t, 0, -days_to_remove);
|
||||||
break;
|
break;
|
||||||
case WEEK_END:
|
case WEEK_END:
|
||||||
(void)mktime (&t);
|
(void)mktime (&t);
|
||||||
@ -717,6 +718,7 @@ calendar_move (enum move move)
|
|||||||
else
|
else
|
||||||
days_to_add = ((t.tm_wday == 0) ?
|
days_to_add = ((t.tm_wday == 0) ?
|
||||||
WEEKINDAYS - 1 : WEEKINDAYS - 1 - t.tm_wday);
|
WEEKINDAYS - 1 : WEEKINDAYS - 1 - t.tm_wday);
|
||||||
|
days_to_add += (count - 1) * WEEKINDAYS;
|
||||||
ret = date_change (&t, 0, days_to_add);
|
ret = date_change (&t, 0, days_to_add);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user