Skip to content

Commit 7efbf21

Browse files
committed
Order master mod list and support filtering
1 parent 0c5db09 commit 7efbf21

File tree

2 files changed

+74
-41
lines changed

2 files changed

+74
-41
lines changed

src/Tkmm/ViewModels/Pages/ProfilesPageViewModel.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using CommunityToolkit.Mvvm.ComponentModel;
33
using CommunityToolkit.Mvvm.Input;
44
using FluentAvalonia.UI.Controls;
5+
using System.Collections.ObjectModel;
6+
using System.Runtime.CompilerServices;
57
using Tkmm.Core.Components;
68
using Tkmm.Core.Components.Models;
79
using Tkmm.Core.Models.Mods;
@@ -19,6 +21,12 @@ public ProfileMod? Selected {
1921
}
2022
}
2123

24+
[ObservableProperty]
25+
private ObservableCollection<Mod> _filteredMods = GetOrderedMods();
26+
27+
[ObservableProperty]
28+
private string? _filterArgument;
29+
2230
[ObservableProperty]
2331
private Mod? _masterSelected;
2432

@@ -113,4 +121,23 @@ This cannot be undone.
113121
? --currentIndex : currentIndex
114122
];
115123
}
124+
125+
partial void OnFilterArgumentChanged(string? value)
126+
{
127+
if (string.IsNullOrEmpty(value)) {
128+
FilteredMods = GetOrderedMods();
129+
return;
130+
}
131+
132+
FilteredMods = [..ProfileManager.Shared.Mods
133+
.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase) || value.Contains(x.Name, StringComparison.InvariantCultureIgnoreCase))
134+
.OrderBy(x => x.Name)
135+
];
136+
}
137+
138+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
139+
private static ObservableCollection<Mod> GetOrderedMods()
140+
{
141+
return [.. ProfileManager.Shared.Mods.OrderBy(x => x.Name)];
142+
}
116143
}

src/Tkmm/Views/Pages/ProfilesPageView.axaml

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -117,46 +117,52 @@
117117
Margin="25,0"
118118
Background="{DynamicResource SystemAccentColor}" />
119119

120-
<ListBox Name="MasterListBox"
121-
Grid.Column="2"
122-
Classes="ModDragDropListBox"
123-
DragDrop.AllowDrop="True"
124-
ItemsSource="{Binding Mods, Source={x:Static comp:ProfileManager.Shared}}"
125-
SelectedItem="{Binding MasterSelected}"
126-
SelectionMode="AlwaysSelected"
127-
ToolTip.Tip="All Mods">
128-
<ListBox.ItemTemplate>
129-
<DataTemplate DataType="{x:Type models:Mod}">
130-
<Grid ColumnDefinitions="*,Auto,Auto">
131-
<TextBlock VerticalAlignment="Center"
132-
Background="Transparent"
133-
Text="{Binding Name}"
134-
TextTrimming="CharacterEllipsis"
135-
ToolTip.Tip="{Binding Name}" />
136-
<Button Grid.Column="1"
137-
Width="25"
138-
Height="25"
139-
Padding="0"
140-
VerticalAlignment="Stretch"
141-
Command="{Binding AddToCurrentProfileCommand}"
142-
ToolTip.Tip="Add to current profile">
143-
<pi:Icon Value="fa-solid fa-plus" />
144-
</Button>
145-
<Button Grid.Column="2"
146-
Width="25"
147-
Height="25"
148-
Margin="5,0,0,0"
149-
Padding="0"
150-
VerticalAlignment="Stretch"
151-
x:CompileBindings="False"
152-
Command="{Binding $parent[UserControl].DataContext.UninstallCommand}"
153-
CommandParameter="{Binding}"
154-
ToolTip.Tip="Uninstall">
155-
<pi:Icon Value="fa-solid fa-trash-xmark" />
156-
</Button>
157-
</Grid>
158-
</DataTemplate>
159-
</ListBox.ItemTemplate>
160-
</ListBox>
120+
<Grid Grid.Column="2" RowDefinitions="Auto,*">
121+
<TextBox Margin="0,0,0,10"
122+
Classes="clearButton"
123+
Text="{Binding FilterArgument}"
124+
Watermark="Search" />
125+
<ListBox Name="MasterListBox"
126+
Grid.Row="1"
127+
Classes="ModDragDropListBox"
128+
DragDrop.AllowDrop="True"
129+
ItemsSource="{Binding FilteredMods}"
130+
SelectedItem="{Binding MasterSelected}"
131+
SelectionMode="AlwaysSelected"
132+
ToolTip.Tip="All Mods">
133+
<ListBox.ItemTemplate>
134+
<DataTemplate DataType="{x:Type models:Mod}">
135+
<Grid ColumnDefinitions="*,Auto,Auto">
136+
<TextBlock VerticalAlignment="Center"
137+
Background="Transparent"
138+
Text="{Binding Name}"
139+
TextTrimming="CharacterEllipsis"
140+
ToolTip.Tip="{Binding Name}" />
141+
<Button Grid.Column="1"
142+
Width="25"
143+
Height="25"
144+
Padding="0"
145+
VerticalAlignment="Stretch"
146+
Command="{Binding AddToCurrentProfileCommand}"
147+
ToolTip.Tip="Add to current profile">
148+
<pi:Icon Value="fa-solid fa-plus" />
149+
</Button>
150+
<Button Grid.Column="2"
151+
Width="25"
152+
Height="25"
153+
Margin="5,0,0,0"
154+
Padding="0"
155+
VerticalAlignment="Stretch"
156+
x:CompileBindings="False"
157+
Command="{Binding $parent[UserControl].DataContext.UninstallCommand}"
158+
CommandParameter="{Binding}"
159+
ToolTip.Tip="Uninstall">
160+
<pi:Icon Value="fa-solid fa-trash-xmark" />
161+
</Button>
162+
</Grid>
163+
</DataTemplate>
164+
</ListBox.ItemTemplate>
165+
</ListBox>
166+
</Grid>
161167
</Grid>
162168
</UserControl>

0 commit comments

Comments
 (0)