mirror of
https://github.com/blueskythlikesclouds/SonicAudioTools.git
synced 2024-11-28 01:10:54 +01:00
87 lines
2.2 KiB
C#
87 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace CsbBuilder
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static TreeNode CreateNodesByFullPath(this TreeView treeView, string path)
|
|
{
|
|
string fullPath = string.Empty;
|
|
TreeNode currentNode = null;
|
|
|
|
foreach (string node in path.Split('/'))
|
|
{
|
|
fullPath += node;
|
|
|
|
TreeNode treeNode = treeView.FindNodeByFullPath(fullPath);
|
|
bool notFound = treeNode == null;
|
|
|
|
if (notFound)
|
|
{
|
|
treeNode = new TreeNode(node);
|
|
treeNode.Name = treeNode.Text;
|
|
}
|
|
|
|
if (currentNode != null && notFound)
|
|
{
|
|
currentNode.Nodes.Add(treeNode);
|
|
}
|
|
|
|
else if (currentNode == null && notFound)
|
|
{
|
|
treeView.Nodes.Add(treeNode);
|
|
}
|
|
|
|
currentNode = treeNode;
|
|
fullPath += '/';
|
|
}
|
|
|
|
return currentNode;
|
|
}
|
|
|
|
|
|
public static TreeNode FindNodeByFullPath(this TreeNode treeNode, string path)
|
|
{
|
|
foreach (TreeNode node in treeNode.Nodes)
|
|
{
|
|
if (node.FullPath == path)
|
|
{
|
|
return node;
|
|
}
|
|
|
|
TreeNode childNode = node.FindNodeByFullPath(path);
|
|
if (childNode != null)
|
|
{
|
|
return childNode;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static TreeNode FindNodeByFullPath(this TreeView treeView, string path)
|
|
{
|
|
foreach (TreeNode node in treeView.Nodes)
|
|
{
|
|
if (node.FullPath == path)
|
|
{
|
|
return node;
|
|
}
|
|
|
|
TreeNode childNode = node.FindNodeByFullPath(path);
|
|
if (childNode != null)
|
|
{
|
|
return childNode;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|