diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs index 3eea27e..c593da0 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs @@ -12,4 +12,5 @@ public interface IGuiAppState : IAppState string? MessageBoxText { get; set; } List PossibleCommands { get; set; } BindedCollection RootDriveInfos { get; set; } + IReadOnlyList Places { get; set; } } \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/PlaceInfo.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/PlaceInfo.cs new file mode 100644 index 0000000..b6ebe36 --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/PlaceInfo.cs @@ -0,0 +1,20 @@ +using FileTime.Core.Models; +using FileTime.GuiApp.Models; + +namespace FileTime.GuiApp.ViewModels; + +public class PlaceInfo : IHaveFullPath +{ + public IContainer Container { get; } + public string DisplayName { get; } + + public PlaceInfo(IContainer container, string displayName) + { + if (container.FullName is null) throw new ArgumentNullException($"{nameof(container.FullName)} of container can not be null"); + + Container = container; + DisplayName = displayName; + } + + public FullName Path => Container.FullName!; +} \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs index d8168a5..60e76df 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs @@ -43,7 +43,8 @@ public static class Startup serviceCollection.TryAddSingleton(s => s.GetRequiredService()); return serviceCollection - .AddSingleton(); + .AddSingleton() + .AddSingleton(); } internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection) diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs index 175a048..4ed07a6 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs @@ -19,5 +19,7 @@ public partial class GuiAppState : AppStateBase, IGuiAppState [Property] private BindedCollection _rootDriveInfos = new(); + [Property] private IReadOnlyList _places; + public List PreviousKeys { get; } = new(); } \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/PlacesService.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/PlacesService.cs new file mode 100644 index 0000000..9ff7e82 --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/PlacesService.cs @@ -0,0 +1,52 @@ +using System.Runtime.InteropServices; +using FileTime.App.Core.Services; +using FileTime.Core.Models; +using FileTime.Core.Timeline; +using FileTime.GuiApp.ViewModels; +using FileTime.Providers.Local; +using Syroot.Windows.IO; + +namespace FileTime.GuiApp.Services; + +public class PlacesService : IStartupHandler +{ + private readonly ILocalContentProvider _localContentProvider; + private readonly IGuiAppState _guiAppState; + + public PlacesService( + ILocalContentProvider localContentProvider, + IGuiAppState guiAppState) + { + _localContentProvider = localContentProvider; + _guiAppState = guiAppState; + } + + public async Task InitAsync() + { + var places = new List(); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var placesFolders = new List() + { + KnownFolders.Profile, + KnownFolders.Desktop, + KnownFolders.DocumentsLocalized, + KnownFolders.DownloadsLocalized, + KnownFolders.Music, + KnownFolders.Pictures, + KnownFolders.Videos, + }; + + foreach (var placesFolder in placesFolders) + { + var possibleContainer = await _localContentProvider.GetItemByNativePathAsync(new NativePath(placesFolder.Path), PointInTime.Present); + if (possibleContainer is not IContainer container) continue; + + + places.Add(new PlaceInfo(container, placesFolder.DisplayName)); + } + } + + _guiAppState.Places = places.AsReadOnly(); + } +} \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/RootDriveInfoService.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/RootDriveInfoService.cs index 7debc60..ea0e780 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/RootDriveInfoService.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/RootDriveInfoService.cs @@ -8,23 +8,23 @@ using FileTime.Core.Models; using FileTime.Core.Timeline; using FileTime.GuiApp.ViewModels; using FileTime.Providers.Local; -using IContainer = FileTime.Core.Models.IContainer; namespace FileTime.GuiApp.Services; public class RootDriveInfoService : IStartupHandler { private readonly SourceList _rootDrives = new(); - private readonly IObservable> _localContentProviderStream; - public RootDriveInfoService(IGuiAppState guiAppState, ILocalContentProvider localContentProvider, + public RootDriveInfoService( + IGuiAppState guiAppState, + ILocalContentProvider localContentProvider, ITimelessContentProvider timelessContentProvider) { InitRootDrives(); var localContentProviderAsList = new SourceCache(i => i.Path.Path); localContentProviderAsList.AddOrUpdate(new AbsolutePath(timelessContentProvider, localContentProvider)); - _localContentProviderStream = localContentProviderAsList.Connect(); + var localContentProviderStream = localContentProviderAsList.Connect(); var rootDriveInfos = Observable.CombineLatest( localContentProvider.Items, @@ -34,7 +34,7 @@ public class RootDriveInfoService : IStartupHandler return items is null ? Observable.Empty>() : items! - .Or(new[] { _localContentProviderStream }) + .Or(new[] { localContentProviderStream }) .Transform(i => (Path: i, Drive: drives.FirstOrDefault(d => { var containerPath = localContentProvider.GetNativePath(i.Path).Path; diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml index f0b4d09..a979ef9 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml @@ -140,39 +140,39 @@ -