modified the interface for the IConfirmer to be generic

This commit is contained in:
David Sparer
2017-01-26 09:38:55 -07:00
parent 7ba106d97b
commit 6a871e73e0
6 changed files with 14 additions and 18 deletions

View File

@@ -23,15 +23,15 @@ namespace mRemoteNGTests.Tree
[Test]
public void ClickingYesReturnsTrue()
{
_deletionConfirmer = new SelectedConnectionDeletionConfirmer(_connectionTree, MockClickYes);
Assert.That(_deletionConfirmer.Confirm(), Is.True);
_deletionConfirmer = new SelectedConnectionDeletionConfirmer(MockClickYes);
Assert.That(_deletionConfirmer.Confirm(_connectionTree.SelectedNode), Is.True);
}
[Test]
public void ClickingNoReturnsFalse()
{
_deletionConfirmer = new SelectedConnectionDeletionConfirmer(_connectionTree, MockClickNo);
Assert.That(_deletionConfirmer.Confirm(), Is.False);
_deletionConfirmer = new SelectedConnectionDeletionConfirmer(MockClickNo);
Assert.That(_deletionConfirmer.Confirm(_connectionTree.SelectedNode), Is.False);
}
private DialogResult MockClickYes(string promptMessage, string title, MessageBoxButtons buttons, MessageBoxIcon icon)

View File

@@ -1,9 +1,9 @@

namespace mRemoteNG.Tree
{
public class AlwaysConfirmYes : IConfirm
public class AlwaysConfirmYes : IConfirm<object>
{
public bool Confirm()
public bool Confirm(object target)
{
return true;
}

View File

@@ -1,7 +1,7 @@
namespace mRemoteNG.Tree
{
public interface IConfirm
public interface IConfirm<in TConfirmationTarget>
{
bool Confirm();
bool Confirm(TConfirmationTarget confirmationTarget);
}
}

View File

@@ -2,25 +2,21 @@
using System.Windows.Forms;
using mRemoteNG.Connection;
using mRemoteNG.Container;
using mRemoteNG.UI.Controls;
namespace mRemoteNG.Tree
{
public class SelectedConnectionDeletionConfirmer : IConfirm
public class SelectedConnectionDeletionConfirmer : IConfirm<ConnectionInfo>
{
private readonly IConnectionTree _connectionTree;
private readonly Func<string, string, MessageBoxButtons, MessageBoxIcon, DialogResult> _confirmationFunc;
public SelectedConnectionDeletionConfirmer(IConnectionTree connectionTree, Func<string, string, MessageBoxButtons, MessageBoxIcon, DialogResult> confirmationFunc)
public SelectedConnectionDeletionConfirmer(Func<string, string, MessageBoxButtons, MessageBoxIcon, DialogResult> confirmationFunc)
{
_connectionTree = connectionTree;
_confirmationFunc = confirmationFunc;
}
public bool Confirm()
public bool Confirm(ConnectionInfo deletionTarget)
{
var deletionTarget = _connectionTree.SelectedNode;
var deletionTargetAsContainer = deletionTarget as ContainerInfo;
if (deletionTargetAsContainer != null)
return deletionTargetAsContainer.HasChildren()

View File

@@ -25,7 +25,7 @@ namespace mRemoteNG.UI.Controls
public NodeSearcher NodeSearcher { get; private set; }
public IConfirm NodeDeletionConfirmer { get; set; } = new AlwaysConfirmYes();
public IConfirm<ConnectionInfo> NodeDeletionConfirmer { get; set; } = new AlwaysConfirmYes();
public IEnumerable<IConnectionTreeDelegate> PostSetupActions { get; set; } = new IConnectionTreeDelegate[0];
@@ -227,7 +227,7 @@ namespace mRemoteNG.UI.Controls
public void DeleteSelectedNode()
{
if (SelectedNode is RootNodeInfo || SelectedNode is PuttySessionInfo) return;
if (!NodeDeletionConfirmer.Confirm()) return;
if (!NodeDeletionConfirmer.Confirm(SelectedNode)) return;
ConnectionTreeModel.DeleteNode(SelectedNode);
Runtime.SaveConnectionsAsync();
}

View File

@@ -83,7 +83,7 @@ namespace mRemoteNG.UI.Window
#region ConnectionTree
private void SetConnectionTreeEventHandlers()
{
olvConnections.NodeDeletionConfirmer = new SelectedConnectionDeletionConfirmer(olvConnections, MessageBox.Show);
olvConnections.NodeDeletionConfirmer = new SelectedConnectionDeletionConfirmer(MessageBox.Show);
olvConnections.BeforeLabelEdit += tvConnections_BeforeLabelEdit;
olvConnections.AfterLabelEdit += tvConnections_AfterLabelEdit;
olvConnections.KeyDown += tvConnections_KeyDown;