From 47d5fe2d45688c376a9646e798ca564e6bb4a6b6 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 27 Jun 2012 08:02:30 +0200 Subject: Move apoint_{cut,paste}() to interaction unit These functions get the current selection, call day_*_item() and fix the current selection on the appointment panel, so move them where they belong. Signed-off-by: Lukas Fleischer --- src/apoint.c | 51 --------------------------------------------------- src/calcurse.c | 4 ++-- src/calcurse.h | 4 ++-- src/interaction.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/apoint.c b/src/apoint.c index e6e02c4..ce872df 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -135,57 +135,6 @@ struct apoint *apoint_new(char *mesg, char *note, long start, long dur, return apt; } -/* Cut an item, so that it can be pasted somewhere else later. */ -int apoint_cut(unsigned *nb_events, unsigned *nb_apoints) -{ - const int NBITEMS = *nb_apoints + *nb_events; - int item_type, to_be_removed; - long date; - - if (NBITEMS == 0) - return 0; - - date = calendar_get_slctd_day_sec(); - item_type = day_cut_item(date, hilt); - if (item_type == EVNT || item_type == RECUR_EVNT) { - (*nb_events)--; - to_be_removed = 1; - } else if (item_type == APPT || item_type == RECUR_APPT) { - (*nb_apoints)--; - to_be_removed = 3; - } else - EXIT(_("no such type")); - /* NOTREACHED */ - - if (hilt > 1) - hilt--; - if (apad.first_onscreen >= to_be_removed) - apad.first_onscreen = apad.first_onscreen - to_be_removed; - if (NBITEMS == 1) - hilt = 0; - - return item_type; -} - -/* Paste a previously cut item. */ -void apoint_paste(unsigned *nb_events, unsigned *nb_apoints, int cut_item_type) -{ - int item_type; - long date; - - date = calendar_get_slctd_day_sec(); - item_type = day_paste_item(date, cut_item_type); - if (item_type == EVNT || item_type == RECUR_EVNT) - (*nb_events)++; - else if (item_type == APPT || item_type == RECUR_APPT) - (*nb_apoints)++; - else - return; - - if (hilt == 0) - hilt++; -} - unsigned apoint_inday(struct apoint *i, long *start) { return (i->start <= *start + DAYINSEC && i->start + i->dur > *start); diff --git a/src/calcurse.c b/src/calcurse.c index 3708236..ed28a30 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -287,7 +287,7 @@ int main(int argc, char **argv) case KEY_GENERIC_CUT: if (wins_slctd() == APP && apoint_hilt() != 0) { - cut_item = apoint_cut(&inday.nb_events, &inday.nb_apoints); + cut_item = interact_day_item_cut(&inday.nb_events, &inday.nb_apoints); inday = do_storage(0); wins_update(FLAG_CAL | FLAG_APP); } @@ -295,7 +295,7 @@ int main(int argc, char **argv) case KEY_GENERIC_PASTE: if (wins_slctd() == APP) { - apoint_paste(&inday.nb_events, &inday.nb_apoints, cut_item); + interact_day_item_paste(&inday.nb_events, &inday.nb_apoints, cut_item); cut_item = 0; inday = do_storage(0); wins_update(FLAG_CAL | FLAG_APP); diff --git a/src/calcurse.h b/src/calcurse.h index 2986420..59e4f1c 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -598,8 +598,6 @@ void apoint_hilt_decrease(int); void apoint_hilt_increase(int); int apoint_hilt(void); struct apoint *apoint_new(char *, char *, long, long, char); -int apoint_cut(unsigned *, unsigned *); -void apoint_paste(unsigned *, unsigned *, int); unsigned apoint_inday(struct apoint *, long *); void apoint_sec2str(struct apoint *, long, char *, char *); void apoint_write(struct apoint *, FILE *); @@ -716,6 +714,8 @@ void interact_day_item_delete(unsigned *, unsigned *); void interact_day_item_edit(void); void interact_day_item_pipe(void); void interact_day_item_repeat(void); +int interact_day_item_cut(unsigned *, unsigned *); +void interact_day_item_paste(unsigned *, unsigned *, int); void interact_todo_add(void); void interact_todo_delete(void); void interact_todo_edit(void); diff --git a/src/interaction.c b/src/interaction.c index c1febe3..1a021be 100644 --- a/src/interaction.c +++ b/src/interaction.c @@ -858,3 +858,54 @@ void interact_day_item_repeat(void) day_erase_item(date, item_nb, ERASE_FORCE); } +/* Cut an item, so that it can be pasted somewhere else later. */ +int interact_day_item_cut(unsigned *nb_events, unsigned *nb_apoints) +{ + const int NBITEMS = *nb_apoints + *nb_events; + int item_type, to_be_removed; + long date; + + if (NBITEMS == 0) + return 0; + + date = calendar_get_slctd_day_sec(); + item_type = day_cut_item(date, apoint_hilt()); + if (item_type == EVNT || item_type == RECUR_EVNT) { + (*nb_events)--; + to_be_removed = 1; + } else if (item_type == APPT || item_type == RECUR_APPT) { + (*nb_apoints)--; + to_be_removed = 3; + } else + EXIT(_("no such type")); + /* NOTREACHED */ + + if (apoint_hilt() > 1) + apoint_hilt_decrease(1); + if (apad.first_onscreen >= to_be_removed) + apad.first_onscreen = apad.first_onscreen - to_be_removed; + if (NBITEMS == 1) + apoint_hilt_set(0); + + return item_type; +} + +/* Paste a previously cut item. */ +void interact_day_item_paste(unsigned *nb_events, unsigned *nb_apoints, + int cut_item_type) +{ + int item_type; + long date; + + date = calendar_get_slctd_day_sec(); + item_type = day_paste_item(date, cut_item_type); + if (item_type == EVNT || item_type == RECUR_EVNT) + (*nb_events)++; + else if (item_type == APPT || item_type == RECUR_APPT) + (*nb_apoints)++; + else + return; + + if (apoint_hilt() == 0) + apoint_hilt_increase(1); +} -- cgit v1.2.3-54-g00ecf