Copy file to clipboard

This commit is contained in:
2023-07-06 22:38:14 +02:00
parent 5c716d5c28
commit ed5d5806ae
10 changed files with 117 additions and 30 deletions

View File

@@ -18,6 +18,7 @@ using FileTime.Core.Timeline;
using InitableService;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using CreateElementCommand = FileTime.App.Core.UserCommand.CreateElementCommand;
namespace FileTime.App.Core.Services.UserCommandHandler;
@@ -70,11 +71,30 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
new TypeUserCommandHandler<MarkCommand>(MarkItemAsync),
new TypeUserCommandHandler<PasteCommand>(PasteAsync),
new TypeUserCommandHandler<CreateContainer>(CreateContainerAsync),
new TypeUserCommandHandler<CreateElement>(CreateElementAsync),
new TypeUserCommandHandler<CreateElementCommand>(CreateElementAsync),
new TypeUserCommandHandler<PasteFilesFromClipboardCommand>(PasteFilesFromClipboardAsync),
new TypeUserCommandHandler<CopyFilesToClipboardCommand>(CopyFilesToClipboardAsync),
});
}
private async Task CopyFilesToClipboardAsync()
{
var list = new List<FullName>();
if ((_markedItems?.Collection?.Count ?? 0) > 0)
{
list.AddRange(_markedItems!.Collection!);
}
else if(_currentSelectedItem?.BaseItem?.FullName is { } selectedItemName)
{
list.Add(selectedItemName);
}
if (list.Count > 0)
{
await _systemClipboardService.SetFilesAsync(list);
}
}
private async Task PasteFilesFromClipboardAsync(PasteFilesFromClipboardCommand command) =>
await (command.PasteMode switch
{
@@ -88,7 +108,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
{
if (_currentLocation?.FullName is not { }) return;
var files = (await _systemClipboardService.GetFiles()).ToList();
var files = (await _systemClipboardService.GetFilesAsync()).ToList();
var copyCommandFactory = _serviceProvider.GetRequiredService<FileTime.Core.Command.Copy.CopyCommandFactory>();
var copyCommand = copyCommandFactory.GenerateCommand(files, mode, _currentLocation.FullName);
@@ -187,7 +207,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
var command = _serviceProvider
.GetInitableResolver(_currentLocation.FullName, newContainerName)
.GetRequiredService<CreateElementCommand>();
.GetRequiredService<FileTime.Core.Command.CreateElement.CreateElementCommand>();
await AddCommandAsync(command);
}

View File

@@ -14,9 +14,10 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
AddUserCommand(CloseTabCommand.Instance);
AddUserCommand(CopyCommand.Instance);
AddUserCommand(CopyBase64Command.Instance);
AddUserCommand(CopyFilesToClipboardCommand.Instance);
AddUserCommand(CopyNativePathCommand.Instance);
AddUserCommand(CreateContainer.Instance);
AddUserCommand(CreateElement.Instance);
AddUserCommand(CreateElementCommand.Instance);
AddUserCommand(DeleteCommand.HardDelete);
AddUserCommand(DeleteCommand.SoftDelete);
AddUserCommand(EnterRapidTravelCommand.Instance);