Moved the code for generating a recursive list of children to ContainerInfo where it makes more sense. Left a helper function in ConnectionTreeModel where it may still be useful

This commit is contained in:
David Sparer
2016-09-06 14:55:19 -06:00
parent bec154e538
commit 617ec4cc3e
4 changed files with 31 additions and 13 deletions

View File

@@ -33,7 +33,7 @@ namespace mRemoteNGTests.Tree
folder1.Add(folder2);
root.Add(con1);
_connectionTreeModel.AddRootNode(root);
var connectionList = _connectionTreeModel.GetChildList(root);
var connectionList = _connectionTreeModel.GetRecursiveChildList(root);
Assert.That(connectionList, Is.EquivalentTo(new[] {folder1,folder2,con1}));
}
}

View File

@@ -62,5 +62,31 @@ namespace mRemoteNG.Container
{
IsExpanded = true;
}
}
public IEnumerable<ConnectionInfo> GetRecursiveChildList()
{
var childList = new List<ConnectionInfo>();
foreach (var child in Children)
{
childList.Add(child);
var childContainer = child as ContainerInfo;
if (childContainer != null)
childList.AddRange(GetRecursiveChildList(childContainer));
}
return childList;
}
private IEnumerable<ConnectionInfo> GetRecursiveChildList(ContainerInfo container)
{
var childList = new List<ConnectionInfo>();
foreach (var child in container.Children)
{
childList.Add(child);
var childContainer = child as ContainerInfo;
if (childContainer != null)
childList.AddRange(GetRecursiveChildList(childContainer));
}
return childList;
}
}
}

View File

@@ -14,17 +14,9 @@ namespace mRemoteNG.Tree
RootNodes.Add(rootNode);
}
public IEnumerable<ConnectionInfo> GetChildList(ContainerInfo container)
public IEnumerable<ConnectionInfo> GetRecursiveChildList(ContainerInfo container)
{
var childList = new List<ConnectionInfo>();
foreach (var child in container.Children)
{
childList.Add(child);
var childContainer = child as ContainerInfo;
if (childContainer != null)
childList.AddRange(GetChildList(childContainer));
}
return childList;
return container.GetRecursiveChildList();
}
}
}

View File

@@ -151,7 +151,7 @@ namespace mRemoteNG.UI.Window
public void ExpandPreviouslyOpenedFolders()
{
var containerList = ConnectionTreeModel.GetChildList(GetRootConnectionNode()).OfType<ContainerInfo>();
var containerList = ConnectionTreeModel.GetRecursiveChildList(GetRootConnectionNode()).OfType<ContainerInfo>();
var previouslyExpandedNodes = containerList.Where(container => container.IsExpanded);
olvConnections.ExpandedObjects = previouslyExpandedNodes;
olvConnections.RebuildAll(true);