added a deletion confirmer to the credential manager

This commit is contained in:
David Sparer
2017-01-26 09:41:15 -07:00
parent 6a871e73e0
commit 6ddd19ac54
6 changed files with 52 additions and 1 deletions

View 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;
}
}
}

View File

@@ -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, &quot;{0}&quot;?.
/// </summary>

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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" />