Skip to content

Commit cce95cb

Browse files
committed
feat(ui): search clips by name
1 parent b49cb40 commit cce95cb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

MainWindow.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
<StackPanel
6565
Width="225"
6666
DockPanel.Dock="Left">
67-
<TextBox Margin="8" Watermark="Search" />
67+
<TextBox Margin="8" Watermark="Search" Text="{Binding SearchText}" />
6868
<ListBox
69-
ItemsSource="{Binding FileMakerClips}"
69+
ItemsSource="{Binding FilteredClips}"
7070
SelectedItem="{Binding SelectedClip}">
7171
<ListBox.Styles>
7272
<Style Selector="ListBoxItem">

ViewModels/MainWindowViewModel.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
2929
public MainWindowViewModel(ILogger logger)
3030
{
3131
_logger = logger;
32+
3233
// default to the local app data folder + \SharpFM, otherwise use provided path
3334
_currentPath ??= Path.Join(
3435
path1: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
3536
path2: Path.Join("SharpFM", "Clips")
3637
);
3738

3839
FileMakerClips = [];
40+
FilteredClips = [];
3941

4042
LoadClips(CurrentPath);
4143
}
@@ -233,6 +235,8 @@ public static string Version
233235

234236
public ObservableCollection<ClipViewModel> FileMakerClips { get; set; }
235237

238+
public ObservableCollection<ClipViewModel> FilteredClips { get; set; }
239+
236240
private ClipViewModel? _selectedClip;
237241
public ClipViewModel? SelectedClip
238242
{
@@ -244,6 +248,22 @@ public ClipViewModel? SelectedClip
244248
}
245249
}
246250

251+
private string _searchText = string.Empty;
252+
public string SearchText
253+
{
254+
get => _searchText;
255+
set
256+
{
257+
_searchText = value;
258+
FilteredClips.Clear();
259+
foreach (var c in FileMakerClips.Where(c => c.Name.Contains(_searchText)))
260+
{
261+
FilteredClips.Add(c);
262+
}
263+
NotifyPropertyChanged();
264+
}
265+
}
266+
247267
private string _currentPath;
248268
public string CurrentPath
249269
{

0 commit comments

Comments
 (0)