ContentAccess, CreateContainer

This commit is contained in:
2022-05-24 09:19:57 +02:00
parent 4ac99480fa
commit 60ab7f94ea
12 changed files with 209 additions and 62 deletions

View File

@@ -8,6 +8,7 @@ using FileTime.Core.Command.CreateContainer;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
using InitableService;
using Microsoft.Extensions.Logging;
using CopyCommand = FileTime.Core.Command.Copy.CopyCommand;
@@ -21,10 +22,9 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
private readonly IClipboardService _clipboardService;
private readonly IInputInterface _inputInterface;
private readonly ILogger<ItemManipulationUserCommandHandlerService> _logger;
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandScheduler _commandScheduler;
private readonly IServiceProvider _serviceProvider;
private readonly BindedCollection<FullName>? _markedItems;
private PointInTime _currentPointInTime;
private IContainer? _currentLocation;
public ItemManipulationUserCommandHandlerService(
@@ -34,20 +34,19 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
IInputInterface inputInterface,
ILogger<ItemManipulationUserCommandHandlerService> logger,
ITimelessContentProvider timelessContentProvider,
ICommandScheduler commandScheduler) : base(appState, timelessContentProvider)
ICommandScheduler commandScheduler,
IServiceProvider serviceProvider) : base(appState, timelessContentProvider)
{
_userCommandHandlerService = userCommandHandlerService;
_clipboardService = clipboardService;
_inputInterface = inputInterface;
_logger = logger;
_timelessContentProvider = timelessContentProvider;
_commandScheduler = commandScheduler;
_currentPointInTime = null!;
_serviceProvider = serviceProvider;
SaveSelectedTab(t => _selectedTab = t);
SaveCurrentLocation(l => _currentLocation = l);
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
SaveCurrentPointInTime(t => _currentPointInTime = t);
_markedItems = new BindedCollection<FullName>(appState.SelectedTab.Select(t => t?.MarkedItems));
@@ -85,7 +84,9 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
else if (_currentSelectedItem?.BaseItem != null)
{
var item = _currentSelectedItem.BaseItem;
_clipboardService.AddContent(item.FullName ?? throw new ArgumentException($"{nameof(item.FullName)} can not be null.", nameof(item)));
_clipboardService.AddContent(item.FullName ??
throw new ArgumentException($"{nameof(item.FullName)} can not be null.",
nameof(item)));
}
return Task.CompletedTask;
@@ -134,7 +135,9 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
if (_currentLocation?.FullName is null || newContainerName is null) return;
var command = new CreateContainerCommand(_currentLocation.FullName, newContainerName, _timelessContentProvider);
var command = _serviceProvider
.GetInitableResolver<FullName, string>(_currentLocation.FullName, newContainerName)
.GetRequiredService<CreateContainerCommand>();
await _commandScheduler.AddCommand(command);
}
}

View File

@@ -4,6 +4,7 @@ using FileTime.App.Core.StartupServices;
using FileTime.App.Core.ViewModels;
using FileTime.App.Core.ViewModels.ItemPreview;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace FileTime.App.Core;
@@ -11,20 +12,19 @@ public static class Startup
{
public static IServiceCollection AddCoreAppServices(this IServiceCollection serviceCollection)
{
return serviceCollection
.AddTransient<ITabViewModel, TabViewModel>()
.AddTransient<IContainerViewModel, ContainerViewModel>()
.AddTransient<IElementViewModel, ElementViewModel>()
.AddTransient<IFileViewModel, FileViewModel>()
.AddTransient<IContainerSizeContainerViewModel, ContainerSizeContainerViewModel>()
.AddTransient<IItemNameConverterService, ItemNameConverterService>()
.AddTransient<ElementPreviewViewModel>()
.AddSingleton<IUserCommandHandlerService, UserCommandHandlerService>()
.AddSingleton<IClipboardService, ClipboardService>()
.AddSingleton<IIdentifiableUserCommandService, IdentifiableUserCommandService>()
.AddSingleton<IStartupHandler, DefaultIdentifiableCommandHandlerRegister>()
.AddSingleton<IItemPreviewService, ItemPreviewService>()
.AddCommandHandlers();
serviceCollection.TryAddTransient<ITabViewModel, TabViewModel>();
serviceCollection.TryAddTransient<IContainerViewModel, ContainerViewModel>();
serviceCollection.TryAddTransient<IElementViewModel, ElementViewModel>();
serviceCollection.TryAddTransient<IFileViewModel, FileViewModel>();
serviceCollection.TryAddTransient<IContainerSizeContainerViewModel, ContainerSizeContainerViewModel>();
serviceCollection.TryAddTransient<IItemNameConverterService, ItemNameConverterService>();
serviceCollection.TryAddTransient<ElementPreviewViewModel>();
serviceCollection.TryAddSingleton<IUserCommandHandlerService, UserCommandHandlerService>();
serviceCollection.TryAddSingleton<IClipboardService, ClipboardService>();
serviceCollection.TryAddSingleton<IIdentifiableUserCommandService, IdentifiableUserCommandService>();
serviceCollection.TryAddSingleton<IStartupHandler, DefaultIdentifiableCommandHandlerRegister>();
serviceCollection.TryAddSingleton<IItemPreviewService, ItemPreviewService>();
return serviceCollection.AddCommandHandlers();
}
private static IServiceCollection AddCommandHandlers(this IServiceCollection serviceCollection)

View File

@@ -1,10 +1,12 @@
using FileTime.App.Core;
using FileTime.Core.Command;
using FileTime.Core.Command.CreateContainer;
using FileTime.Core.ContentAccess;
using FileTime.Core.Services;
using FileTime.Core.Timeline;
using FileTime.Providers.Local;
using Microsoft.Extensions.DependencyInjection;
using ICommandExecutor = FileTime.Core.Timeline.ICommandExecutor;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace FileTime.App.DependencyInjection;
@@ -14,13 +16,21 @@ public static class DependencyInjection
{
serviceCollection ??= new ServiceCollection();
serviceCollection.TryAddSingleton<ICommandScheduler, CommandScheduler>();
serviceCollection.TryAddSingleton<ITimelessContentProvider, TimelessContentProvider>();
serviceCollection.TryAddSingleton<ICommandRunner, CommandRunner>();
serviceCollection.TryAddSingleton<IContentAccessorFactory, ContentAccessorFactory>();
serviceCollection.TryAddSingleton<ITab, Tab>();
serviceCollection.TryAddSingleton<ILocalCommandExecutor, LocalCommandExecutor>();
return serviceCollection
.AddSingleton<ICommandScheduler, CommandScheduler>()
.AddSingleton<ITimelessContentProvider, TimelessContentProvider>()
.AddSingleton<ICommandRunner, CommandRunner>()
.AddTransient<ITab, Tab>()
.AddTransient<ILocalCommandExecutor, LocalCommandExecutor>()
.AddCoreAppServices()
.AddLocalServices();
.AddLocalServices()
.RegisterCommands();
}
public static IServiceCollection RegisterCommands(this IServiceCollection serviceCollection)
{
return serviceCollection.AddTransient<CreateContainerCommand>();
}
}