summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-07-07 19:14:33 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-07-07 21:39:35 +0200
commit13c21ac28023542a10cb75c085ce1925da2cdd0e (patch)
tree5d81c830a1d476d9d150ff6da03d968d6a5a3e61
parent88588ad704329939834b45eb2058fb48f0a5068f (diff)
downloadcalcurse-13c21ac28023542a10cb75c085ce1925da2cdd0e.tar.gz
calcurse-13c21ac28023542a10cb75c085ce1925da2cdd0e.zip
Merge cut/delete
Remove the cut function and merge it into the del-item command. This allows for vim-style cutting/pasting. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/calcurse.c10
-rw-r--r--src/calcurse.h4
-rw-r--r--src/help.c29
-rw-r--r--src/interaction.c193
-rw-r--r--src/keys.c2
-rw-r--r--src/wins.c3
6 files changed, 83 insertions, 158 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index 770e967..20a06e0 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -275,7 +275,7 @@ int main(int argc, char **argv)
case KEY_DEL_ITEM:
if (wins_slctd() == APP && apoint_hilt() != 0) {
- interact_day_item_delete(&inday.nb_events, &inday.nb_apoints);
+ interact_day_item_delete(&inday.nb_events, &inday.nb_apoints, reg);
inday = do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD && todo_hilt() != 0) {
@@ -284,14 +284,6 @@ int main(int argc, char **argv)
}
break;
- case KEY_GENERIC_CUT:
- if (wins_slctd() == APP && apoint_hilt() != 0) {
- interact_day_item_cut(&inday.nb_events, &inday.nb_apoints, reg);
- inday = do_storage(0);
- wins_update(FLAG_CAL | FLAG_APP);
- }
- break;
-
case KEY_GENERIC_COPY:
if (wins_slctd() == APP && apoint_hilt() != 0) {
interact_day_item_copy(&inday.nb_events, &inday.nb_apoints, reg);
diff --git a/src/calcurse.h b/src/calcurse.h
index 25a91e3..4c3d1d1 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -398,7 +398,6 @@ enum key {
KEY_GENERIC_HELP,
KEY_GENERIC_QUIT,
KEY_GENERIC_SAVE,
- KEY_GENERIC_CUT,
KEY_GENERIC_COPY,
KEY_GENERIC_PASTE,
KEY_GENERIC_CHANGE_VIEW,
@@ -722,12 +721,11 @@ void ical_export_data(FILE *);
/* interaction.c */
void interact_day_item_add(void);
-void interact_day_item_delete(unsigned *, unsigned *);
+void interact_day_item_delete(unsigned *, unsigned *, unsigned);
void interact_day_item_edit(void);
void interact_day_item_pipe(void);
void interact_day_item_repeat(void);
void interact_day_item_cut_free(unsigned);
-void interact_day_item_cut(unsigned *, unsigned *, unsigned);
void interact_day_item_copy(unsigned *, unsigned *, unsigned);
void interact_day_item_paste(unsigned *, unsigned *, unsigned);
void interact_todo_add(void);
diff --git a/src/help.c b/src/help.c
index 9ad548f..a8d3edb 100644
--- a/src/help.c
+++ b/src/help.c
@@ -60,7 +60,7 @@ typedef enum {
HELP_GOTO,
HELP_DELETE,
HELP_ADD,
- HELP_CUT_COPY_PASTE,
+ HELP_COPY_PASTE,
HELP_EDIT,
HELP_ENOTE,
HELP_VNOTE,
@@ -126,7 +126,6 @@ help_write_pad(struct window *win, char *title, char *text, enum key action)
case KEY_GENERIC_NEXT_YEAR:
case KEY_GENERIC_GOTO_TODAY:
case KEY_GENERIC_CREDITS:
- case KEY_GENERIC_CUT:
case KEY_GENERIC_COPY:
case KEY_GENERIC_PASTE:
break;
@@ -262,10 +261,9 @@ static int wanted_page(int ch)
page = HELP_DELETE;
break;
- case KEY_GENERIC_CUT:
case KEY_GENERIC_COPY:
case KEY_GENERIC_PASTE:
- page = HELP_CUT_COPY_PASTE;
+ page = HELP_COPY_PASTE;
break;
case KEY_EDIT_ITEM:
@@ -538,22 +536,17 @@ void help_screen(void)
keys_action_firstkey(KEY_ADD_ITEM),
keys_action_firstkey(KEY_ADD_ITEM));
- hscr[HELP_CUT_COPY_PASTE].title = _("Cut and Paste\n");
- snprintf(hscr[HELP_CUT_COPY_PASTE].text, HELPTEXTSIZ,
+ hscr[HELP_COPY_PASTE].title = _("Copy and Paste\n");
+ snprintf(hscr[HELP_COPY_PASTE].text, HELPTEXTSIZ,
_
(
- "Cut/copy and paste the currently selected item. This is useful to\n"
- "quickly move or copy an item from one date to another.\n"
- "To do so, one must first highlight the item that needs to be moved or\n"
- "copied, then press '%s' to cut (or '%s' to copy) this item. Once the\n"
- "new date is chosen in the calendar, the appointment panel must be\n"
- "selected and the '%s' key must be pressed to paste the item. The item\n"
- "will appear again in the appointment panel, assigned to the newly\n"
- "selected date.\n\n"
- "Be careful that if two cuts are performed successively without pasting\n"
- "between them, the item that was cut at first will be lost, together\n"
- "with its associated note if it had one."),
- keys_action_firstkey(KEY_GENERIC_CUT),
+ "Copy and paste the currently selected item. This is useful to quickly\n"
+ "copy an item from one date to another. To do so, one must first\n"
+ "highlight the item that needs to be copied, then press '%s' to copy.\n"
+ "Once the new date is chosen in the calendar, the appointment panel must\n"
+ "be selected and the '%s' key must be pressed to paste the item. The item\n"
+ "will appear in the appointment panel, assigned to the newly selected\n"
+ "date.\n\n"),
keys_action_firstkey(KEY_GENERIC_COPY),
keys_action_firstkey(KEY_GENERIC_PASTE));
diff --git a/src/interaction.c b/src/interaction.c
index d61ea4e..0a3b743 100644
--- a/src/interaction.c
+++ b/src/interaction.c
@@ -36,7 +36,7 @@
#include "calcurse.h"
-struct day_item day_cut[37] = { { 0, 0, { NULL } } };
+struct day_item day_cut[38] = { { 0, 0, { NULL } } };
/* Request the user to enter a new time. */
static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute)
@@ -364,68 +364,6 @@ void interact_day_item_edit(void)
notify_check_next_app(1);
}
-/*
- * In order to erase an item, we need to count first the number of
- * items for each type (in order: recurrent events, events,
- * recurrent appointments and appointments) and then to test the
- * type of the item to be deleted.
- */
-static int day_erase_item(long date, int item_number, enum eraseflg flag)
-{
- struct day_item *p;
-
- const char *erase_warning =
- _("This item is recurrent. "
- "Delete (a)ll occurences or just this (o)ne ?");
- const char *erase_choices = _("[ao]");
- const int nb_erase_choices = 2;
-
- const char *note_warning =
- _("This item has a note attached to it. "
- "Delete (i)tem or just its (n)ote ?");
- const char *note_choices = _("[in]");
- const int nb_note_choices = 2;
-
- p = day_get_item(item_number);
- if (flag == ERASE_DONT_FORCE && day_item_get_note(p)) {
- switch (status_ask_choice(note_warning, note_choices, nb_note_choices)) {
- case 1:
- break;
- case 2:
- day_item_erase_note(p);
- return 0;
- default: /* User escaped */
- return 0;
- }
- }
-
- flag = ERASE_FORCE;
-
- if (p->type == EVNT) {
- event_delete(p->item.ev, flag);
- } else if (p->type == APPT) {
- apoint_delete(p->item.apt, flag);
- } else {
- switch (status_ask_choice(erase_warning, erase_choices, nb_erase_choices)) {
- case 1:
- break;
- case 2:
- day_item_add_exc(p, date);
- return 0;
- default:
- return 0;
- }
-
- if (p->type == RECUR_EVNT) {
- recur_event_erase(p->item.rev, flag);
- } else {
- recur_apoint_erase(p->item.rapt, flag);
- }
- }
-
- return p->type;
-}
-
/* Pipe an appointment or event to an external program. */
void interact_day_item_pipe(void)
{
@@ -567,18 +505,32 @@ void interact_day_item_add(void)
}
/* Delete an item from the appointment list. */
-void interact_day_item_delete(unsigned *nb_events, unsigned *nb_apoints)
+void interact_day_item_delete(unsigned *nb_events, unsigned *nb_apoints,
+ unsigned reg)
{
const char *del_app_str = _("Do you really want to delete this item ?");
- long date;
+
+ const char *erase_warning =
+ _("This item is recurrent. "
+ "Delete (a)ll occurences or just this (o)ne ?");
+ const char *erase_choices = _("[ao]");
+ const int nb_erase_choices = 2;
+
+ const char *note_warning =
+ _("This item has a note attached to it. "
+ "Delete (i)tem or just its (n)ote ?");
+ const char *note_choices = _("[in]");
+ const int nb_note_choices = 2;
+
+ long date = calendar_get_slctd_day_sec();
int nb_items = *nb_apoints + *nb_events;
int to_be_removed = 0;
- date = calendar_get_slctd_day_sec();
-
if (nb_items == 0)
return;
+ struct day_item *p = day_get_item(apoint_hilt());
+
if (conf.confirm_delete) {
if (status_ask_bool(del_app_str) != 1) {
wins_erase_status_bar();
@@ -586,34 +538,59 @@ void interact_day_item_delete(unsigned *nb_events, unsigned *nb_apoints)
}
}
- if (nb_items != 0) {
- switch (day_erase_item(date, apoint_hilt(), ERASE_DONT_FORCE)) {
- case EVNT:
- case RECUR_EVNT:
- (*nb_events)--;
- to_be_removed = 1;
+ if (day_item_get_note(p)) {
+ switch (status_ask_choice(note_warning, note_choices, nb_note_choices)) {
+ case 1:
break;
- case APPT:
- case RECUR_APPT:
- (*nb_apoints)--;
- to_be_removed = 3;
+ case 2:
+ day_item_erase_note(p);
+ return;
+ default: /* User escaped */
+ return;
+ }
+ }
+
+ if (p->type == RECUR_EVNT || p->type == RECUR_APPT) {
+ switch (status_ask_choice(erase_warning, erase_choices, nb_erase_choices)) {
+ case 1:
break;
- case 0:
+ case 2:
+ day_item_add_exc(p, date);
return;
default:
- EXIT(_("no such type"));
- /* NOTREACHED */
+ return;
}
+ }
- calendar_monthly_view_cache_set_invalid();
+ interact_day_item_cut_free(reg);
+ p = day_cut_item(date, apoint_hilt());
+ day_cut[reg].type = p->type;
+ day_cut[reg].item = p->item;
- 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 (nb_items == 1)
- apoint_hilt_set(0);
+ switch (p->type) {
+ case EVNT:
+ case RECUR_EVNT:
+ (*nb_events)--;
+ to_be_removed = 1;
+ break;
+ case APPT:
+ case RECUR_APPT:
+ (*nb_apoints)--;
+ to_be_removed = 3;
+ break;
+ default:
+ EXIT(_("no such type"));
+ /* NOTREACHED */
}
+
+ calendar_monthly_view_cache_set_invalid();
+
+ 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 (nb_items == 1)
+ apoint_hilt_set(0);
}
/* Request user to enter a new todo item. */
@@ -851,7 +828,11 @@ void interact_day_item_repeat(void)
EXIT(_("wrong item type"));
/* NOTREACHED */
}
- day_erase_item(date, item_nb, ERASE_FORCE);
+
+ interact_day_item_cut_free(REG_BLACK_HOLE);
+ p = day_cut_item(date, item_nb);
+ day_cut[REG_BLACK_HOLE].type = p->type;
+ day_cut[REG_BLACK_HOLE].item = p->item;
calendar_monthly_view_cache_set_invalid();
}
@@ -878,42 +859,6 @@ void interact_day_item_cut_free(unsigned reg)
}
}
-/* Cut an item, so that it can be pasted somewhere else later. */
-void interact_day_item_cut(unsigned *nb_events, unsigned *nb_apoints,
- unsigned reg)
-{
- const int NBITEMS = *nb_apoints + *nb_events;
- int to_be_removed;
-
- if (NBITEMS == 0)
- return;
-
- interact_day_item_cut_free(reg);
- struct day_item *p = day_cut_item(calendar_get_slctd_day_sec(),
- apoint_hilt());
- day_cut[reg].type = p->type;
- day_cut[reg].item = p->item;
-
- calendar_monthly_view_cache_set_invalid();
-
- if (p->type == EVNT || p->type == RECUR_EVNT) {
- (*nb_events)--;
- to_be_removed = 1;
- } else if (p->type == APPT || p->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);
-}
-
/* Copy an item, so that it can be pasted somewhere else later. */
void interact_day_item_copy(unsigned *nb_events, unsigned *nb_apoints,
unsigned reg)
diff --git a/src/keys.c b/src/keys.c
index 38b6780..65aa00b 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -56,7 +56,6 @@ static struct keydef_s keydef[NBKEYS] = {
{"generic-help", "?"},
{"generic-quit", "q Q"},
{"generic-save", "s S C-s"},
- {"generic-cut", "C-x"},
{"generic-copy", "c"},
{"generic-paste", "C-v"},
{"generic-change-view", "TAB"},
@@ -461,7 +460,6 @@ void keys_popup_info(enum key key)
_("Display hints whenever some help screens are available.");
info[KEY_GENERIC_QUIT] = _("Exit from the current menu, or quit calcurse.");
info[KEY_GENERIC_SAVE] = _("Save calcurse data.");
- info[KEY_GENERIC_CUT] = _("Cut the item that is currently selected.");
info[KEY_GENERIC_COPY] = _("Copy the item that is currently selected.");
info[KEY_GENERIC_PASTE] = _("Paste an item at the current position.");
info[KEY_GENERIC_CHANGE_VIEW] =
diff --git a/src/wins.c b/src/wins.c
index 5123e1c..2f04605 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -587,7 +587,6 @@ void wins_status_bar(void)
struct binding help = { _("Help"), KEY_GENERIC_HELP };
struct binding quit = { _("Quit"), KEY_GENERIC_QUIT };
struct binding save = { _("Save"), KEY_GENERIC_SAVE };
- struct binding cut = { _("Cut"), KEY_GENERIC_CUT };
struct binding copy = { _("Copy"), KEY_GENERIC_COPY };
struct binding paste = { _("Paste"), KEY_GENERIC_PASTE };
struct binding chgvu = { _("Chg Win"), KEY_GENERIC_CHANGE_VIEW };
@@ -639,7 +638,7 @@ void wins_status_bar(void)
&help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
&pipe, &draw, &rept, &flag, &enote, &vnote, &up, &down, &gpday, &gnday,
&gpweek, &gnweek, &gpmonth, &gnmonth, &gpyear, &gnyear, &togo, &today,
- &conf, &appt, &todo, &cut, &copy, &paste
+ &conf, &appt, &todo, &copy, &paste
};
struct binding *bindings_todo[] = {