Copy file to clipboard
This commit is contained in:
@@ -5,5 +5,6 @@ namespace FileTime.App.Core.Services;
|
||||
public interface ISystemClipboardService
|
||||
{
|
||||
Task CopyToClipboardAsync(string text);
|
||||
Task<IEnumerable<FullName>> GetFiles();
|
||||
Task<IEnumerable<FullName>> GetFilesAsync();
|
||||
Task SetFilesAsync(IEnumerable<FullName> files);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace FileTime.App.Core.UserCommand;
|
||||
|
||||
public class CopyFilesToClipboardCommand : IIdentifiableUserCommand
|
||||
{
|
||||
public const string CommandName = "copy_to_clipboard";
|
||||
|
||||
public static readonly CopyFilesToClipboardCommand Instance = new();
|
||||
|
||||
private CopyFilesToClipboardCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public string UserCommandID => CommandName;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace FileTime.App.Core.UserCommand;
|
||||
|
||||
public sealed class CreateElement : IIdentifiableUserCommand
|
||||
{
|
||||
public const string CommandName = "create_element";
|
||||
public static CreateElement Instance { get; } = new();
|
||||
|
||||
private CreateElement()
|
||||
{
|
||||
}
|
||||
|
||||
public string UserCommandID => CommandName;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace FileTime.App.Core.UserCommand;
|
||||
|
||||
public sealed class CreateElementCommand : IIdentifiableUserCommand
|
||||
{
|
||||
public const string CommandName = "create_element";
|
||||
public static CreateElementCommand Instance { get; } = new();
|
||||
|
||||
private CreateElementCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public string UserCommandID => CommandName;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user