From 5c9f4690388d74e715e38909bd9dc2db638ef085 Mon Sep 17 00:00:00 2001 From: MayNL Date: Sun, 28 Jun 2026 20:43:37 -0400 Subject: [PATCH] Folders now sort on top of other files --- PCK-Studio/Internal/PckNodeSorter.cs | 50 +++++++++++++++++----------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/PCK-Studio/Internal/PckNodeSorter.cs b/PCK-Studio/Internal/PckNodeSorter.cs index 174cd4f2..12830968 100644 --- a/PCK-Studio/Internal/PckNodeSorter.cs +++ b/PCK-Studio/Internal/PckNodeSorter.cs @@ -1,10 +1,9 @@ -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Windows.Forms; - -using OMI.Formats.Pck; +using OMI.Formats.Pck; using PckStudio.Core.Extensions; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Windows.Forms; namespace PckStudio.Internal { @@ -37,20 +36,33 @@ namespace PckStudio.Internal return result; } - private int InternalCompare(TreeNode first, TreeNode second) - { - if (first.IsTagOfType() && !second.IsTagOfType()) - return -1; - if (!first.IsTagOfType() && second.IsTagOfType()) - return 1; + private int InternalCompare(TreeNode first, TreeNode second) + { + bool firstIsFile = first.IsTagOfType(); + bool secondIsFile = second.IsTagOfType(); - if (CheckForSkinAndCapeFiles(first)) - return 1; - if (CheckForSkinAndCapeFiles(second)) - return 1; + // Put folders first + if (!firstIsFile && secondIsFile) + return -1; + if (firstIsFile && !secondIsFile) + return 1; - return first.Text.CompareTo(second.Text); - } - } + bool firstIsSkinOrCape = CheckForSkinAndCapeFiles(first); + bool secondIsSkinOrCape = CheckForSkinAndCapeFiles(second); + + // Skins and capes after the rest for simplicity + if (firstIsSkinOrCape && !secondIsSkinOrCape) + return 1; + if (!firstIsSkinOrCape && secondIsSkinOrCape) + return -1; + + // Don't change order if both are skin related files + if (firstIsSkinOrCape && secondIsSkinOrCape) + return 0; + + // Sort the rest alpha-numerically + return string.Compare(first.Text, second.Text, StringComparison.OrdinalIgnoreCase); + } + } } \ No newline at end of file