Use status_ask_choice() where applicable

These cases make obvious candidates for factorisation.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Baptiste Jonglez 2012-05-14 12:38:22 +02:00 committed by Lukas Fleischer
parent 4087cd4e5e
commit 1d9c90bb18
2 changed files with 44 additions and 42 deletions

View File

@ -922,33 +922,40 @@ int
day_erase_item (long date, int item_number, enum eraseflg flag) day_erase_item (long date, int item_number, enum eraseflg flag)
{ {
struct day_item *p; struct day_item *p;
const char *erase_warning = const char *erase_warning =
_("This item is recurrent. " _("This item is recurrent. "
"Delete (a)ll occurences or just this (o)ne ?"); "Delete (a)ll occurences or just this (o)ne ?");
const char *erase_choices = _("[ao]");
const int nb_erase_choices = 2;
const char *note_warning = const char *note_warning =
_("This item has a note attached to it. " _("This item has a note attached to it. "
"Delete (i)tem or just its (n)ote ?"); "Delete (i)tem or just its (n)ote ?");
const char *note_choice = _("[i/n] "); const char *note_choices = _("[in]");
const char *erase_choice = _("[a/o] "); const int nb_note_choices = 2;
int ch, ans; int ans;
unsigned delete_whole; unsigned delete_whole;
ch = -1;
p = day_get_item (item_number); p = day_get_item (item_number);
if (flag == ERASE_DONT_FORCE) if (flag == ERASE_DONT_FORCE)
{ {
ans = 0;
if (p->note == NULL) if (p->note == NULL)
ans = 'i'; ans = 1;
while (ans != 'i' && ans != 'n')
{
status_mesg (note_warning, note_choice);
ans = wgetch (win[STA].p);
}
if (ans == 'i')
flag = ERASE_FORCE;
else else
ans = status_ask_choice (note_warning, note_choices, nb_note_choices);
switch (ans)
{
case 1:
flag = ERASE_FORCE;
break;
case 2:
flag = ERASE_FORCE_ONLY_NOTE; flag = ERASE_FORCE_ONLY_NOTE;
break;
default: /* User escaped */
return 0;
}
} }
if (p->type == EVNT) if (p->type == EVNT)
{ {
@ -961,24 +968,23 @@ day_erase_item (long date, int item_number, enum eraseflg flag)
else else
{ {
if (flag == ERASE_FORCE_ONLY_NOTE) if (flag == ERASE_FORCE_ONLY_NOTE)
ch = 'a'; ans = 1;
while ((ch != 'a') && (ch != 'o') && (ch != KEY_GENERIC_CANCEL))
{
status_mesg (erase_warning, erase_choice);
ch = wgetch (win[STA].p);
}
if (ch == 'a')
{
delete_whole = 1;
}
else if (ch == 'o')
{
delete_whole = 0;
}
else else
ans = status_ask_choice (erase_warning, erase_choices,
nb_erase_choices);
switch (ans)
{ {
case 1:
delete_whole = 1;
break;
case 2:
delete_whole = 0;
break;
default:
return 0; return 0;
} }
if (p->type == RECUR_EVNT) if (p->type == RECUR_EVNT)
{ {
recur_event_erase (date, day_item_nb (date, item_number, RECUR_EVNT), recur_event_erase (date, day_item_nb (date, item_number, RECUR_EVNT),

View File

@ -246,8 +246,9 @@ todo_delete (void)
const char *erase_warning = const char *erase_warning =
_("This item has a note attached to it. " _("This item has a note attached to it. "
"Delete (t)odo or just its (n)ote ?"); "Delete (t)odo or just its (n)ote ?");
const char *erase_choice = _("[t/n] "); const char *erase_choice = _("[tn]");
int answer, has_note; const int nb_erase_choice = 2;
int answer;
if (conf.confirm_delete) if (conf.confirm_delete)
{ {
@ -265,20 +266,15 @@ todo_delete (void)
return; return;
} }
answer = -1; /* This todo item doesn't have any note associated. */
has_note = (todo_get_item (hilt)->note != NULL) ? 1 : 0; if (todo_get_item (hilt)->note == NULL)
if (has_note == 0) answer = 1;
answer = 't'; else
answer = status_ask_choice (erase_warning, erase_choice, nb_erase_choice);
while (answer != 't' && answer != 'n' && answer != KEY_GENERIC_CANCEL)
{
status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p);
}
switch (answer) switch (answer)
{ {
case 't': case 1:
todo_delete_bynum (hilt - 1); todo_delete_bynum (hilt - 1);
todos--; todos--;
if (hilt > 1) if (hilt > 1)
@ -288,7 +284,7 @@ todo_delete (void)
if (hilt - first < 0) if (hilt - first < 0)
first--; first--;
break; break;
case 'n': case 2:
todo_delete_note_bynum (hilt - 1); todo_delete_note_bynum (hilt - 1);
break; break;
default: default: