From ce4bfc55c12e17d0a96a89295e524d0f446faab8 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Tue, 2 May 2017 08:49:04 -0600 Subject: [PATCH] ConnectionInfo.Clone no longer sets the Parent property this resolves undesirable tree nodes from being created --- mRemoteNGTests/Connection/ConnectionInfoTests.cs | 8 ++++++++ mRemoteNGTests/Container/ContainerInfoTests.cs | 8 ++++++++ mRemoteV1/Connection/ConnectionInfo.cs | 1 - mRemoteV1/Container/ContainerInfo.cs | 1 - mRemoteV1/Tree/ConnectionTreeModel.cs | 5 ----- mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs | 1 + 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mRemoteNGTests/Connection/ConnectionInfoTests.cs b/mRemoteNGTests/Connection/ConnectionInfoTests.cs index ea6cf7d9..0eff910f 100644 --- a/mRemoteNGTests/Connection/ConnectionInfoTests.cs +++ b/mRemoteNGTests/Connection/ConnectionInfoTests.cs @@ -48,6 +48,14 @@ namespace mRemoteNGTests.Connection Assert.That(secondConnection.Domain, Is.EqualTo(_connectionInfo.Domain)); } + [Test] + public void CloneDoesNotSetParentOfNewConnectionInfo() + { + _connectionInfo.SetParent(new ContainerInfo()); + var clonedConnection = _connectionInfo.Clone(); + Assert.That(clonedConnection.Parent, Is.Null); + } + [Test] public void CopyFromCopiesProperties() { diff --git a/mRemoteNGTests/Container/ContainerInfoTests.cs b/mRemoteNGTests/Container/ContainerInfoTests.cs index 133f5069..8c08a419 100644 --- a/mRemoteNGTests/Container/ContainerInfoTests.cs +++ b/mRemoteNGTests/Container/ContainerInfoTests.cs @@ -263,6 +263,14 @@ namespace mRemoteNGTests.Container Assert.That(clone.ConstantID, Is.Not.EqualTo(_containerInfo.ConstantID)); } + [Test] + public void ClonedContainerDoesNotHaveParentSet() + { + _containerInfo.SetParent(new ContainerInfo()); + var clone = _containerInfo.Clone(); + Assert.That(clone.Parent, Is.Null); + } + [Test] public void ClonedContainerContainsClonedChildren() { diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index 76b006ae..c3fc1107 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -78,7 +78,6 @@ namespace mRemoteNG.Connection var newConnectionInfo = new ConnectionInfo(); newConnectionInfo.CopyFrom(this); newConnectionInfo.ConstantID = MiscTools.CreateConstantID(); - newConnectionInfo.SetParent(Parent); newConnectionInfo.Inheritance = Inheritance.Clone(); return newConnectionInfo; } diff --git a/mRemoteV1/Container/ContainerInfo.cs b/mRemoteV1/Container/ContainerInfo.cs index 114b36e3..9650e822 100644 --- a/mRemoteV1/Container/ContainerInfo.cs +++ b/mRemoteV1/Container/ContainerInfo.cs @@ -179,7 +179,6 @@ namespace mRemoteNG.Container var newContainer = new ContainerInfo(); newContainer.CopyFrom(this); newContainer.ConstantID = MiscTools.CreateConstantID(); - newContainer.SetParent(Parent); newContainer.OpenConnections = new ProtocolList(); newContainer.Inheritance = Inheritance.Clone(); foreach (var child in Children.ToArray()) diff --git a/mRemoteV1/Tree/ConnectionTreeModel.cs b/mRemoteV1/Tree/ConnectionTreeModel.cs index 3c30baaa..0d75a780 100644 --- a/mRemoteV1/Tree/ConnectionTreeModel.cs +++ b/mRemoteV1/Tree/ConnectionTreeModel.cs @@ -63,11 +63,6 @@ namespace mRemoteNG.Tree connectionInfo?.RemoveParent(); } - public void CloneNode(ConnectionInfo connectionInfo) - { - connectionInfo.Clone(); - } - public event NotifyCollectionChangedEventHandler CollectionChanged; private void RaiseCollectionChangedEvent(object sender, NotifyCollectionChangedEventArgs args) { diff --git a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs index cb640ba0..e19e4713 100644 --- a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs +++ b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs @@ -215,6 +215,7 @@ namespace mRemoteNG.UI.Controls public void DuplicateSelectedNode() { var newNode = SelectedNode.Clone(); + SelectedNode.Parent.AddChildBelow(newNode, SelectedNode); newNode.Parent.SetChildBelow(newNode, SelectedNode); Runtime.SaveConnectionsAsync(); }