2018-06-22 18:31:55 +02:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Windows.UI.Xaml;
|
2018-06-21 18:40:44 +02:00
|
|
|
|
using Microsoft.Xaml.Interactivity;
|
2020-03-27 13:27:29 +01:00
|
|
|
|
using ModernKeePass.Application.Resources.Queries;
|
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-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));
|
|
|
|
|
|
|
|
|
|
public object Execute(object sender, object parameter)
|
|
|
|
|
{
|
2020-03-27 13:27:29 +01:00
|
|
|
|
var mediator = App.Mediator;
|
2018-06-21 18:40:44 +02:00
|
|
|
|
var type = Entity is GroupVm ? "Group" : "Entry";
|
|
|
|
|
|
|
|
|
|
var message = Entity.IsRecycleOnDelete
|
2020-03-27 13:27:29 +01:00
|
|
|
|
? mediator.Send(new GetResourceQuery { Key = $"{type}RecyclingConfirmation" })
|
|
|
|
|
: mediator.Send(new GetResourceQuery { Key = $"{type}DeletingConfirmation" });
|
|
|
|
|
var text = Entity.IsRecycleOnDelete ?
|
|
|
|
|
mediator.Send(new GetResourceQuery { Key = $"{type}Recycled" }) :
|
|
|
|
|
mediator.Send(new GetResourceQuery { Key = $"{type}Deleted" });
|
|
|
|
|
MessageDialogHelper.ShowActionDialog(
|
|
|
|
|
mediator.Send(new GetResourceQuery { Key = "EntityDeleteTitle" }).GetAwaiter().GetResult(),
|
|
|
|
|
message.GetAwaiter().GetResult(),
|
|
|
|
|
mediator.Send(new GetResourceQuery { Key = "EntityDeleteActionButton" }).GetAwaiter().GetResult(),
|
|
|
|
|
mediator.Send(new GetResourceQuery { Key = "EntityDeleteCancelButton" }).GetAwaiter().GetResult(), async a =>
|
2018-06-21 18:40:44 +02:00
|
|
|
|
{
|
2020-03-27 13:27:29 +01:00
|
|
|
|
ToastNotificationHelper.ShowMovedToast(Entity, await mediator.Send(new GetResourceQuery { Key = "EntityDeleting" }), await text);
|
|
|
|
|
await Entity.MarkForDelete(await mediator.Send(new GetResourceQuery { Key = "RecycleBinTitle"}));
|
2018-06-22 18:31:55 +02:00
|
|
|
|
Command.Execute(null);
|
2018-06-21 18:40:44 +02:00
|
|
|
|
}, null).GetAwaiter();
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|