| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="RecentFilesOperations.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Threading; |
| | | 10 | | using System.Threading.Tasks; |
| | | 11 | | using MyNet.IO.FileHistory; |
| | | 12 | | |
| | | 13 | | namespace MyNet.UI.Services.FileHistory; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Wraps <see cref="IRecentFilesService"/> for UI scenarios and notifies subscribers when data changes. |
| | | 17 | | /// </summary> |
| | | 18 | | public sealed class RecentFilesOperations(IRecentFilesService recentFilesService) : IRecentFilesOperations |
| | | 19 | | { |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public event EventHandler? Changed; |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public Task<IReadOnlyList<RecentFile>> GetAllAsync(CancellationToken cancellationToken = default) => |
| | 0 | 25 | | recentFilesService.GetAllAsync(); |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public async Task<RecentFile?> AddAsync(string name, string path, bool isRecovered = false, CancellationToken cancel |
| | | 29 | | { |
| | | 30 | | _ = cancellationToken; |
| | 0 | 31 | | var result = await recentFilesService.AddAsync(name, path, isRecovered).ConfigureAwait(false); |
| | 0 | 32 | | NotifyChanged(); |
| | 0 | 33 | | return result; |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | | 37 | | public async Task<bool> RemoveAsync(string path, CancellationToken cancellationToken = default) |
| | | 38 | | { |
| | | 39 | | _ = cancellationToken; |
| | 0 | 40 | | var removed = await recentFilesService.RemoveAsync(path).ConfigureAwait(false); |
| | | 41 | | |
| | 0 | 42 | | if (removed) |
| | 0 | 43 | | NotifyChanged(); |
| | | 44 | | |
| | 0 | 45 | | return removed; |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <inheritdoc /> |
| | | 49 | | public async Task<RecentFile?> SetPinnedAsync(string path, bool isPinned, CancellationToken cancellationToken = defa |
| | | 50 | | { |
| | | 51 | | _ = cancellationToken; |
| | 0 | 52 | | var result = await recentFilesService.PinAsync(path, isPinned).ConfigureAwait(false); |
| | 0 | 53 | | NotifyChanged(); |
| | 0 | 54 | | return result; |
| | 0 | 55 | | } |
| | | 56 | | |
| | 0 | 57 | | private void NotifyChanged() => Changed?.Invoke(this, EventArgs.Empty); |
| | | 58 | | } |
| | | 59 | | |