From b41069ff844e8d8e24da43b7f777801be1a55390 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 5 Feb 2001 13:08:18 +0000 Subject: [PATCH] Jacob's patch to improve Close On Exit behaviour git-svn-id: svn://svn.tartarus.org/sgt/putty@927 cda61777-01e9-0310-a592-d414129be87e --- putty.h | 9 +++++++++ settings.c | 4 ++-- windlg.c | 29 +++++++++++++++++++++-------- window.c | 19 ++++++++++--------- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/putty.h b/putty.h index a06ed7d0..88774e0d 100644 --- a/putty.h +++ b/putty.h @@ -130,6 +130,15 @@ enum { LD_ECHO /* local echo */ }; +enum { + /* + * Close On Exit behaviours. (cfg.close_on_exit) + */ + COE_NEVER, /* Never close the window */ + COE_ALWAYS, /* Always close the window */ + COE_NORMAL /* Close window on "normal" (non-error) exits only */ +}; + typedef struct { char *(*init) (char *host, int port, char **realhost); void (*send) (char *buf, int len); diff --git a/settings.c b/settings.c index b8a7f79f..d3f33bcf 100644 --- a/settings.c +++ b/settings.c @@ -42,7 +42,7 @@ void save_settings (char *section, int do_host, Config *cfg) { } write_setting_s (sesskey, "Protocol", p); } - write_setting_i (sesskey, "CloseOnExit", !!cfg->close_on_exit); + write_setting_i (sesskey, "CloseOnExit", cfg->close_on_exit); write_setting_i (sesskey, "WarnOnClose", !!cfg->warn_on_close); write_setting_i (sesskey, "PingInterval", cfg->ping_interval / 60); /* minutes */ write_setting_i (sesskey, "PingIntervalSecs", cfg->ping_interval % 60); /* seconds */ @@ -171,7 +171,7 @@ void load_settings (char *section, int do_host, Config *cfg) { break; } - gppi (sesskey, "CloseOnExit", 1, &cfg->close_on_exit); + gppi (sesskey, "CloseOnExit", COE_NORMAL, &cfg->close_on_exit); gppi (sesskey, "WarnOnClose", 1, &cfg->warn_on_close); { /* This is two values for backward compatibility with 0.50/0.51 */ diff --git a/windlg.c b/windlg.c index d6fce02a..b7e878d6 100644 --- a/windlg.c +++ b/windlg.c @@ -204,6 +204,9 @@ enum { IDCX_ABOUT = IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue, IDC_SESSSAVE, IDC_SESSDEL, IDC_CLOSEEXIT, + IDC_COEALWAYS, + IDC_COENORMAL, + IDC_COENEVER, sessionpanelend, loggingpanelstart, @@ -537,7 +540,9 @@ static void init_dlg_ctrls(HWND hwnd) { CheckDlgButton (hwnd, IDC_BLINKCUR, cfg.blink_cur); CheckDlgButton (hwnd, IDC_SCROLLBAR, cfg.scrollbar); CheckDlgButton (hwnd, IDC_LOCKSIZE, cfg.locksize); - CheckDlgButton (hwnd, IDC_CLOSEEXIT, cfg.close_on_exit); + CheckRadioButton (hwnd, IDC_COEALWAYS, IDC_COENEVER, + cfg.close_on_exit==COE_NEVER ? IDC_COENEVER : + cfg.close_on_exit==COE_NORMAL ? IDC_COENORMAL : IDC_COEALWAYS); CheckDlgButton (hwnd, IDC_CLOSEWARN, cfg.warn_on_close); SetDlgItemText (hwnd, IDC_TTEDIT, cfg.termtype); @@ -659,7 +664,7 @@ static HTREEITEM treeview_insert(struct treeview_faff *faff, */ static void create_controls(HWND hwnd, int dlgtype, int panel) { if (panel == sessionpanelstart) { - /* The Session panel. Accelerators used: [acgo] nprtih elsd x */ + /* The Session panel. Accelerators used: [acgo] nprtih elsd w */ struct ctlpos cp; ctlposinit(&cp, hwnd, 80, 3, 13); bartitle(&cp, "Basic options for your PuTTY session", @@ -699,7 +704,10 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) { endbox(&cp); } beginbox(&cp, NULL, IDC_BOX_SESSION3); - checkbox(&cp, "Close Window on E&xit", IDC_CLOSEEXIT); + radioline(&cp, "At session end, close &window:", IDC_CLOSEEXIT, 3, + "Always", IDC_COEALWAYS, + "On clean exit", IDC_COENORMAL, + "Never", IDC_COENEVER, NULL); endbox(&cp); } @@ -1596,11 +1604,16 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg, GetDlgItemText (hwnd, IDC_WINEDIT, cfg.wintitle, sizeof(cfg.wintitle)-1); break; - case IDC_CLOSEEXIT: - if (HIWORD(wParam) == BN_CLICKED || - HIWORD(wParam) == BN_DOUBLECLICKED) - cfg.close_on_exit = IsDlgButtonChecked (hwnd, IDC_CLOSEEXIT); - break; + case IDC_COEALWAYS: + case IDC_COENORMAL: + case IDC_COENEVER: + if (HIWORD(wParam) == BN_CLICKED || + HIWORD(wParam) == BN_DOUBLECLICKED) { + cfg.close_on_exit = IsDlgButtonChecked (hwnd, IDC_COEALWAYS) ? COE_ALWAYS : + IsDlgButtonChecked (hwnd, IDC_COENORMAL) ? COE_NORMAL : + COE_NEVER; + } + break; case IDC_CLOSEWARN: if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == BN_DOUBLECLICKED) diff --git a/window.c b/window.c index c1f3fac2..cdc58dc3 100644 --- a/window.c +++ b/window.c @@ -667,7 +667,7 @@ void connection_fatal(char *fmt, ...) { vsprintf(stuff, fmt, ap); va_end(ap); MessageBox(hwnd, stuff, "PuTTY Fatal Error", MB_ICONERROR | MB_OK); - if (cfg.close_on_exit) + if (cfg.close_on_exit == COE_ALWAYS) PostQuitMessage(1); else { session_closed = TRUE; @@ -692,16 +692,17 @@ static void enact_pending_netevent(void) { ret = select_result (pend_netevent_wParam, pend_netevent_lParam); reentering = 0; - if (ret == 0) { - if (cfg.close_on_exit) + if (ret == 0 && !session_closed) { + /* Abnormal exits will already have set session_closed and taken + * appropriate action. */ + if (cfg.close_on_exit == COE_ALWAYS || + cfg.close_on_exit == COE_NORMAL) PostQuitMessage(0); else { - if (!session_closed) { - session_closed = TRUE; - SetWindowText (hwnd, "PuTTY (inactive)"); - MessageBox(hwnd, "Connection closed by remote host", - "PuTTY", MB_OK | MB_ICONINFORMATION); - } + session_closed = TRUE; + SetWindowText (hwnd, "PuTTY (inactive)"); + MessageBox(hwnd, "Connection closed by remote host", + "PuTTY", MB_OK | MB_ICONINFORMATION); } } } -- 2.11.0