mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
added a deletion confirmer to the credential manager
This commit is contained in:
32
mRemoteV1/Credential/CredentialDeletionMsgBoxConfirmer.cs
Normal file
32
mRemoteV1/Credential/CredentialDeletionMsgBoxConfirmer.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using mRemoteNG.Tree;
|
||||
|
||||
|
||||
namespace mRemoteNG.Credential
|
||||
{
|
||||
public class CredentialDeletionMsgBoxConfirmer : IConfirm<ICredentialRecord>
|
||||
{
|
||||
private readonly Func<string, string, MessageBoxButtons, MessageBoxIcon, DialogResult> _confirmationFunc;
|
||||
|
||||
public CredentialDeletionMsgBoxConfirmer(Func<string, string, MessageBoxButtons, MessageBoxIcon, DialogResult> confirmationFunc)
|
||||
{
|
||||
if (confirmationFunc == null)
|
||||
throw new ArgumentNullException(nameof(confirmationFunc));
|
||||
|
||||
_confirmationFunc = confirmationFunc;
|
||||
}
|
||||
|
||||
public bool Confirm(ICredentialRecord confirmationTarget)
|
||||
{
|
||||
var promptText = string.Format(Language.strConfirmDeleteCredentialRecord, confirmationTarget.Title);
|
||||
return PromptUser(promptText);
|
||||
}
|
||||
|
||||
private bool PromptUser(string promptMessage)
|
||||
{
|
||||
var msgBoxResponse = _confirmationFunc.Invoke(promptMessage, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
return msgBoxResponse == DialogResult.Yes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1094,6 +1094,15 @@ namespace mRemoteNG {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Are you sure you want to delete the credential record, {0}?.
|
||||
/// </summary>
|
||||
internal static string strConfirmDeleteCredentialRecord {
|
||||
get {
|
||||
return ResourceManager.GetString("strConfirmDeleteCredentialRecord", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Are you sure you want to delete the external tool, "{0}"?.
|
||||
/// </summary>
|
||||
|
||||
@@ -2451,4 +2451,7 @@ mRemoteNG will now quit and begin with the installation.</value>
|
||||
<data name="strPropertyDescriptionCredential" xml:space="preserve">
|
||||
<value>Select which credential to use for this connection.</value>
|
||||
</data>
|
||||
<data name="strConfirmDeleteCredentialRecord" xml:space="preserve">
|
||||
<value>Are you sure you want to delete the credential record, {0}?</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Windows.Forms;
|
||||
using BrightIdeasSoftware;
|
||||
using mRemoteNG.Credential;
|
||||
using mRemoteNG.Tree;
|
||||
|
||||
|
||||
namespace mRemoteNG.UI.Forms
|
||||
@@ -11,6 +12,7 @@ namespace mRemoteNG.UI.Forms
|
||||
private readonly CredentialManager _credentialManager;
|
||||
|
||||
public ICredentialRecord SelectedRecord => objectListView1.SelectedObject as ICredentialRecord;
|
||||
public IConfirm<ICredentialRecord> DeletionConfirmer { get; set; } = new AlwaysConfirmYes();
|
||||
|
||||
public CredentialManagerForm(CredentialManager credentialManager)
|
||||
{
|
||||
@@ -74,6 +76,7 @@ namespace mRemoteNG.UI.Forms
|
||||
{
|
||||
var selectedCredential = objectListView1.SelectedObject as CredentialRecord;
|
||||
if (selectedCredential == null) return;
|
||||
if (!DeletionConfirmer.Confirm(selectedCredential)) return;
|
||||
_credentialManager.Remove(selectedCredential);
|
||||
RaiseCredentialsChangedEvent(this);
|
||||
}
|
||||
|
||||
@@ -1334,7 +1334,10 @@ namespace mRemoteNG.UI.Forms
|
||||
|
||||
private void credentialManagerToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var credentialManagerForm = new CredentialManagerForm(_credentialManager);
|
||||
var credentialManagerForm = new CredentialManagerForm(_credentialManager)
|
||||
{
|
||||
DeletionConfirmer = new CredentialDeletionMsgBoxConfirmer(MessageBox.Show)
|
||||
};
|
||||
credentialManagerForm.CenterOnTarget(this);
|
||||
credentialManagerForm.Show();
|
||||
}
|
||||
|
||||
@@ -200,6 +200,7 @@
|
||||
<Compile Include="Connection\IHasParent.cs" />
|
||||
<Compile Include="Connection\Protocol\ProtocolFactory.cs" />
|
||||
<Compile Include="Connection\Protocol\VNC\VNCEnum.cs" />
|
||||
<Compile Include="Credential\CredentialDeletionMsgBoxConfirmer.cs" />
|
||||
<Compile Include="Credential\CredentialDomainUserComparer.cs" />
|
||||
<Compile Include="Credential\CredentialManager.cs" />
|
||||
<Compile Include="Credential\CredentialProviderCatalog.cs" />
|
||||
|
||||
Reference in New Issue
Block a user