mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
modified the interface for the IConfirmer to be generic
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace mRemoteNG.Tree
|
||||
{
|
||||
public interface IConfirm
|
||||
public interface IConfirm<in TConfirmationTarget>
|
||||
{
|
||||
bool Confirm();
|
||||
bool Confirm(TConfirmationTarget confirmationTarget);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user