diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2020-01-10 20:39:19 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2020-01-13 20:45:25 +0100 |
commit | 12863ff7c05e4abe601890157b222eaee9737ad5 (patch) | |
tree | a1ee93b8cfc8d37b540bdb563f43327b26ae6dfb /src/ui-day.c | |
parent | 002cf305a59d311d1dc3806009ecae90a5d9be38 (diff) | |
download | calcurse-12863ff7c05e4abe601890157b222eaee9737ad5.tar.gz calcurse-12863ff7c05e4abe601890157b222eaee9737ad5.zip |
Refactor cut and paste registers
Register REG_BLACK_HOLE can neither be copied into nor pasted from and
has been removed from the input routine.
Register 36 was not used.
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/ui-day.c')
-rw-r--r-- | src/ui-day.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/ui-day.c b/src/ui-day.c index e0e306b..912f700 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -36,7 +36,8 @@ #include "calcurse.h" -struct day_item day_cut[38] = { {0, 0, 0, {NULL}} }; +/* Cut & paste registers. */ +static struct day_item day_cut[REG_BLACK_HOLE + 1]; /* * Set the selected day in the calendar from the selected item in the APP panel. @@ -834,11 +835,7 @@ void ui_day_item_delete(unsigned reg) return; } } - - ui_day_item_cut_free(reg); - p = day_cut_item(listbox_get_sel(&lb_apt)); - day_cut[reg].type = p->type; - day_cut[reg].item = p->item; + ui_day_item_cut(reg); /* Keep the selection on the same day. */ day_set_sel_data(day_get_item(listbox_get_sel(&lb_apt) - 1)); io_set_modified(); @@ -995,11 +992,7 @@ void ui_day_item_repeat(void) /* NOTREACHED */ } day_set_sel_data(&d); - - ui_day_item_cut_free(REG_BLACK_HOLE); - p = day_cut_item(item_nb); - day_cut[REG_BLACK_HOLE].type = p->type; - day_cut[REG_BLACK_HOLE].item = p->item; + ui_day_item_cut(REG_BLACK_HOLE); io_set_modified(); ui_calendar_monthly_view_cache_set_invalid(); @@ -1008,9 +1001,23 @@ cleanup: mem_free(msg_asktype); } +/* Delete an item and save it in a register. */ +void ui_day_item_cut(unsigned reg) +{ + struct day_item *p; + + ui_day_item_cut_free(reg); + + p = day_cut_item(listbox_get_sel(&lb_apt)); + day_cut[reg].type = p->type; + day_cut[reg].item = p->item; +} + /* Free the current cut item, if any. */ void ui_day_item_cut_free(unsigned reg) { + EXIT_IF(reg > REG_BLACK_HOLE, "illegal register"); + if (!day_cut[reg].type) { /* No previously cut item, don't free anything. */ return; |