Merge pull request #2887 from mRemoteNG/copilot/add-warning-for-disconnect-option

Add confirmation dialog when disconnecting connections from context menu
This commit is contained in:
Dimitrij
2025-10-09 19:27:33 +01:00
committed by GitHub
3 changed files with 37 additions and 0 deletions

View File

@@ -1041,6 +1041,15 @@ namespace mRemoteNG.Resources.Language {
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to disconnect &quot;{0}&quot;?.
/// </summary>
internal static string ConfirmDisconnectConnection {
get {
return ResourceManager.GetString("ConfirmDisconnectConnection", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to delete the credential record, {0}?.
/// </summary>

View File

@@ -348,6 +348,9 @@
<data name="ConfirmCloseConnectionPanelMainInstruction" xml:space="preserve">
<value>Are you sure you want to close the panel, "{0}"? Any connections that it contains will also be closed.</value>
</data>
<data name="ConfirmDisconnectConnection" xml:space="preserve">
<value>Are you sure you want to disconnect "{0}"?</value>
</data>
<data name="ConfirmDeleteExternalTool" xml:space="preserve">
<value>Are you sure you want to delete the external tool, "{0}"?</value>
</data>

View File

@@ -3,9 +3,12 @@ using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using mRemoteNG.App;
using mRemoteNG.App.Info;
using mRemoteNG.Config;
using mRemoteNG.Connection;
using mRemoteNG.Connection.Protocol;
using mRemoteNG.Container;
using mRemoteNG.Properties;
using mRemoteNG.Tools;
using mRemoteNG.Tools.Clipboard;
using mRemoteNG.Tree;
@@ -13,6 +16,7 @@ using mRemoteNG.Tree.Root;
using mRemoteNG.Resources.Language;
using System.Runtime.Versioning;
using mRemoteNG.Security;
using mRemoteNG.UI.TaskDialog;
// ReSharper disable UnusedParameter.Local
@@ -794,6 +798,27 @@ namespace mRemoteNG.UI.Controls
try
{
if (connectionInfo == null) return;
// Check if confirmation is needed based on settings
if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All)
{
string confirmMessage = string.Format(Language.ConfirmDisconnectConnection, connectionInfo.Name);
DialogResult result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName,
confirmMessage, "", "", "",
Language.CheckboxDoNotShowThisMessageAgain,
ETaskDialogButtons.YesNo, ESysIcons.Question,
ESysIcons.Question);
if (CTaskDialog.VerificationChecked)
{
Settings.Default.ConfirmCloseConnection--;
}
if (result == DialogResult.No)
{
return; // User cancelled the disconnect
}
}
ContainerInfo nodeAsContainer = connectionInfo as ContainerInfo;
if (nodeAsContainer != null)
{