From 5ea2304d5e4c1f3162035fe9ef609ae07a4f8eb2 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Wed, 7 Sep 2016 14:36:52 -0600 Subject: [PATCH] Duplicating nodes now works --- mRemoteV1/Connection/ConnectionInfo.cs | 5 +++-- mRemoteV1/Container/ContainerInfo.cs | 15 ++++++++++++--- mRemoteV1/Tree/ConnectionTreeModel.cs | 4 ++++ mRemoteV1/Tree/ConnectionTreeNode.cs | 2 +- mRemoteV1/UI/Window/ConnectionTreeWindow.cs | 5 +++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index 76469073..acc78596 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -670,7 +670,8 @@ namespace mRemoteNG.Connection #region Public Methods public virtual ConnectionInfo Clone() { - var newConnectionInfo = (ConnectionInfo)MemberwiseClone(); + var newConnectionInfo = new ConnectionInfo(); + newConnectionInfo.CopyFrom(this); newConnectionInfo.ConstantID = MiscTools.CreateConstantID(); newConnectionInfo.SetParent(Parent); newConnectionInfo.OpenConnections = new ProtocolList(); @@ -718,7 +719,7 @@ namespace mRemoteNG.Connection return filteredProperties; } - public void SetParent(ContainerInfo parent) + public virtual void SetParent(ContainerInfo parent) { parent?.AddChild(this); } diff --git a/mRemoteV1/Container/ContainerInfo.cs b/mRemoteV1/Container/ContainerInfo.cs index 378c70c8..1627db27 100644 --- a/mRemoteV1/Container/ContainerInfo.cs +++ b/mRemoteV1/Container/ContainerInfo.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using mRemoteNG.Connection; using System.ComponentModel; +using mRemoteNG.Connection.Protocol; using mRemoteNG.Tools; using mRemoteNG.Tree; @@ -66,9 +67,17 @@ namespace mRemoteNG.Container public override ConnectionInfo Clone() { var newContainer = new ContainerInfo(); - newContainer.CopyFrom(base.Clone()); - foreach (var child in Children) - newContainer.AddChild(child.Clone()); + newContainer.CopyFrom(this); + newContainer.ConstantID = MiscTools.CreateConstantID(); + newContainer.SetParent(Parent); + newContainer.OpenConnections = new ProtocolList(); + newContainer.Inheritance = Inheritance.Clone(); + foreach (var child in Children.ToArray()) + { + var newChild = child.Clone(); + newChild.RemoveParent(); + newContainer.AddChild(newChild); + } return newContainer; } diff --git a/mRemoteV1/Tree/ConnectionTreeModel.cs b/mRemoteV1/Tree/ConnectionTreeModel.cs index 83071e16..5234e134 100644 --- a/mRemoteV1/Tree/ConnectionTreeModel.cs +++ b/mRemoteV1/Tree/ConnectionTreeModel.cs @@ -37,6 +37,10 @@ namespace mRemoteNG.Tree connectionInfo?.Dispose(); } + + public void CloneNode(ConnectionInfo connectionInfo) + { + connectionInfo.Clone(); } } } \ No newline at end of file diff --git a/mRemoteV1/Tree/ConnectionTreeNode.cs b/mRemoteV1/Tree/ConnectionTreeNode.cs index 44917312..8727e027 100644 --- a/mRemoteV1/Tree/ConnectionTreeNode.cs +++ b/mRemoteV1/Tree/ConnectionTreeNode.cs @@ -175,7 +175,7 @@ namespace mRemoteNG.Tree { ContainerInfo oldContainerInfo = (ContainerInfo) oldTreeNode.Tag; - ContainerInfo newContainerInfo = oldContainerInfo.Clone(); + ContainerInfo newContainerInfo = (ContainerInfo)oldContainerInfo.Clone(); ConnectionInfo newConnectionInfo = oldContainerInfo.Clone(); newContainerInfo.CopyFrom(newConnectionInfo); diff --git a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs index 32bb7822..5760f6c1 100644 --- a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs @@ -654,9 +654,10 @@ namespace mRemoteNG.UI.Window //TODO Fix for TreeListView private void cMenTreeDuplicate_Click(object sender, EventArgs e) - { - ConnectionTreeNode.CloneNode(tvConnections.SelectedNode); + { + SelectedNode.Clone(); Runtime.SaveConnectionsBG(); + olvConnections.RebuildAll(true); } private void cMenTreeRename_Click(object sender, EventArgs e)