diff --git a/src/Tkmm/ViewModels/Pages/ProfilesPageViewModel.cs b/src/Tkmm/ViewModels/Pages/ProfilesPageViewModel.cs index b421746e..70718da7 100644 --- a/src/Tkmm/ViewModels/Pages/ProfilesPageViewModel.cs +++ b/src/Tkmm/ViewModels/Pages/ProfilesPageViewModel.cs @@ -2,6 +2,8 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using FluentAvalonia.UI.Controls; +using System.Collections.ObjectModel; +using System.Runtime.CompilerServices; using Tkmm.Core.Components; using Tkmm.Core.Components.Models; using Tkmm.Core.Models.Mods; @@ -19,6 +21,12 @@ public ProfileMod? Selected { } } + [ObservableProperty] + private ObservableCollection _filteredMods = GetOrderedMods(); + + [ObservableProperty] + private string? _filterArgument; + [ObservableProperty] private Mod? _masterSelected; @@ -113,4 +121,23 @@ This cannot be undone. ? --currentIndex : currentIndex ]; } + + partial void OnFilterArgumentChanged(string? value) + { + if (string.IsNullOrEmpty(value)) { + FilteredMods = GetOrderedMods(); + return; + } + + FilteredMods = [..ProfileManager.Shared.Mods + .Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase) || value.Contains(x.Name, StringComparison.InvariantCultureIgnoreCase)) + .OrderBy(x => x.Name) + ]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ObservableCollection GetOrderedMods() + { + return [.. ProfileManager.Shared.Mods.OrderBy(x => x.Name)]; + } } diff --git a/src/Tkmm/Views/Pages/ProfilesPageView.axaml b/src/Tkmm/Views/Pages/ProfilesPageView.axaml index 8c6446c4..d637ae8d 100644 --- a/src/Tkmm/Views/Pages/ProfilesPageView.axaml +++ b/src/Tkmm/Views/Pages/ProfilesPageView.axaml @@ -117,46 +117,52 @@ Margin="25,0" Background="{DynamicResource SystemAccentColor}" /> - - - - - - - - - - - + + + + + + + + + + + + + +