- add: Sorting in content viewer
This commit is contained in:
@@ -97,7 +97,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
|||||||
if(SearchText.Length > oldSearchText.Length)
|
if(SearchText.Length > oldSearchText.Length)
|
||||||
AppendHistory(oldSearchText);
|
AppendHistory(oldSearchText);
|
||||||
|
|
||||||
foreach (var (_, entryCh) in value.Childs) Entries.Add(entryCh);
|
foreach (var entryCh in value.Childs) Entries.Add(entryCh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,6 +239,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
|||||||
public class ContentEntry
|
public class ContentEntry
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, ContentEntry> _childs = new();
|
private readonly Dictionary<string, ContentEntry> _childs = new();
|
||||||
|
|
||||||
private readonly ContentBrowserViewModel _viewModel;
|
private readonly ContentBrowserViewModel _viewModel;
|
||||||
private HashApi _fileApi;
|
private HashApi _fileApi;
|
||||||
|
|
||||||
@@ -263,13 +264,8 @@ public class ContentEntry
|
|||||||
public ContentEntry? Parent { get; private set; }
|
public ContentEntry? Parent { get; private set; }
|
||||||
public bool IsRoot => Parent == null;
|
public bool IsRoot => Parent == null;
|
||||||
|
|
||||||
public IReadOnlyDictionary<string, ContentEntry> Childs => _childs.ToFrozenDictionary();
|
//TODO: Remove LINQ later...
|
||||||
|
public IReadOnlyList<ContentEntry> Childs => _childs.Values.OrderBy(v => v,new ContentComparer()).ToList();
|
||||||
public Stream Open()
|
|
||||||
{
|
|
||||||
_fileApi.TryOpen(Item!.Value, out var stream);
|
|
||||||
return stream!;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryOpen([NotNullWhen(true)] out Stream? stream,[NotNullWhen(true)] out RobustManifestItem? item){
|
public bool TryOpen([NotNullWhen(true)] out Stream? stream,[NotNullWhen(true)] out RobustManifestItem? item){
|
||||||
stream = null;
|
stream = null;
|
||||||
@@ -424,4 +420,19 @@ public struct ContentPath
|
|||||||
{
|
{
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ContentComparer : IComparer<ContentEntry>
|
||||||
|
{
|
||||||
|
public int Compare(ContentEntry? x, ContentEntry? y)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(x, y)) return 0;
|
||||||
|
if (y is null) return 1;
|
||||||
|
if (x is null) return -1;
|
||||||
|
var iconComparison = string.Compare(x.IconPath, y.IconPath, StringComparison.Ordinal);
|
||||||
|
if (iconComparison != 0) return -iconComparison;
|
||||||
|
var nameComparison = string.Compare(x.Name, y.Name, StringComparison.Ordinal);
|
||||||
|
if (nameComparison != 0) return nameComparison;
|
||||||
|
return string.Compare(x.ServerName, y.ServerName, StringComparison.Ordinal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user