WIP
This commit is contained in:
@@ -5,8 +5,8 @@ namespace FileTime.App.Core.Services;
|
||||
|
||||
public interface IModalService
|
||||
{
|
||||
IObservable<IChangeSet<IModalViewModelBase>> OpenModals { get; }
|
||||
IObservable<IChangeSet<IModalViewModel>> OpenModals { get; }
|
||||
|
||||
void OpenModal(IModalViewModelBase modalToOpen);
|
||||
void CloseModal(IModalViewModelBase modalToClose);
|
||||
void OpenModal(IModalViewModel modalToOpen);
|
||||
void CloseModal(IModalViewModel modalToClose);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace FileTime.App.Core.UserCommand;
|
||||
|
||||
public class DeleteCommand : IIdentifiableUserCommand
|
||||
{
|
||||
public const string SoftDeleteCommandName = "soft_delete";
|
||||
public const string HardDeleteCommandName = "hard_delete";
|
||||
|
||||
public static DeleteCommand SoftDelete { get; } = new DeleteCommand(SoftDeleteCommandName, false);
|
||||
public static DeleteCommand HardDelete { get; } = new DeleteCommand(HardDeleteCommandName, true);
|
||||
|
||||
private DeleteCommand(string commandName, bool hardDelete)
|
||||
{
|
||||
UserCommandID = commandName;
|
||||
IsHardDelete = hardDelete;
|
||||
}
|
||||
|
||||
public string UserCommandID { get; }
|
||||
public bool IsHardDelete { get; }
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
public interface IModalViewModelBase
|
||||
public interface IModalViewModel
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Command.CreateContainer;
|
||||
using FileTime.Core.Command.CreateElement;
|
||||
using FileTime.Core.Extensions;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
@@ -23,6 +24,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
private readonly IClipboardService _clipboardService;
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private readonly ILogger<ItemManipulationUserCommandHandlerService> _logger;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly ICommandScheduler _commandScheduler;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly BindedCollection<FullName>? _markedItems;
|
||||
@@ -42,6 +44,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
_clipboardService = clipboardService;
|
||||
_userCommunicationService = userCommunicationService;
|
||||
_logger = logger;
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_commandScheduler = commandScheduler;
|
||||
_serviceProvider = serviceProvider;
|
||||
|
||||
@@ -54,6 +57,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
AddCommandHandlers(new IUserCommandHandler[]
|
||||
{
|
||||
new TypeUserCommandHandler<CopyCommand>(Copy),
|
||||
new TypeUserCommandHandler<DeleteCommand>(Delete),
|
||||
new TypeUserCommandHandler<MarkCommand>(MarkItem),
|
||||
new TypeUserCommandHandler<PasteCommand>(Paste),
|
||||
new TypeUserCommandHandler<CreateContainer>(CreateContainer),
|
||||
@@ -143,7 +147,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
_clipboardService.Clear();
|
||||
|
||||
if (command is IRequireInputCommand requireInput) await requireInput.ReadInputs();
|
||||
|
||||
|
||||
await AddCommand(command);
|
||||
}
|
||||
|
||||
@@ -181,6 +185,65 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
await AddCommand(command);
|
||||
}
|
||||
|
||||
private async Task Delete(DeleteCommand command)
|
||||
{
|
||||
IList<FullName>? itemsToDelete = null;
|
||||
var shouldDelete = false;
|
||||
string? questionText = null;
|
||||
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
||||
{
|
||||
itemsToDelete = new List<FullName>(_markedItems!.Collection!);
|
||||
}
|
||||
else if (_currentSelectedItem?.BaseItem?.FullName is not null)
|
||||
{
|
||||
itemsToDelete = new List<FullName>()
|
||||
{
|
||||
_currentSelectedItem.BaseItem.FullName
|
||||
};
|
||||
}
|
||||
|
||||
if ((itemsToDelete?.Count ?? 0) == 0) return;
|
||||
|
||||
if (itemsToDelete!.Count == 1)
|
||||
{
|
||||
var resolvedOnlyItem = await _timelessContentProvider.GetItemByFullNameAsync(itemsToDelete[0], PointInTime.Present);
|
||||
|
||||
if (resolvedOnlyItem is IContainer {AllowRecursiveDeletion: true} onlyContainer
|
||||
&& await onlyContainer.Items.GetItemsAsync() is { } children
|
||||
&& children.Any())
|
||||
{
|
||||
questionText = $"The container '{onlyContainer.DisplayName}' is not empty. Proceed with delete?";
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldDelete = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemsToDelete?.Count == 0) return;
|
||||
|
||||
if (questionText is { })
|
||||
{
|
||||
var proceedDelete = await _userCommunicationService.ShowMessageBox(questionText!);
|
||||
|
||||
if (proceedDelete == MessageBoxResult.Cancel) return;
|
||||
}
|
||||
else if (!shouldDelete)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var deleteCommand = new FileTime.Core.Command.Delete.DeleteCommand()
|
||||
{
|
||||
HardDelete = command.IsHardDelete
|
||||
};
|
||||
|
||||
deleteCommand.ItemsToDelete.AddRange(itemsToDelete!);
|
||||
await AddCommand(deleteCommand);
|
||||
|
||||
_selectedTab?.ClearMarkedItems();
|
||||
}
|
||||
|
||||
private async Task AddCommand(ICommand command)
|
||||
{
|
||||
await _commandScheduler.AddCommand(command);
|
||||
|
||||
@@ -16,6 +16,8 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
||||
AddUserCommand(CopyNativePathCommand.Instance);
|
||||
AddUserCommand(CreateContainer.Instance);
|
||||
AddUserCommand(CreateElement.Instance);
|
||||
AddUserCommand(DeleteCommand.HardDelete);
|
||||
AddUserCommand(DeleteCommand.SoftDelete);
|
||||
AddUserCommand(EnterRapidTravelCommand.Instance);
|
||||
AddUserCommand(ExitRapidTravelCommand.Instance);
|
||||
AddUserCommand(GoToHomeCommand.Instance);
|
||||
|
||||
Reference in New Issue
Block a user