Skip to content

Commit

Permalink
feat(ui): search clips by name
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd committed Jul 11, 2024
1 parent 4653b2d commit a5d4907
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
<StackPanel
Width="225"
DockPanel.Dock="Left">
<TextBox Margin="8" Watermark="Search" />
<TextBox Margin="8" Watermark="Search" Text="{Binding SearchText}" />
<ListBox
ItemsSource="{Binding FileMakerClips}"
ItemsSource="{Binding FilteredClips}"
SelectedItem="{Binding SelectedClip}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
Expand Down
20 changes: 20 additions & 0 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
public MainWindowViewModel(ILogger logger)
{
_logger = logger;

// default to the local app data folder + \SharpFM, otherwise use provided path
_currentPath ??= Path.Join(
path1: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
path2: Path.Join("SharpFM", "Clips")
);

FileMakerClips = [];
FilteredClips = [];

LoadClips(CurrentPath);
}
Expand Down Expand Up @@ -233,6 +235,8 @@ public static string Version

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

public ObservableCollection<ClipViewModel> FilteredClips { get; set; }

private ClipViewModel? _selectedClip;
public ClipViewModel? SelectedClip
{
Expand All @@ -244,6 +248,22 @@ public ClipViewModel? SelectedClip
}
}

private string _searchText = string.Empty;
public string SearchText
{
get => _searchText;
set
{
_searchText = value;
FilteredClips.Clear();
foreach (var c in FileMakerClips.Where(c => c.Name.Contains(_searchText)))
{
FilteredClips.Add(c);
}
NotifyPropertyChanged();
}
}

private string _currentPath;
public string CurrentPath
{
Expand Down

0 comments on commit a5d4907

Please sign in to comment.