Ask user before exit if there are opened screens in MC.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-06-18 14:35:27 +04:00
parent 768f48de29
commit 15a7b10191
3 changed files with 31 additions and 12 deletions

View File

@ -129,6 +129,12 @@ dialog_switch_remove (Dlg_head *h)
}
}
size_t
dialog_switch_num (void)
{
return g_list_length (mc_dialogs);
}
void
dialog_switch_next (void)
{

View File

@ -2,10 +2,13 @@
#ifndef MC_DIALOG_SWITCH_H
#define MC_DIALOG_SWITCH_H
#include <sys/types.h>
struct Dlg_head;
void dialog_switch_add (struct Dlg_head *h);
void dialog_switch_remove (struct Dlg_head *h);
size_t dialog_switch_num (void);
void dialog_switch_next (void);
void dialog_switch_prev (void);

View File

@ -335,20 +335,29 @@ static int
quit_cmd_internal (int quiet)
{
int q = quit;
size_t n = dialog_switch_num () - 1;
if (quiet || !confirm_exit)
if (n != 0)
{
q = 1;
}
else
{
if (query_dialog
(_("The Midnight Commander"),
_("Do you really want to quit the Midnight Commander?"), D_NORMAL,
2, _("&Yes"), _("&No")) == 0)
char msg[BUF_MEDIUM];
g_snprintf (msg, sizeof (msg),
ngettext ("You have %zd opened screen. Quit anyway?",
"You have %zd opened screens. Quit anyway?", n),
n);
if (query_dialog (_("The Midnight Commander"), msg,
D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
q = 1;
}
if (q)
} else if (quiet || !confirm_exit)
q = 1;
else if (query_dialog (_("The Midnight Commander"),
_("Do you really want to quit the Midnight Commander?"),
D_NORMAL, 2, _("&Yes"), _("&No")) == 0)
q = 1;
if (q != 0)
{
#ifdef HAVE_SUBSHELL_SUPPORT
if (!use_subshell)
@ -357,7 +366,8 @@ quit_cmd_internal (int quiet)
#endif
stop_dialogs ();
}
if (q)
if (q != 0)
quit |= 1;
return quit;
}