mirror of
https://github.com/4sval/FModel.git
synced 2026-08-12 04:06:58 -05:00
pulled c4p
This commit is contained in:
Submodule CUE4Parse updated: 65d2cc0ba1...1b82397777
@@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using CUE4Parse.FileProvider.Objects;
|
||||
using CUE4Parse.UE4.VirtualFileSystem;
|
||||
using FModel.Framework;
|
||||
|
||||
namespace FModel.ViewModels;
|
||||
@@ -64,7 +66,7 @@ public class SearchViewModel : ViewModel
|
||||
SearchResultsView.Refresh();
|
||||
}
|
||||
|
||||
public void CycleSortSizeMode()
|
||||
public async Task CycleSortSizeMode()
|
||||
{
|
||||
CurrentSortSizeMode = CurrentSortSizeMode switch
|
||||
{
|
||||
@@ -73,18 +75,37 @@ public class SearchViewModel : ViewModel
|
||||
_ => ESortSizeMode.None
|
||||
};
|
||||
|
||||
using (SearchResultsView.DeferRefresh())
|
||||
var sorted = await Task.Run(() =>
|
||||
{
|
||||
SearchResultsView.SortDescriptions.Clear();
|
||||
if (CurrentSortSizeMode != ESortSizeMode.None)
|
||||
{
|
||||
var sort = CurrentSortSizeMode == ESortSizeMode.Ascending
|
||||
? ListSortDirection.Ascending
|
||||
: ListSortDirection.Descending;
|
||||
var archiveDict = SearchResults
|
||||
.OfType<VfsEntry>()
|
||||
.Select(f => f.Vfs.Name)
|
||||
.Distinct()
|
||||
.Select((name, idx) => (name, idx))
|
||||
.ToDictionary(x => x.name, x => x.idx);
|
||||
|
||||
SearchResultsView.SortDescriptions.Add(new SortDescription(nameof(GameFile.Size), sort));
|
||||
}
|
||||
}
|
||||
var keyed = SearchResults.Select(f =>
|
||||
{
|
||||
int archiveKey = f is VfsEntry ve && archiveDict.TryGetValue(ve.Vfs.Name, out var key) ? key : -1;
|
||||
return (File: f, f.Size, ArchiveKey: archiveKey);
|
||||
});
|
||||
|
||||
return CurrentSortSizeMode switch
|
||||
{
|
||||
ESortSizeMode.Ascending => keyed
|
||||
.OrderBy(x => x.Size).ThenBy(x => x.ArchiveKey)
|
||||
.Select(x => x.File).ToList(),
|
||||
ESortSizeMode.Descending => keyed
|
||||
.OrderByDescending(x => x.Size).ThenBy(x => x.ArchiveKey)
|
||||
.Select(x => x.File).ToList(),
|
||||
_ => keyed
|
||||
.OrderBy(x => x.ArchiveKey).ThenBy(x => x.File.Path, StringComparer.OrdinalIgnoreCase)
|
||||
.Select(x => x.File).ToList()
|
||||
};
|
||||
});
|
||||
|
||||
SearchResults.Clear();
|
||||
SearchResults.AddRange(sorted.ToList());
|
||||
}
|
||||
|
||||
private bool ItemFilter(object item, IEnumerable<string> filters)
|
||||
|
||||
@@ -97,7 +97,11 @@
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<ListView Grid.Row="1" x:Name="SearchListView" VirtualizingPanel.IsVirtualizing="True" ItemsSource="{Binding CUE4Parse.SearchVm.SearchResultsView, IsAsync=True}">
|
||||
<ListView Grid.Row="1" x:Name="SearchListView"
|
||||
VirtualizingPanel.IsVirtualizing="True"
|
||||
VirtualizingPanel.VirtualizationMode="Recycling"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
ItemsSource="{Binding CUE4Parse.SearchVm.SearchResultsView, IsAsync=True}">
|
||||
<ListView.Resources>
|
||||
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
|
||||
@@ -29,9 +29,9 @@ public partial class SearchView
|
||||
_applicationView.CUE4Parse.SearchVm.RefreshFilter();
|
||||
}
|
||||
|
||||
private void OnSortClick(object sender, RoutedEventArgs e)
|
||||
private async void OnSortClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_applicationView.CUE4Parse.SearchVm.CycleSortSizeMode();
|
||||
await _applicationView.CUE4Parse.SearchVm.CycleSortSizeMode();
|
||||
}
|
||||
|
||||
private async void OnAssetDoubleClick(object sender, RoutedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user