From 6907ae73e76d11c201ff237663af79b3bbfc5385 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 27 Jun 2012 08:52:42 +0200 Subject: Revise cut/pasting Instead of calling type-specific duplication handlers and inserting clones of the original items when pasting, save the generic day item and remove the actual item from the linked list, so that it can be inserted anywhere else later. The cut/paste buffer is moved to the interaction unit, item-specific cut operations are changed to remove the item from the linked list only instead of copying and freeing it. An item is only freed if another item is cut before the current cut/paste buffer is pasted. All paste operations are changed and reinsert the actual item instead of creating a clone. Signed-off-by: Lukas Fleischer --- src/day.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/day.c') diff --git a/src/day.c b/src/day.c index 087d8b7..2488c59 100644 --- a/src/day.c +++ b/src/day.c @@ -595,60 +595,55 @@ unsigned day_chk_busy_slices(struct date day, int slicesno, int *slices) } /* Cut an item so it can be pasted somewhere else later. */ -int day_cut_item(long date, int item_number) +struct day_item *day_cut_item(long date, int item_number) { - const int DELETE_WHOLE = 1; - struct day_item *p; + struct day_item *p = day_get_item(item_number); - p = day_get_item(item_number); switch (p->type) { case EVNT: event_delete(p->item.ev, ERASE_CUT); break; case RECUR_EVNT: - recur_event_erase(p->item.rev, date, DELETE_WHOLE, ERASE_CUT); + recur_event_erase(p->item.rev, date, 1, ERASE_CUT); break; case APPT: apoint_delete(p->item.apt, ERASE_CUT); break; case RECUR_APPT: - recur_apoint_erase(p->item.rapt, date, DELETE_WHOLE, ERASE_CUT); + recur_apoint_erase(p->item.rapt, date, 1, ERASE_CUT); break; default: EXIT(_("unknwon type")); /* NOTREACHED */ } - return p->type; + return p; } /* Paste a previously cut item. */ -int day_paste_item(long date, int cut_item_type) +int day_paste_item(struct day_item *p, long date) { - int pasted_item_type; - - pasted_item_type = cut_item_type; - switch (cut_item_type) { + switch (p->type) { case 0: return 0; case EVNT: - event_paste_item(); + event_paste_item(p->item.ev, date); break; case RECUR_EVNT: - recur_event_paste_item(); + recur_event_paste_item(p->item.rev, date); break; case APPT: - apoint_paste_item(); + apoint_paste_item(p->item.apt, date); break; case RECUR_APPT: - recur_apoint_paste_item(); + recur_apoint_paste_item(p->item.rapt, date); break; default: EXIT(_("unknwon type")); /* NOTREACHED */ } - return pasted_item_type; + return p->type; } /* Returns a structure containing the selected item. */ -- cgit v1.2.3