Factorize boolean user prompting.

Introduce a new `status_ask_bool()` function, and use it where
applicable.

This greatly reduces code duplication, and will allow handling special
events (resize, user escape) much more uniformely.

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-13 14:09:21 +02:00 committed by Lukas Fleischer
parent 7d4ef08345
commit 13d6f8703b
6 changed files with 19 additions and 35 deletions

View File

@ -276,8 +276,7 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
if (conf.confirm_delete)
{
status_mesg_yesno (del_app_str);
if (wgetch (win[STA].p) != 'y')
if (status_ask_bool (del_app_str) != 1)
{
wins_erase_status_bar ();
return;

View File

@ -546,10 +546,8 @@ main (int argc, char **argv)
if (conf.confirm_quit)
{
status_mesg_yesno (_("Do you really want to quit ?"));
key = wgetch (win[STA].p);
if (key == 'y')
exit_calcurse (EXIT_SUCCESS);
if (status_ask_bool (_("Do you really want to quit ?")) == 1)
exit_calcurse (EXIT_SUCCESS);
else
{
wins_erase_status_bar ();

View File

@ -895,8 +895,8 @@ void free_user_data (void);
void fatalbox (const char *);
void warnbox (const char *);
void status_mesg (const char *, const char *);
void status_mesg_yesno (const char *);
int status_ask_choice (const char *, const char[], int);
int status_ask_bool (const char *);
int status_ask_simplechoice (const char *, const char *[], int);
void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup (int, int, int, int, const char *, const char *, int);

View File

@ -1253,16 +1253,8 @@ io_log_display (struct io_file *log, const char *msg, const char *pager)
}
else
{
status_mesg_yesno (msg);
do
{
ans = wgetch (win[STA].p);
if (ans == 'y')
{
wins_launch_external (log->name, pager);
}
}
while (ans != 'y' && ans != 'n');
if (status_ask_bool (msg) == 1)
wins_launch_external (log->name, pager);
wins_erase_status_bar ();
}
}

View File

@ -250,17 +250,8 @@ todo_delete (void)
const int nb_erase_choice = 2;
int answer;
if (conf.confirm_delete)
{
status_mesg_yesno (del_todo_str);
answer = wgetch (win[STA].p);
if ((answer != 'y') || (todos <= 0))
{
wins_erase_status_bar ();
return;
}
}
else if (todos <= 0)
if ((todos <= 0) ||
(conf.confirm_delete && (status_ask_bool (del_todo_str) != 1)))
{
wins_erase_status_bar ();
return;

View File

@ -184,13 +184,6 @@ status_mesg (const char *msg1, const char *msg2)
custom_remove_attr (win[STA].p, ATTR_HIGHEST);
}
/* Print a status message, followed by a "[y/n]" prompt. */
void
status_mesg_yesno (const char *msg)
{
status_mesg (msg, "[y/n] ");
}
/*
* Prompts the user to make a choice between named alternatives.
*
@ -233,6 +226,17 @@ status_ask_choice(const char *message, const char choice[], int nb_choice)
}
}
/*
* Prompts the user with a boolean question.
*
* Returns 1 if yes, 2 if no, and -1 otherwise
*/
int
status_ask_bool (const char *msg)
{
return (status_ask_choice (msg, _("[yn]"), 2));
}
/*
* Prompts the user to make a choice between a number of alternatives.
*