Timeless refactor

This commit is contained in:
2022-05-21 14:30:24 +02:00
parent ced0c88a10
commit 6ee5afa632
47 changed files with 571 additions and 181 deletions

View File

@@ -5,6 +5,7 @@ using DynamicData.Binding;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
using FileTime.GuiApp.ViewModels;
using FileTime.Providers.Local;
using IContainer = FileTime.Core.Models.IContainer;
@@ -14,14 +15,14 @@ namespace FileTime.GuiApp.Services;
public class RootDriveInfoService : IStartupHandler
{
private readonly SourceList<DriveInfo> _rootDrives = new();
private readonly IObservable<IChangeSet<IAbsolutePath>> _localContentProviderStream;
private readonly IObservable<IChangeSet<AbsolutePath>> _localContentProviderStream;
public RootDriveInfoService(IGuiAppState guiAppState, ILocalContentProvider localContentProvider)
public RootDriveInfoService(IGuiAppState guiAppState, ILocalContentProvider localContentProvider, ITimelessContentProvider timelessContentProvider)
{
InitRootDrives();
var localContentProviderAsList = new SourceList<IAbsolutePath>();
localContentProviderAsList.Add(new AbsolutePath(localContentProvider));
var localContentProviderAsList = new SourceList<AbsolutePath>();
localContentProviderAsList.Add(new AbsolutePath(timelessContentProvider, localContentProvider));
_localContentProviderStream = localContentProviderAsList.Connect();
var rootDriveInfos = Observable.CombineLatest(
@@ -30,7 +31,7 @@ public class RootDriveInfoService : IStartupHandler
(items, drives) =>
{
return items is null
? Observable.Empty<IChangeSet<(IAbsolutePath Path, DriveInfo? Drive)>>()
? Observable.Empty<IChangeSet<(AbsolutePath Path, DriveInfo? Drive)>>()
: items!
.Or(new[] { _localContentProviderStream })
.Transform(i => (Path: i, Drive: drives.FirstOrDefault(d =>

View File

@@ -1,9 +1,11 @@
using System.Reflection;
using Avalonia.Input;
using FileTime.App.Core.Services;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Models;
using FileTime.Core.Services;
using FileTime.Core.Timeline;
using FileTime.GuiApp.Services;
using FileTime.Providers.Local;
using Microsoft.Extensions.DependencyInjection;
@@ -22,6 +24,7 @@ namespace FileTime.GuiApp.ViewModels;
[Inject(typeof(LifecycleService), PropertyName = "_lifecycleService")]
[Inject(typeof(IItemPreviewService), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(IDialogService), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(ITimelessContentProvider), PropertyName = "_timelessContentProvider")]
public partial class MainWindowViewModel : IMainWindowViewModelBase
{
public bool Loading => false;
@@ -42,12 +45,14 @@ public partial class MainWindowViewModel : IMainWindowViewModelBase
versionString += $" ({version.Revision})";
}
}
Title = "FileTime " + versionString;
//TODO: refactor
if (AppState.Tabs.Count == 0)
{
var tab = _serviceProvider.GetInitableResolver<IContainer>(_localContentProvider).GetRequiredService<ITab>();
var tab = _serviceProvider.GetInitableResolver<IContainer>(_localContentProvider)
.GetRequiredService<ITab>();
var tabViewModel = _serviceProvider.GetInitableResolver(tab, 1).GetRequiredService<ITabViewModel>();
_appState.AddTab(tabViewModel);
@@ -58,4 +63,12 @@ public partial class MainWindowViewModel : IMainWindowViewModelBase
{
_keyInputHandlerService.ProcessKeyDown(key, keyModifiers, setHandled);
}
public async Task OpenContainerByFullName(FullName fullName)
{
var resolvedItem = await _timelessContentProvider.GetItemByFullNameAsync(fullName, PointInTime.Present);
if (resolvedItem is not IContainer resolvedContainer) return;
await UserCommandHandlerService.HandleCommandAsync(
new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, resolvedContainer)));
}
}

View File

@@ -74,12 +74,12 @@ public partial class MainWindow : Window
&& e.GetCurrentPoint(this).Properties.IsLeftButtonPressed
&& sender is StyledElement control)
{
IAbsolutePath? path = null;
if (control.DataContext is IHaveAbsolutePath { Path: { } } haveAbsolutePath)
FullName? path = null;
if (control.DataContext is IHaveFullPath { Path: { } } hasFullPath)
{
path = haveAbsolutePath.Path;
path = hasFullPath.Path;
}
else if (control.DataContext is IAbsolutePath p)
else if (control.DataContext is FullName p)
{
path = p;
}
@@ -97,10 +97,7 @@ public partial class MainWindow : Window
if (path is null) return;
var resolvedItem = await path.ResolveAsync();
if (resolvedItem is not IContainer resolvedContainer) return;
await ViewModel.UserCommandHandlerService.HandleCommandAsync(
new OpenContainerCommand(new AbsolutePath(resolvedContainer)));
await ViewModel.OpenContainerByFullName(path);
e.Handled = true;
}
}