aboutsummaryrefslogtreecommitdiffstats
path: root/src/interaction.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-06-27 08:52:42 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-06-30 14:34:36 +0200
commit6907ae73e76d11c201ff237663af79b3bbfc5385 (patch)
tree3863be2f3c8b31f7a0c138debc3e5927f9b06acd /src/interaction.c
parentb230e2949ef888010c133e4b6f7690f2e1ed2c09 (diff)
downloadcalcurse-6907ae73e76d11c201ff237663af79b3bbfc5385.tar.gz
calcurse-6907ae73e76d11c201ff237663af79b3bbfc5385.zip
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 <calcurse@cryptocrack.de>
Diffstat (limited to 'src/interaction.c')
-rw-r--r--src/interaction.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/src/interaction.c b/src/interaction.c
index 1a021be..103cdf0 100644
--- a/src/interaction.c
+++ b/src/interaction.c
@@ -36,6 +36,8 @@
#include "calcurse.h"
+struct day_item day_cut = { 0, 0, { NULL } };
+
/* Request the user to enter a new time. */
static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute)
{
@@ -858,22 +860,47 @@ void interact_day_item_repeat(void)
day_erase_item(date, item_nb, ERASE_FORCE);
}
+/* Free the current cut item, if any. */
+void interact_day_item_cut_free(void)
+{
+ switch (day_cut.type) {
+ case 0:
+ /* No previous item, don't free anything. */
+ break;
+ case APPT:
+ apoint_free(day_cut.item.apt);
+ break;
+ case EVNT:
+ event_free(day_cut.item.ev);
+ break;
+ case RECUR_APPT:
+ recur_apoint_free(day_cut.item.rapt);
+ break;
+ case RECUR_EVNT:
+ recur_event_free(day_cut.item.rev);
+ break;
+ }
+}
+
/* 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;
+ int to_be_removed;
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) {
+ interact_day_item_cut_free();
+ struct day_item *p = day_cut_item(calendar_get_slctd_day_sec(),
+ apoint_hilt());
+ day_cut.type = p->type;
+ day_cut.item = p->item;
+
+ if (p->type == EVNT || p->type == RECUR_EVNT) {
(*nb_events)--;
to_be_removed = 1;
- } else if (item_type == APPT || item_type == RECUR_APPT) {
+ } else if (p->type == APPT || p->type == RECUR_APPT) {
(*nb_apoints)--;
to_be_removed = 3;
} else
@@ -887,7 +914,7 @@ int interact_day_item_cut(unsigned *nb_events, unsigned *nb_apoints)
if (NBITEMS == 1)
apoint_hilt_set(0);
- return item_type;
+ return p->type;
}
/* Paste a previously cut item. */
@@ -895,10 +922,13 @@ 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 (!day_cut.type)
+ return;
+
+ item_type = day_paste_item(&day_cut, calendar_get_slctd_day_sec());
+ day_cut.type = 0;
+
if (item_type == EVNT || item_type == RECUR_EVNT)
(*nb_events)++;
else if (item_type == APPT || item_type == RECUR_APPT)