summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-07-07 11:55:10 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-07-07 21:35:02 +0200
commit7fb25a84d427f4a3cb79ea02908daf9ce8ba07ca (patch)
treecb24b54351955c1d354095023534d8b51d8f9cec
parent69345edd77b3ff98a99b36de8063f9e5febad3eb (diff)
downloadcalcurse-7fb25a84d427f4a3cb79ea02908daf9ce8ba07ca.zip
Refactor note removal
Remove the note removal code from *_delete()/*_erase() and create a new wrapper function called day_item_erase_note() that is be used to drop the note being associated to an item. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/apoint.c3
-rw-r--r--src/calcurse.h2
-rw-r--r--src/day.c19
-rw-r--r--src/event.c3
-rw-r--r--src/interaction.c28
-rw-r--r--src/recur.c8
6 files changed, 31 insertions, 32 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 694c318..a308b26 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -224,9 +224,6 @@ void apoint_delete(struct apoint *apt, enum eraseflg flag)
EXIT(_("no such appointment"));
switch (flag) {
- case ERASE_FORCE_ONLY_NOTE:
- erase_note(&apt->note);
- break;
case ERASE_CUT:
if (notify_bar())
need_check_notify = notify_same_item(apt->start);
diff --git a/src/calcurse.h b/src/calcurse.h
index c9b0307..b0f1477 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -524,7 +524,6 @@ enum item_type {
enum eraseflg {
ERASE_DONT_FORCE,
ERASE_FORCE,
- ERASE_FORCE_ONLY_NOTE,
ERASE_CUT
};
@@ -669,6 +668,7 @@ void custom_config_main(void);
void day_free_list(void);
char *day_item_get_mesg(struct day_item *);
char *day_item_get_note(struct day_item *);
+void day_item_erase_note(struct day_item *);
long day_item_get_duration(struct day_item *);
int day_item_get_state(struct day_item *);
void day_item_fork(struct day_item *, struct day_item *);
diff --git a/src/day.c b/src/day.c
index 26ae3e0..10caa05 100644
--- a/src/day.c
+++ b/src/day.c
@@ -123,6 +123,25 @@ char *day_item_get_note(struct day_item *day)
}
}
+/* Get the note attached to an item. */
+void day_item_erase_note(struct day_item *day)
+{
+ switch (day->type) {
+ case APPT:
+ erase_note(&day->item.apt->note);
+ break;
+ case EVNT:
+ erase_note(&day->item.ev->note);
+ break;
+ case RECUR_APPT:
+ erase_note(&day->item.rapt->note);
+ break;
+ case RECUR_EVNT:
+ erase_note(&day->item.rev->note);
+ break;
+ }
+}
+
/* Get the duration of an item. */
long day_item_get_duration(struct day_item *day)
{
diff --git a/src/event.c b/src/event.c
index de0ce02..b53ec2f 100644
--- a/src/event.c
+++ b/src/event.c
@@ -158,9 +158,6 @@ void event_delete(struct event *ev, enum eraseflg flag)
EXIT(_("no such appointment"));
switch (flag) {
- case ERASE_FORCE_ONLY_NOTE:
- erase_note(&ev->note);
- break;
case ERASE_CUT:
LLIST_REMOVE(&eventlist, i);
break;
diff --git a/src/interaction.c b/src/interaction.c
index b619992..4d71520 100644
--- a/src/interaction.c
+++ b/src/interaction.c
@@ -389,32 +389,26 @@ static int day_erase_item(long date, int item_number, enum eraseflg flag)
unsigned delete_whole;
p = day_get_item(item_number);
- if (flag == ERASE_DONT_FORCE) {
- if (day_item_get_note(p) == NULL)
- ans = 1;
- else
- ans = status_ask_choice(note_warning, note_choices, nb_note_choices);
-
- switch (ans) {
+ if (flag == ERASE_DONT_FORCE && day_item_get_note(p)) {
+ switch (status_ask_choice(note_warning, note_choices, nb_note_choices)) {
case 1:
- flag = ERASE_FORCE;
break;
case 2:
- flag = ERASE_FORCE_ONLY_NOTE;
- break;
+ 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 {
- if (flag == ERASE_FORCE_ONLY_NOTE)
- ans = 1;
- else
- ans = status_ask_choice(erase_warning, erase_choices, nb_erase_choices);
+ ans = status_ask_choice(erase_warning, erase_choices, nb_erase_choices);
switch (ans) {
case 1:
@@ -433,10 +427,8 @@ static int day_erase_item(long date, int item_number, enum eraseflg flag)
recur_apoint_erase(p->item.rapt, date, delete_whole, flag);
}
}
- if (flag == ERASE_FORCE_ONLY_NOTE)
- return 0;
- else
- return p->type;
+
+ return p->type;
}
/* Pipe an appointment or event to an external program. */
diff --git a/src/recur.c b/src/recur.c
index 0a17414..d8215d1 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -687,9 +687,6 @@ recur_event_erase(struct recur_event *rev, long start, unsigned delete_whole,
if (delete_whole) {
switch (flag) {
- case ERASE_FORCE_ONLY_NOTE:
- erase_note(&rev->note);
- break;
case ERASE_CUT:
LLIST_REMOVE(&recur_elist, i);
return;
@@ -723,13 +720,10 @@ recur_apoint_erase(struct recur_apoint *rapt, long start,
EXIT(_("appointment not found"));
LLIST_TS_LOCK(&recur_alist_p);
- if (notify_bar() && flag != ERASE_FORCE_ONLY_NOTE)
+ if (notify_bar())
need_check_notify = notify_same_recur_item(rapt);
if (delete_whole) {
switch (flag) {
- case ERASE_FORCE_ONLY_NOTE:
- erase_note(&rapt->note);
- break;
case ERASE_CUT:
LLIST_TS_REMOVE(&recur_alist_p, i);
break;