sort Properties and wwwroot above other folders
This commit is contained in:
@@ -15,6 +15,7 @@ public class SharpIdeFileComparer : IComparer<SharpIdeFile>
|
||||
}
|
||||
}
|
||||
|
||||
// AI
|
||||
public class SharpIdeFolderComparer : IComparer<SharpIdeFolder>
|
||||
{
|
||||
public static readonly SharpIdeFolderComparer Instance = new SharpIdeFolderComparer();
|
||||
@@ -24,8 +25,24 @@ public class SharpIdeFolderComparer : IComparer<SharpIdeFolder>
|
||||
if (x is null) return -1;
|
||||
if (y is null) return 1;
|
||||
|
||||
int result = string.Compare(x.Path, y.Path, StringComparison.OrdinalIgnoreCase);
|
||||
// Special folders priority: Properties > wwwroot > others
|
||||
int xPriority = GetFolderPriority(x.Name);
|
||||
int yPriority = GetFolderPriority(y.Name);
|
||||
|
||||
return result;
|
||||
int priorityComparison = xPriority.CompareTo(yPriority);
|
||||
if (priorityComparison != 0) return priorityComparison;
|
||||
|
||||
// Default alphabetical compare for same priority
|
||||
return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static int GetFolderPriority(string? name)
|
||||
{
|
||||
if (string.Equals(name, "Properties", StringComparison.OrdinalIgnoreCase))
|
||||
return 0;
|
||||
if (string.Equals(name, "wwwroot", StringComparison.OrdinalIgnoreCase))
|
||||
return 1;
|
||||
|
||||
return 2; // all others
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user