From 6a871e73e04d8ae19448c2e01439234adf90e127 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Thu, 26 Jan 2017 09:38:55 -0700 Subject: [PATCH] modified the interface for the IConfirmer to be generic --- .../Tree/SelectedConnectionDeletionConfirmerTests.cs | 8 ++++---- mRemoteV1/Tree/AlwaysConfirmYes.cs | 4 ++-- mRemoteV1/Tree/IConfirm.cs | 4 ++-- mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs | 10 +++------- mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs | 4 ++-- mRemoteV1/UI/Window/ConnectionTreeWindow.cs | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs b/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs index ffab4e6b..77a226b1 100644 --- a/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs +++ b/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs @@ -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) diff --git a/mRemoteV1/Tree/AlwaysConfirmYes.cs b/mRemoteV1/Tree/AlwaysConfirmYes.cs index 40d0989e..5eb7b9fe 100644 --- a/mRemoteV1/Tree/AlwaysConfirmYes.cs +++ b/mRemoteV1/Tree/AlwaysConfirmYes.cs @@ -1,9 +1,9 @@  namespace mRemoteNG.Tree { - public class AlwaysConfirmYes : IConfirm + public class AlwaysConfirmYes : IConfirm { - public bool Confirm() + public bool Confirm(object target) { return true; } diff --git a/mRemoteV1/Tree/IConfirm.cs b/mRemoteV1/Tree/IConfirm.cs index e4434cb5..606c8b81 100644 --- a/mRemoteV1/Tree/IConfirm.cs +++ b/mRemoteV1/Tree/IConfirm.cs @@ -1,7 +1,7 @@ namespace mRemoteNG.Tree { - public interface IConfirm + public interface IConfirm { - bool Confirm(); + bool Confirm(TConfirmationTarget confirmationTarget); } } \ No newline at end of file diff --git a/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs b/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs index 29ab1046..a6bbaeb3 100644 --- a/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs +++ b/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs @@ -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 { - private readonly IConnectionTree _connectionTree; private readonly Func _confirmationFunc; - public SelectedConnectionDeletionConfirmer(IConnectionTree connectionTree, Func confirmationFunc) + public SelectedConnectionDeletionConfirmer(Func 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() diff --git a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs index 3f01fa54..0faea8fc 100644 --- a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs +++ b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs @@ -25,7 +25,7 @@ namespace mRemoteNG.UI.Controls public NodeSearcher NodeSearcher { get; private set; } - public IConfirm NodeDeletionConfirmer { get; set; } = new AlwaysConfirmYes(); + public IConfirm NodeDeletionConfirmer { get; set; } = new AlwaysConfirmYes(); public IEnumerable 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(); } diff --git a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs index 3ce13648..d6716a41 100644 --- a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs @@ -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;