Skip to content

Commit

Permalink
Order master mod list and support filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Aug 24, 2024
1 parent 0c5db09 commit 7efbf21
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 41 deletions.
27 changes: 27 additions & 0 deletions src/Tkmm/ViewModels/Pages/ProfilesPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,12 @@ public ProfileMod? Selected {
}
}

[ObservableProperty]
private ObservableCollection<Mod> _filteredMods = GetOrderedMods();

[ObservableProperty]
private string? _filterArgument;

[ObservableProperty]
private Mod? _masterSelected;

Expand Down Expand Up @@ -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<Mod> GetOrderedMods()
{
return [.. ProfileManager.Shared.Mods.OrderBy(x => x.Name)];
}
}
88 changes: 47 additions & 41 deletions src/Tkmm/Views/Pages/ProfilesPageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,46 +117,52 @@
Margin="25,0"
Background="{DynamicResource SystemAccentColor}" />

<ListBox Name="MasterListBox"
Grid.Column="2"
Classes="ModDragDropListBox"
DragDrop.AllowDrop="True"
ItemsSource="{Binding Mods, Source={x:Static comp:ProfileManager.Shared}}"
SelectedItem="{Binding MasterSelected}"
SelectionMode="AlwaysSelected"
ToolTip.Tip="All Mods">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:Mod}">
<Grid ColumnDefinitions="*,Auto,Auto">
<TextBlock VerticalAlignment="Center"
Background="Transparent"
Text="{Binding Name}"
TextTrimming="CharacterEllipsis"
ToolTip.Tip="{Binding Name}" />
<Button Grid.Column="1"
Width="25"
Height="25"
Padding="0"
VerticalAlignment="Stretch"
Command="{Binding AddToCurrentProfileCommand}"
ToolTip.Tip="Add to current profile">
<pi:Icon Value="fa-solid fa-plus" />
</Button>
<Button Grid.Column="2"
Width="25"
Height="25"
Margin="5,0,0,0"
Padding="0"
VerticalAlignment="Stretch"
x:CompileBindings="False"
Command="{Binding $parent[UserControl].DataContext.UninstallCommand}"
CommandParameter="{Binding}"
ToolTip.Tip="Uninstall">
<pi:Icon Value="fa-solid fa-trash-xmark" />
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Column="2" RowDefinitions="Auto,*">
<TextBox Margin="0,0,0,10"
Classes="clearButton"
Text="{Binding FilterArgument}"
Watermark="Search" />
<ListBox Name="MasterListBox"
Grid.Row="1"
Classes="ModDragDropListBox"
DragDrop.AllowDrop="True"
ItemsSource="{Binding FilteredMods}"
SelectedItem="{Binding MasterSelected}"
SelectionMode="AlwaysSelected"
ToolTip.Tip="All Mods">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:Mod}">
<Grid ColumnDefinitions="*,Auto,Auto">
<TextBlock VerticalAlignment="Center"
Background="Transparent"
Text="{Binding Name}"
TextTrimming="CharacterEllipsis"
ToolTip.Tip="{Binding Name}" />
<Button Grid.Column="1"
Width="25"
Height="25"
Padding="0"
VerticalAlignment="Stretch"
Command="{Binding AddToCurrentProfileCommand}"
ToolTip.Tip="Add to current profile">
<pi:Icon Value="fa-solid fa-plus" />
</Button>
<Button Grid.Column="2"
Width="25"
Height="25"
Margin="5,0,0,0"
Padding="0"
VerticalAlignment="Stretch"
x:CompileBindings="False"
Command="{Binding $parent[UserControl].DataContext.UninstallCommand}"
CommandParameter="{Binding}"
ToolTip.Tip="Uninstall">
<pi:Icon Value="fa-solid fa-trash-xmark" />
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
</UserControl>

0 comments on commit 7efbf21

Please sign in to comment.