Close dialogs during MC shutdown.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-05-30 18:43:50 +04:00
parent 56bbdeb15f
commit cf6098505c
8 changed files with 100 additions and 49 deletions

View File

@ -232,3 +232,15 @@ dialog_switch_process_pending (void)
return ret;
}
void
dialog_switch_shutdown (void)
{
while (mc_dialogs != NULL)
{
Dlg_head *dlg = (Dlg_head *) mc_dialogs->data;
run_dlg (dlg);
destroy_dlg (dlg);
}
}

View File

@ -13,5 +13,6 @@ void dialog_switch_prev (void);
void dialog_switch_list (void);
int dialog_switch_process_pending (void);
void dialog_switch_shutdown (void);
#endif /* MC_DIALOG_SWITCH_H */

View File

@ -963,6 +963,14 @@ frontend_run_dlg (Dlg_head * h)
Gpm_Event event;
event.x = -1;
/* close opened editors, viewers, etc */
if (!h->modal && midnight_shutdown)
{
h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
return;
}
while (h->state == DLG_ACTIVE)
{
if (winch_flag)

View File

@ -51,7 +51,7 @@
#include "src/history.h"
#include "src/panel.h" /* Needed for current_panel and other_panel */
#include "src/layout.h" /* Needed for get_current_index and get_other_panel */
#include "src/main.h" /* mc_run_mode */
#include "src/main.h" /* mc_run_mode, midnight_shutdown */
#include "src/selcodepage.h"
#include "ydiff.h"
@ -2940,23 +2940,35 @@ static gboolean
dview_ok_to_exit (WDiff * dview)
{
gboolean res = TRUE;
int act;
if (!dview->merged)
return res;
switch (query_dialog
(_("Quit"), _("File was modified, Save with exit?"), D_NORMAL, 2, _("&Yes"),
_("&No")))
act = query_dialog (_("Quit"), !midnight_shutdown ?
_("File was modified. Save with exit?") :
_("Midnight Commander is being shut down.\nSave modified file?"),
D_NORMAL, 2, _("&Yes"), _("&No"));
/* Esc is No */
if (midnight_shutdown || (act == -1))
act = 1;
switch (act)
{
case -1:
case -1: /* Esc */
res = FALSE;
break;
case 0:
res = TRUE;
case 0: /* Yes */
(void) dview_save (dview);
break;
case 1:
res = TRUE;
break;
case 1: /* No */
if (mc_util_restore_from_backup_if_possible (dview->file[0], "~~~"))
res = mc_util_unlink_backup_if_possible (dview->file[0], "~~~");
/* fall through */
default:
res = TRUE;
break;
}
return res;

View File

@ -215,7 +215,7 @@ int edit_save_confirm_cmd (WEdit * edit);
int edit_save_as_cmd (WEdit * edit);
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, long line);
int edit_clean (WEdit * edit);
int edit_ok_to_exit (WEdit * edit);
gboolean edit_ok_to_exit (WEdit * edit);
int edit_renew (WEdit * edit);
int edit_new_cmd (WEdit * edit);
int edit_reload (WEdit * edit, const char *filename);

View File

@ -56,7 +56,7 @@
#include "src/history.h"
#include "src/widget.h" /* listbox_new() */
#include "src/layout.h" /* clr_scr() */
#include "src/main.h" /* mc_home */
#include "src/main.h" /* mc_home, midnight_shutdown */
#include "src/setup.h" /* option_tab_spacing */
#include "src/help.h" /* interactive_display() */
#include "src/wtools.h" /* message() */
@ -2039,33 +2039,48 @@ edit_search_cmd (WEdit * edit, int again)
* Check if it's OK to close the editor. If there are unsaved changes,
* ask user. Return 1 if it's OK to exit, 0 to continue editing.
*/
int
gboolean
edit_ok_to_exit (WEdit * edit)
{
int act;
if (!edit->modified)
return 1;
return TRUE;
if (!edit_check_newline (edit))
return 0;
switch (edit_query_dialog3
(_("Quit"), _("File was modified, save with exit?"),
_("&Cancel quit"), _("&Yes"), _("&No")))
if (!midnight_shutdown)
{
case 1:
edit_push_markers (edit);
edit_set_markers (edit, 0, 0, 0, 0);
if (!edit_save_cmd (edit))
return 0;
break;
case 2:
break;
case 0:
case -1:
return 0;
if (!edit_check_newline (edit))
return FALSE;
act = edit_query_dialog3 (_("Quit"), _("File was modified. Save with exit?"),
_("&Yes"), _("&No"), _("&Cancel quit"));
}
else
{
act = edit_query_dialog2 (_("Quit"), _("Midnight Commander is being shut down.\nSave modified file?"),
_("&Yes"), _("&No"));
/* Esc is No */
if (act == -1)
act = 1;
}
return 1;
switch (act)
{
case 0: /* Yes */
edit_push_markers (edit);
edit_set_markers (edit, 0, 0, 0, 0);
if (!edit_save_cmd (edit) || midnight_shutdown)
return (gboolean) midnight_shutdown;
break;
case 1: /* No */
break;
case 2: /* Cancel quit */
case -1: /* Esc */
return FALSE;
}
return TRUE;
}
/* Return a null terminated length of text. Result must be g_free'd */

View File

@ -1574,15 +1574,6 @@ done_mc (void)
vfs_add_current_stamps ();
}
/* This should be called after destroy_dlg since panel widgets
* save their state on the profiles
*/
static void
done_mc_profile (void)
{
done_setup ();
}
static cb_ret_t
midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
@ -1927,7 +1918,6 @@ mc_maybe_editor_or_viewer (void)
break;
}
midnight_shutdown = 1;
done_mc ();
}
/* Run the main dialog that occupies the whole screen */
@ -1967,13 +1957,14 @@ do_nc (void)
if (mc_args__last_wd_file && vfs_current_is_local ())
last_wd_string = g_strdup (current_panel->cwd);
done_mc ();
}
dialog_switch_shutdown ();
done_mc ();
destroy_dlg (midnight_dlg);
panel_deinit ();
current_panel = 0;
done_mc_profile ();
done_setup ();
}
/* POSIX version. The only version we support. */

View File

@ -146,15 +146,27 @@ mcview_ok_to_quit (mcview_t * view)
if (view->change_list == NULL)
return TRUE;
r = query_dialog (_("Quit"),
_("File was modified, Save with exit?"), D_NORMAL, 3,
_("&Cancel quit"), _("&Yes"), _("&No"));
if (!midnight_shutdown)
{
r = query_dialog (_("Quit"),
_("File was modified. Save with exit?"), D_NORMAL, 3,
_("&Yes"), _("&No"), _("&Cancel quit"));
}
else
{
r = query_dialog (_("Quit"),
_("Midnight Commander is being shut down.\nSave modified file?"), D_NORMAL, 2,
_("&Yes"), _("&No"));
/* Esc is No */
if (r == -1)
r = 1;
}
switch (r)
{
case 1:
return mcview_hexedit_save_changes (view);
case 2:
case 0: /* Yes */
return mcview_hexedit_save_changes (view) || midnight_shutdown;
case 1: /* No */
mcview_hexedit_free_change_list (view);
return TRUE;
default: