From 5f776a352596394c6e913cf241b40868974587ff Mon Sep 17 00:00:00 2001 From: David Sparer Date: Wed, 14 Aug 2019 09:22:01 -0500 Subject: [PATCH] minor cleanup of the connection tab class --- mRemoteV1/UI/Tabs/ConnectionTab.cs | 68 +++++++++++++------------ mRemoteV1/UI/Window/ConnectionWindow.cs | 4 +- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/mRemoteV1/UI/Tabs/ConnectionTab.cs b/mRemoteV1/UI/Tabs/ConnectionTab.cs index b3be1cef..5788efb0 100644 --- a/mRemoteV1/UI/Tabs/ConnectionTab.cs +++ b/mRemoteV1/UI/Tabs/ConnectionTab.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Windows.Forms; using mRemoteNG.App; using mRemoteNG.App.Info; @@ -13,15 +14,17 @@ namespace mRemoteNG.UI.Tabs { public partial class ConnectionTab : DockContent { + private InterfaceControl InterfaceControl => Tag as InterfaceControl; + /// ///Silent close ignores the popup asking for confirmation /// - public bool silentClose { get; set; } + public bool SilentClose { get; set; } /// /// Protocol close ignores the interface controller cleanup and the user confirmation dialog /// - public bool protocolClose { get; set; } + public bool ProtocolClose { get; set; } public ConnectionTab() { @@ -36,58 +39,35 @@ namespace mRemoteNG.UI.Tabs protected override void OnFormClosing(FormClosingEventArgs e) { - if (!protocolClose) + if (!ProtocolClose) { - if (!silentClose) + if (!SilentClose) { if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All) { - var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName, - string - .Format(Language.strConfirmCloseConnectionPanelMainInstruction, - TabText), "", "", "", - Language.strCheckboxDoNotShowThisMessageAgain, - ETaskDialogButtons.YesNo, ESysIcons.Question, - ESysIcons.Question); - if (CTaskDialog.VerificationChecked) - { - Settings.Default.ConfirmCloseConnection--; - } - - if (result == DialogResult.No) - { - e.Cancel = true; - } - else - { - ((InterfaceControl)Tag)?.Protocol.Close(); - } + ShowCloseConnectionTabPrompt(e); } else { // close without the confirmation prompt... - ((InterfaceControl)Tag)?.Protocol.Close(); + InterfaceControl?.Protocol.Close(); } } else { - ((InterfaceControl)Tag)?.Protocol.Close(); + InterfaceControl?.Protocol.Close(); } } base.OnFormClosing(e); } - - #region HelperFunctions - public void RefreshInterfaceController() { try { - var interfaceControl = Tag as InterfaceControl; - if (interfaceControl?.Info.Protocol == ProtocolType.VNC) - ((ProtocolVNC)interfaceControl.Protocol).RefreshScreen(); + if (InterfaceControl?.Info.Protocol == ProtocolType.VNC) + ((ProtocolVNC)InterfaceControl.Protocol).RefreshScreen(); } catch (Exception ex) { @@ -95,6 +75,28 @@ namespace mRemoteNG.UI.Tabs } } - #endregion + private void ShowCloseConnectionTabPrompt(FormClosingEventArgs e) + { + var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName, + string.Format(Language.strConfirmCloseConnectionPanelMainInstruction, TabText), + "", "", "", + Language.strCheckboxDoNotShowThisMessageAgain, + ETaskDialogButtons.YesNo, ESysIcons.Question, + ESysIcons.Question); + + if (CTaskDialog.VerificationChecked) + { + Settings.Default.ConfirmCloseConnection--; + } + + if (result == DialogResult.No) + { + e.Cancel = true; + } + else + { + InterfaceControl?.Protocol.Close(); + } + } } } \ No newline at end of file diff --git a/mRemoteV1/UI/Window/ConnectionWindow.cs b/mRemoteV1/UI/Window/ConnectionWindow.cs index 4b29b2e5..5ba9efdc 100644 --- a/mRemoteV1/UI/Window/ConnectionWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionWindow.cs @@ -316,7 +316,7 @@ namespace mRemoteNG.UI.Window { var tabP = (ConnectionTab)dockContent; if (tabP.Tag == null) continue; - tabP.silentClose = true; + tabP.SilentClose = true; tabP.Close(); } } @@ -798,7 +798,7 @@ namespace mRemoteNG.UI.Window var protocolBase = sender as ProtocolBase; if (!(protocolBase?.InterfaceControl.Parent is ConnectionTab tabPage)) return; if (tabPage.Disposing) return; - tabPage.protocolClose = true; + tabPage.ProtocolClose = true; Invoke(new Action(() => tabPage.Close())); }