2018-06-22 18:31:55 +02:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Windows.UI.Xaml;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using MediatR;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2018-06-21 18:40:44 +02:00
|
|
|
|
using Microsoft.Xaml.Interactivity;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
2018-06-21 18:40:44 +02:00
|
|
|
|
using ModernKeePass.Common;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
|
|
|
|
using ModernKeePass.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Actions
|
|
|
|
|
{
|
|
|
|
|
public class DeleteEntityAction : DependencyObject, IAction
|
|
|
|
|
{
|
2020-03-30 19:43:04 +02:00
|
|
|
|
private readonly IMediator _mediator;
|
|
|
|
|
|
2020-03-26 12:25:22 +01:00
|
|
|
|
public IVmEntity Entity
|
2018-06-21 18:40:44 +02:00
|
|
|
|
{
|
2020-03-26 12:25:22 +01:00
|
|
|
|
get { return (IVmEntity)GetValue(EntityProperty); }
|
2018-06-21 18:40:44 +02:00
|
|
|
|
set { SetValue(EntityProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty EntityProperty =
|
2020-03-26 12:25:22 +01:00
|
|
|
|
DependencyProperty.Register("Entity", typeof(IVmEntity), typeof(DeleteEntityAction),
|
2018-06-21 18:40:44 +02:00
|
|
|
|
new PropertyMetadata(null));
|
|
|
|
|
|
2018-06-22 18:31:55 +02:00
|
|
|
|
public ICommand Command
|
2018-06-21 18:40:44 +02:00
|
|
|
|
{
|
2018-06-22 18:31:55 +02:00
|
|
|
|
get { return (ICommand)GetValue(CommandProperty); }
|
|
|
|
|
set { SetValue(CommandProperty, value); }
|
2018-06-21 18:40:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 18:31:55 +02:00
|
|
|
|
public static readonly DependencyProperty CommandProperty =
|
|
|
|
|
DependencyProperty.Register("Command", typeof(ICommand), typeof(DeleteEntityAction),
|
2018-06-21 18:40:44 +02:00
|
|
|
|
new PropertyMetadata(null));
|
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public DeleteEntityAction() : this(App.Services.GetRequiredService<IMediator>()) { }
|
2020-03-30 19:43:04 +02:00
|
|
|
|
|
|
|
|
|
public DeleteEntityAction(IMediator mediator)
|
|
|
|
|
{
|
|
|
|
|
_mediator = mediator;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 18:40:44 +02:00
|
|
|
|
public object Execute(object sender, object parameter)
|
|
|
|
|
{
|
2020-04-06 20:20:45 +02:00
|
|
|
|
var resource = new ResourceHelper();
|
2020-04-01 12:48:36 +02:00
|
|
|
|
var type = Entity is GroupDetailVm ? "Group" : "Entry";
|
2020-03-30 19:43:04 +02:00
|
|
|
|
var isRecycleOnDelete = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult().IsRecycleBinEnabled;
|
2020-03-28 16:13:17 +01:00
|
|
|
|
|
2020-03-30 19:43:04 +02:00
|
|
|
|
var message = isRecycleOnDelete
|
2020-03-28 16:13:17 +01:00
|
|
|
|
? resource.GetResourceValue($"{type}RecyclingConfirmation")
|
|
|
|
|
: resource.GetResourceValue($"{type}DeletingConfirmation");
|
2020-03-30 19:43:04 +02:00
|
|
|
|
var text = isRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
|
2020-03-28 16:13:17 +01:00
|
|
|
|
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
|
|
|
|
|
resource.GetResourceValue("EntityDeleteActionButton"),
|
|
|
|
|
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
|
2018-06-21 18:40:44 +02:00
|
|
|
|
{
|
2020-03-28 16:13:17 +01:00
|
|
|
|
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
|
|
|
|
|
Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
|
2018-06-22 18:31:55 +02:00
|
|
|
|
Command.Execute(null);
|
2020-04-09 19:43:06 +02:00
|
|
|
|
}, null).GetAwaiter().GetResult();
|
2018-06-21 18:40:44 +02:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|