Compression

This commit is contained in:
2023-08-02 12:40:40 +02:00
parent 5508828717
commit c95be170ed
34 changed files with 505 additions and 66 deletions

View File

@@ -10,7 +10,7 @@ public class CommandSchedulerUserCommandHandlerService : UserCommandHandlerServi
public CommandSchedulerUserCommandHandlerService(ICommandScheduler commandScheduler)
{
_commandScheduler = commandScheduler;
AddCommandHandlers(new IUserCommandHandler[]
AddCommandHandler(new IUserCommandHandler[]
{
new TypeUserCommandHandler<PauseCommandSchedulerCommand>(PauseCommandScheduler),
new TypeUserCommandHandler<StartCommandSchedulerCommand>(StartCommandScheduler),

View File

@@ -12,8 +12,8 @@ public class IdentifiableUserCommandService : IIdentifiableUserCommandService
IdentifiableUserCommands = _identifiableUserCommands.AsReadOnly();
}
public void AddIdentifiableUserCommandFactory(string identifier, IIdentifiableUserCommand commandFactory)
=> _identifiableUserCommands.Add(identifier, commandFactory);
public void AddIdentifiableUserCommand(IIdentifiableUserCommand command)
=> _identifiableUserCommands.Add(command.UserCommandID, command);
public IIdentifiableUserCommand? GetCommand(string identifier)
{

View File

@@ -62,7 +62,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
_markedItems = appState.SelectedTab.Map(t => t?.MarkedItems).Switch();
AddCommandHandlers(new IUserCommandHandler[]
AddCommandHandler(new IUserCommandHandler[]
{
new TypeUserCommandHandler<CopyCommand>(CopyAsync),
new TypeUserCommandHandler<DeleteCommand>(DeleteAsync),

View File

@@ -59,7 +59,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
appState.ViewMode.Subscribe(v => _viewMode = v);
AddCommandHandlers(new IUserCommandHandler[]
AddCommandHandler(new IUserCommandHandler[]
{
new TypeUserCommandHandler<CloseTabCommand>(CloseTab),
new TypeUserCommandHandler<EnterRapidTravelCommand>(EnterRapidTravel),

View File

@@ -45,7 +45,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
SaveSelectedTab(t => _currentSelectedTab = t);
AddCommandHandlers(new IUserCommandHandler[]
AddCommandHandler(new IUserCommandHandler[]
{
new TypeUserCommandHandler<OpenInDefaultFileExplorerCommand>(OpenInDefaultFileExplorer),
new TypeUserCommandHandler<CopyNativePathCommand>(CopyNativePath),

View File

@@ -1,26 +0,0 @@
using FileTime.App.Core.UserCommand;
namespace FileTime.App.Core.Services.UserCommandHandler;
public class TypeUserCommandHandler<T> : IUserCommandHandler where T : IUserCommand
{
private readonly Func<T, Task> _handler;
public TypeUserCommandHandler(Func<T, Task> handler)
{
_handler = handler;
}
public TypeUserCommandHandler(Func<Task> handler)
{
_handler = async (_) => await handler();
}
public bool CanHandleCommand(IUserCommand command) => command is T;
public Task HandleCommandAsync(IUserCommand command)
{
if (command is not T typedCommand) throw new ArgumentException($"Parameter '{nameof(command)}' is not of type '{typeof(T).Name}'");
return _handler(typedCommand);
}
}

View File

@@ -1,16 +0,0 @@
namespace FileTime.App.Core.Services.UserCommandHandler;
public sealed class UserCommandHandler : IUserCommandHandler
{
private readonly Func<UserCommand.IUserCommand, bool> _canHandle;
private readonly Func<UserCommand.IUserCommand, Task> _handle;
public UserCommandHandler(Func<UserCommand.IUserCommand, bool> canHandle, Func<UserCommand.IUserCommand, Task> handle)
{
_canHandle = canHandle;
_handle = handle;
}
public bool CanHandleCommand(UserCommand.IUserCommand command) => _canHandle(command);
public async Task HandleCommandAsync(UserCommand.IUserCommand command) => await _handle(command);
}

View File

@@ -8,9 +8,8 @@ using FileTime.Core.Timeline;
namespace FileTime.App.Core.Services.UserCommandHandler;
public abstract class UserCommandHandlerServiceBase : IUserCommandHandler
public abstract class UserCommandHandlerServiceBase : AggregatedUserCommandHandler
{
private readonly List<IUserCommandHandler> _userCommandHandlers = new();
private readonly IAppState? _appState;
private readonly ITimelessContentProvider? _timelessContentProvider;
@@ -22,28 +21,6 @@ public abstract class UserCommandHandlerServiceBase : IUserCommandHandler
_timelessContentProvider = timelessContentProvider;
}
public bool CanHandleCommand(UserCommand.IUserCommand command) => _userCommandHandlers.Any(h => h.CanHandleCommand(command));
public async Task HandleCommandAsync(UserCommand.IUserCommand command)
{
var handler = _userCommandHandlers.Find(h => h.CanHandleCommand(command));
if (handler is null) return;
await handler.HandleCommandAsync(command);
}
protected void AddCommandHandler(IUserCommandHandler userCommandHandler) => _userCommandHandlers.Add(userCommandHandler);
protected void AddCommandHandlers(IEnumerable<IUserCommandHandler> commandHandlers)
{
foreach (var userCommandHandler in commandHandlers)
{
AddCommandHandler(userCommandHandler);
}
}
protected void RemoveCommandHandler(IUserCommandHandler userCommandHandler) => _userCommandHandlers.Remove(userCommandHandler);
protected IDisposable SaveSelectedTab(Action<ITabViewModel?> handler) => RunWithAppState(appState => appState.SelectedTab.Subscribe(handler));
protected IDisposable SaveCurrentSelectedItem(Action<IDeclarativeProperty<IItemViewModel?>?> handler)