CopyCommandFactory, Copy status

This commit is contained in:
2023-07-01 22:04:00 +02:00
parent bd494526f5
commit 01fce38b7d
9 changed files with 111 additions and 42 deletions

View File

@@ -7,7 +7,7 @@ public class ClipboardService : IClipboardService
{
private List<FullName> _content;
public IReadOnlyList<FullName> Content { get; private set; }
public Type? CommandType { get; private set; }
public Type? CommandFactoryType { get; private set; }
public ClipboardService()
{
@@ -40,11 +40,11 @@ public class ClipboardService : IClipboardService
{
_content = new List<FullName>();
Content = _content.AsReadOnly();
CommandType = null;
CommandFactoryType = null;
}
public void SetCommand<T>() where T : ITransportationCommand
public void SetCommand<T>() where T : ITransportationCommandFactory
{
CommandType = typeof(T);
CommandFactoryType = typeof(T);
}
}

View File

@@ -84,7 +84,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
private Task Copy()
{
_clipboardService.Clear();
_clipboardService.SetCommand<FileTime.Core.Command.Copy.CopyCommand>();
_clipboardService.SetCommand<FileTime.Core.Command.Copy.CopyCommandFactory>();
if ((_markedItems?.Collection?.Count ?? 0) > 0)
{
@@ -120,23 +120,15 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
private async Task Paste(TransportMode mode)
{
if (_clipboardService.CommandType is null)
if (_clipboardService.CommandFactoryType is null)
{
_userCommunicationService.ShowToastMessage("Clipboard is empty.");
return;
}
var command = (ITransportationCommand) _serviceProvider.GetRequiredService(_clipboardService.CommandType);
command.TransportMode = mode;
command.Sources.Clear();
foreach (var item in _clipboardService.Content)
{
command.Sources.Add(item);
}
command.Target = _currentLocation?.FullName;
//TODO: check _currentLocation?.FullName
var commandFactory = (ITransportationCommandFactory) _serviceProvider.GetRequiredService(_clipboardService.CommandFactoryType);
var command = commandFactory.GenerateCommand(_clipboardService.Content, mode, _currentLocation?.FullName);
_clipboardService.Clear();