MoveCommand

This commit is contained in:
2023-07-04 22:07:11 +02:00
parent 718fd53026
commit 453834646b
17 changed files with 263 additions and 22 deletions

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class RenameCommand : IIdentifiableUserCommand
{
public const string CommandName = "rename";
public static RenameCommand Instance { get; } = new();
private RenameCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -5,6 +5,7 @@ using FileTime.App.Core.ViewModels;
using FileTime.Core.Command;
using FileTime.Core.Command.CreateContainer;
using FileTime.Core.Command.CreateElement;
using FileTime.Core.Command.Move;
using FileTime.Core.Extensions;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
@@ -60,6 +61,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
{
new TypeUserCommandHandler<CopyCommand>(Copy),
new TypeUserCommandHandler<DeleteCommand>(Delete),
new TypeUserCommandHandler<RenameCommand>(Rename),
new TypeUserCommandHandler<MarkCommand>(MarkItem),
new TypeUserCommandHandler<PasteCommand>(Paste),
new TypeUserCommandHandler<CreateContainer>(CreateContainer),
@@ -171,6 +173,29 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
await AddCommand(command);
}
private async Task Rename(RenameCommand command)
{
//TODO: group rename
List<ItemToMove> itemsToMove = new();
if (_currentSelectedItem?.BaseItem?.FullName is null) return;
var item = await _timelessContentProvider.GetItemByFullNameAsync(_currentSelectedItem.BaseItem.FullName, PointInTime.Present);
if (item is null) return;
var renameInput = new TextInputElement("New name", item.Name);
await _userCommunicationService.ReadInputs(renameInput);
//TODO: should check these...
var newPath = item.FullName!.GetParent()!.GetChild(renameInput.Value!);
itemsToMove.Add(new ItemToMove(item.FullName, newPath));
var moveCommandFactory = _serviceProvider.GetRequiredService<MoveCommandFactory>();
var moveCommand = moveCommandFactory.GenerateCommand(itemsToMove);
await AddCommand(moveCommand);
}
private async Task Delete(DeleteCommand command)
{
IList<FullName>? itemsToDelete = null;

View File

@@ -43,6 +43,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
AddUserCommand(PasteFilesFromClipboardCommand.Merge);
AddUserCommand(PauseCommandSchedulerCommand.Instance);
AddUserCommand(RefreshCommand.Instance);
AddUserCommand(RenameCommand.Instance);
AddUserCommand(StartCommandSchedulerCommand.Instance);
AddUserCommand(IdentifiableSearchCommand.SearchByNameContains);
AddUserCommand(SwitchToTabCommand.SwitchToLastTab);