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,17 +5,17 @@ namespace FileTime.App.Core.Services;
public class ClipboardService : IClipboardService
{
private List<IAbsolutePath> _content;
public IReadOnlyList<IAbsolutePath> Content { get; private set; }
private List<FullName> _content;
public IReadOnlyList<FullName> Content { get; private set; }
public Type? CommandType { get; private set; }
public ClipboardService()
{
_content = new List<IAbsolutePath>();
_content = new List<FullName>();
Content = _content.AsReadOnly();
}
public void AddContent(IAbsolutePath absolutePath)
public void AddContent(FullName absolutePath)
{
foreach (var content in _content)
{
@@ -25,7 +25,7 @@ public class ClipboardService : IClipboardService
_content.Add(absolutePath);
}
public void RemoveContent(IAbsolutePath absolutePath)
public void RemoveContent(FullName absolutePath)
{
for (var i = 0; i < _content.Count; i++)
{
@@ -38,7 +38,7 @@ public class ClipboardService : IClipboardService
public void Clear()
{
_content = new List<IAbsolutePath>();
_content = new List<FullName>();
Content = _content.AsReadOnly();
CommandType = null;
}

View File

@@ -4,8 +4,10 @@ using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Command;
using FileTime.Core.Command.CreateContainer;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
using Microsoft.Extensions.Logging;
using CopyCommand = FileTime.Core.Command.Copy.CopyCommand;
@@ -19,24 +21,30 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
private readonly IClipboardService _clipboardService;
private readonly IInputInterface _inputInterface;
private readonly ILogger<ItemManipulationUserCommandHandlerService> _logger;
private readonly BindedCollection<IAbsolutePath>? _markedItems;
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly BindedCollection<FullName>? _markedItems;
private PointInTime _currentPointInTime;
public ItemManipulationUserCommandHandlerService(
IAppState appState,
IUserCommandHandlerService userCommandHandlerService,
IClipboardService clipboardService,
IInputInterface inputInterface,
ILogger<ItemManipulationUserCommandHandlerService> logger) : base(appState)
ILogger<ItemManipulationUserCommandHandlerService> logger,
ITimelessContentProvider timelessContentProvider) : base(appState, timelessContentProvider)
{
_userCommandHandlerService = userCommandHandlerService;
_clipboardService = clipboardService;
_inputInterface = inputInterface;
_logger = logger;
_timelessContentProvider = timelessContentProvider;
_currentPointInTime = null!;
SaveSelectedTab(t => _selectedTab = t);
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
SaveCurrentPointInTime(t => _currentPointInTime = t);
_markedItems = new BindedCollection<IAbsolutePath>(appState.SelectedTab.Select(t => t?.MarkedItems));
_markedItems = new BindedCollection<FullName>(appState.SelectedTab.Select(t => t?.MarkedItems));
AddCommandHandlers(new IUserCommandHandler[]
{
@@ -51,7 +59,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
{
if (_selectedTab == null || _currentSelectedItem?.BaseItem?.FullName == null) return;
_selectedTab.ToggleMarkedItem(new AbsolutePath(_currentSelectedItem.BaseItem));
_selectedTab.ToggleMarkedItem(_currentSelectedItem.BaseItem.FullName);
await _userCommandHandlerService.HandleCommandAsync(MoveCursorDownCommand.Instance);
}
@@ -71,7 +79,8 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
}
else if (_currentSelectedItem?.BaseItem != null)
{
_clipboardService.AddContent(new AbsolutePath(_currentSelectedItem.BaseItem));
var item = _currentSelectedItem.BaseItem;
_clipboardService.AddContent(item.FullName ?? throw new ArgumentException($"{nameof(item.FullName)} can not be null.", nameof(item)));
}
return Task.CompletedTask;
@@ -114,8 +123,10 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
var containerNameInput = new TextInputElement("Container name");
await _inputInterface.ReadInputs(new List<IInputElement>() { containerNameInput });
//TODO: message on empty result
var newContainerName = containerNameInput.Value;
var command = new CreateContainerCommand();
}
}

View File

@@ -4,6 +4,7 @@ using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Models;
using FileTime.Core.Services;
using FileTime.Core.Timeline;
using FileTime.Providers.Local;
using Microsoft.Extensions.DependencyInjection;
@@ -15,6 +16,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
private readonly IServiceProvider _serviceProvider;
private readonly ILocalContentProvider _localContentProvider;
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly ITimelessContentProvider _timelessContentProvider;
private ITabViewModel? _selectedTab;
private IContainer? _currentLocation;
private IItemViewModel? _currentSelectedItem;
@@ -25,12 +27,14 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
IAppState appState,
IServiceProvider serviceProvider,
ILocalContentProvider localContentProvider,
IUserCommandHandlerService userCommandHandlerService) : base(appState)
IUserCommandHandlerService userCommandHandlerService,
ITimelessContentProvider timelessContentProvider) : base(appState)
{
_appState = appState;
_serviceProvider = serviceProvider;
_localContentProvider = localContentProvider;
_userCommandHandlerService = userCommandHandlerService;
_timelessContentProvider = timelessContentProvider;
SaveSelectedTab(t => _selectedTab = t);
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
@@ -71,7 +75,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
private async Task GoUp()
{
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsyncSafe() is not IContainer newContainer) return;
if (_currentLocation?.Parent is not AbsolutePath parentPath || await parentPath.ResolveAsyncSafe() is not IContainer newContainer) return;
_selectedTab?.Tab?.SetCurrentLocation(newContainer);
}
@@ -94,7 +98,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
var newSelectedItem = getNewSelected(_currentItems);
if (newSelectedItem == null) return;
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath());
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath(_timelessContentProvider));
}
private Task EnterRapidTravel()

View File

@@ -2,6 +2,7 @@ using System.Reactive.Linq;
using DynamicData;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
namespace FileTime.App.Core.Services.UserCommandHandler;
@@ -9,10 +10,14 @@ public abstract class UserCommandHandlerServiceBase : IUserCommandHandler
{
private readonly List<IUserCommandHandler> _userCommandHandlers = new();
private readonly IAppState? _appState;
private readonly ITimelessContentProvider? _timelessContentProvider;
protected UserCommandHandlerServiceBase(IAppState? appState = null)
protected UserCommandHandlerServiceBase(
IAppState? appState = null,
ITimelessContentProvider? timelessContentProvider = null)
{
_appState = appState;
_timelessContentProvider = timelessContentProvider;
}
public bool CanHandleCommand(UserCommand.IUserCommand command) => _userCommandHandlers.Any(h => h.CanHandleCommand(command));
@@ -48,13 +53,23 @@ public abstract class UserCommandHandlerServiceBase : IUserCommandHandler
protected IDisposable SaveCurrentItems(Action<IEnumerable<IItemViewModel>> handler)
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t?.CurrentItemsCollectionObservable ?? Observable.Return((IEnumerable<IItemViewModel>?) Enumerable.Empty<IItemViewModel>())).Switch().Subscribe(i => handler(i ?? Enumerable.Empty<IItemViewModel>())));
protected IDisposable SaveMarkedItems(Action<IChangeSet<IAbsolutePath>> handler)
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t == null ? Observable.Empty<IChangeSet<IAbsolutePath>>() : t.MarkedItems).Switch().Subscribe(handler));
protected IDisposable SaveMarkedItems(Action<IChangeSet<FullName>> handler)
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t == null ? Observable.Empty<IChangeSet<FullName>>() : t.MarkedItems).Switch().Subscribe(handler));
protected IDisposable SaveCurrentPointInTime(Action<PointInTime> handler)
=> RunWithTimelessContentProvider(timelessContentProvider => timelessContentProvider.CurrentPointInTime.Subscribe(handler));
private IDisposable RunWithAppState(Func<IAppState, IDisposable> act)
{
if (_appState == null) throw new NullReferenceException($"AppState is nit initialized in {nameof(UserCommandHandlerServiceBase)}.");
if (_appState == null) throw new NullReferenceException($"AppState is not initialized in {nameof(UserCommandHandlerServiceBase)}.");
return act(_appState);
}
private IDisposable RunWithTimelessContentProvider(Func<ITimelessContentProvider, IDisposable> act)
{
if (_timelessContentProvider == null) throw new NullReferenceException($"TimelessContainer is not initialized in {nameof(UserCommandHandlerServiceBase)}.");
return act(_timelessContentProvider);
}
}