From 2edb8986bb45155e85f9dc1da865ac4dfd5eeb3f Mon Sep 17 00:00:00 2001
From: miku-666 <74728189+NessieHax@users.noreply.github.com>
Date: Fri, 28 Nov 2025 08:33:20 +0100
Subject: [PATCH] Core - Add TreeNodeCollectionExtensions.cs
---
PCK-Studio/Controls/PckAssetBrowserEditor.cs | 40 +---------------
.../TreeNodeCollectionExtensions.cs | 47 +++++++++++++++++++
PckStudio.Core/PckStudio.Core.csproj | 1 +
3 files changed, 49 insertions(+), 39 deletions(-)
create mode 100644 PckStudio.Core/Extensions/TreeNodeCollectionExtensions.cs
diff --git a/PCK-Studio/Controls/PckAssetBrowserEditor.cs b/PCK-Studio/Controls/PckAssetBrowserEditor.cs
index 621246c8..41a6e1fe 100644
--- a/PCK-Studio/Controls/PckAssetBrowserEditor.cs
+++ b/PCK-Studio/Controls/PckAssetBrowserEditor.cs
@@ -577,49 +577,11 @@ namespace PckStudio.Controls
}
}
- ///
- /// wrapper that allows the use of in TreeNode.Nodes.Find(, ...) and TreeNode.Nodes.ContainsKey()
- ///
- ///
- ///
- /// new Created TreeNode
- private static TreeNode CreateNode(string name, object tag = null)
- {
- TreeNode node = new TreeNode(name);
- node.Name = name;
- node.Tag = tag;
- return node;
- }
-
- private TreeNode BuildNodeTreeBySeperator(TreeNodeCollection root, string path, char seperator)
- {
- _ = root ?? throw new ArgumentNullException(nameof(root));
- if (!path.Contains(seperator))
- {
- TreeNode finalNode = CreateNode(path);
- root.Add(finalNode);
- return finalNode;
- }
- string nodeText = path.Substring(0, path.IndexOf(seperator));
- string subPath = path.Substring(path.IndexOf(seperator) + 1);
-
- if (string.IsNullOrWhiteSpace(nodeText))
- {
- return BuildNodeTreeBySeperator(root, subPath, seperator);
- }
-
- bool alreadyExists = root.ContainsKey(nodeText);
- TreeNode subNode = alreadyExists ? root[nodeText] : CreateNode(nodeText);
- if (!alreadyExists)
- root.Add(subNode);
- return BuildNodeTreeBySeperator(subNode.Nodes, subPath, seperator);
- }
-
private void BuildPckTreeView(TreeNodeCollection root, PckFile pckFile)
{
foreach (PckAsset asset in pckFile.GetAssets())
{
- TreeNode node = BuildNodeTreeBySeperator(root, asset.Filename, '/');
+ TreeNode node = root.BuildNodeTreeBySeperator(asset.Filename, '/');
node.Tag = asset;
int nodeIconId = GetNodeIconId(asset.Type);
node.ImageIndex = nodeIconId;
diff --git a/PckStudio.Core/Extensions/TreeNodeCollectionExtensions.cs b/PckStudio.Core/Extensions/TreeNodeCollectionExtensions.cs
new file mode 100644
index 00000000..133b88f2
--- /dev/null
+++ b/PckStudio.Core/Extensions/TreeNodeCollectionExtensions.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace PckStudio.Core.Extensions
+{
+ public static class TreeNodeCollectionExtensions
+ {
+
+ ///
+ /// wrapper that allows the use of in TreeNode.Nodes.Find(, ...) and TreeNode.Nodes.ContainsKey()
+ ///
+ ///
+ ///
+ /// new Created TreeNode
+ public static TreeNode CreateNode(this TreeNodeCollection root, string name, object tag = null)
+ {
+ TreeNode node = new TreeNode(name);
+ node.Name = name;
+ node.Tag = tag;
+ root.Add(node);
+ return node;
+ }
+
+ public static TreeNode BuildNodeTreeBySeperator(this TreeNodeCollection root, string path, char seperator)
+ {
+ _ = root ?? throw new ArgumentNullException(nameof(root));
+ if (!path.Contains(seperator))
+ {
+ return root.CreateNode(path);
+ }
+ string nodeText = path.Substring(0, path.IndexOf(seperator));
+ string subPath = path.Substring(path.IndexOf(seperator) + 1);
+
+ if (string.IsNullOrWhiteSpace(nodeText))
+ {
+ return BuildNodeTreeBySeperator(root, subPath, seperator);
+ }
+
+ TreeNode subNode = root.ContainsKey(nodeText) ? root[nodeText] : root.CreateNode(nodeText);
+ return BuildNodeTreeBySeperator(subNode.Nodes, subPath, seperator);
+ }
+ }
+}
diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj
index 1fb9c5ae..671efa3f 100644
--- a/PckStudio.Core/PckStudio.Core.csproj
+++ b/PckStudio.Core/PckStudio.Core.csproj
@@ -103,6 +103,7 @@
+