| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="RecentFilesListOptions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using MyNet.UI.ViewModels.List.Filtering; |
| | | 8 | | using MyNet.UI.ViewModels.List.Filtering.Filters; |
| | | 9 | | using MyNet.UI.ViewModels.List.Sorting; |
| | | 10 | | |
| | | 11 | | namespace MyNet.UI.ViewModels.FileHistory; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// List configuration for recent files. |
| | | 15 | | /// </summary> |
| | | 16 | | internal sealed class RecentFilesListOptions( |
| | | 17 | | FiltersViewModel<RecentFileViewModel> filters, |
| | | 18 | | StringFilterViewModel<RecentFileViewModel> nameFilter, |
| | | 19 | | StringFilterViewModel<RecentFileViewModel> pathFilter, |
| | | 20 | | ISortingViewModel<RecentFileViewModel> sorting) |
| | | 21 | | { |
| | | 22 | | /// <summary> |
| | | 23 | | /// Creates filtering and sorting view models for <see cref="RecentFilesViewModel"/>. |
| | | 24 | | /// </summary> |
| | | 25 | | public static RecentFilesListOptions Create() |
| | | 26 | | { |
| | 0 | 27 | | StringFilterViewModel<RecentFileViewModel>? nameFilter = null; |
| | 0 | 28 | | StringFilterViewModel<RecentFileViewModel>? pathFilter = null; |
| | | 29 | | |
| | 0 | 30 | | var filters = FiltersViewModelBuilder<RecentFileViewModel>.Create(builder => |
| | 0 | 31 | | { |
| | 0 | 32 | | builder.OrGroup(search => |
| | 0 | 33 | | { |
| | 0 | 34 | | search.AddStringFilter( |
| | 0 | 35 | | nameof(RecentFileViewModel.DisplayName), |
| | 0 | 36 | | x => x.DisplayName, |
| | 0 | 37 | | filter => nameFilter = filter); |
| | 0 | 38 | | |
| | 0 | 39 | | search.AddStringFilter( |
| | 0 | 40 | | nameof(RecentFileViewModel.Path), |
| | 0 | 41 | | x => x.Path, |
| | 0 | 42 | | filter => pathFilter = filter); |
| | 0 | 43 | | }); |
| | 0 | 44 | | }); |
| | | 45 | | |
| | 0 | 46 | | var sorting = SortingViewModelBuilder<RecentFileViewModel>.Create(builder => |
| | 0 | 47 | | { |
| | 0 | 48 | | builder.AddProperty( |
| | 0 | 49 | | x => x.DisplayName, |
| | 0 | 50 | | property => property |
| | 0 | 51 | | .WithDisplayName(nameof(RecentFileViewModel.DisplayName)) |
| | 0 | 52 | | .Ascending()); |
| | 0 | 53 | | |
| | 0 | 54 | | builder.AddProperty( |
| | 0 | 55 | | x => x.LastAccessDate, |
| | 0 | 56 | | property => property |
| | 0 | 57 | | .WithDisplayName(nameof(RecentFileViewModel.LastAccessDate)) |
| | 0 | 58 | | .Descending()); |
| | 0 | 59 | | }); |
| | | 60 | | |
| | 0 | 61 | | return new(filters, nameFilter!, pathFilter!, sorting); |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | public FiltersViewModel<RecentFileViewModel> Filters { get; } = filters; |
| | | 65 | | |
| | | 66 | | public StringFilterViewModel<RecentFileViewModel> NameFilter { get; } = nameFilter; |
| | | 67 | | |
| | | 68 | | public StringFilterViewModel<RecentFileViewModel> PathFilter { get; } = pathFilter; |
| | | 69 | | |
| | | 70 | | public ISortingViewModel<RecentFileViewModel> Sorting { get; } = sorting; |
| | | 71 | | |
| | | 72 | | /// <summary> |
| | | 73 | | /// Updates the shared search text applied to name and path filters. |
| | | 74 | | /// </summary> |
| | | 75 | | public void SetSearchText(string? value) |
| | | 76 | | { |
| | 0 | 77 | | NameFilter.Value = value; |
| | 0 | 78 | | PathFilter.Value = value; |
| | 0 | 79 | | Filters.Apply(); |
| | 0 | 80 | | } |
| | | 81 | | } |
| | | 82 | | |