Don't use mediator for App services (recent, resource, settings)

WIP in View models
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-28 16:13:17 +01:00
parent 45fcf7e8ab
commit d1ba73ee9d
30 changed files with 68 additions and 349 deletions

View File

@@ -1,9 +1,9 @@
using System.Windows.Input;
using Windows.UI.Xaml;
using Microsoft.Xaml.Interactivity;
using ModernKeePass.Application.Resources.Queries;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Actions
@@ -32,23 +32,19 @@ namespace ModernKeePass.Actions
public object Execute(object sender, object parameter)
{
var mediator = App.Mediator;
var resource = new ResourcesService();
var type = Entity is GroupVm ? "Group" : "Entry";
var message = Entity.IsRecycleOnDelete
? 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 =>
? resource.GetResourceValue($"{type}RecyclingConfirmation")
: resource.GetResourceValue($"{type}DeletingConfirmation");
var text = Entity.IsRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
{
ToastNotificationHelper.ShowMovedToast(Entity, await mediator.Send(new GetResourceQuery { Key = "EntityDeleting" }), await text);
await Entity.MarkForDelete(await mediator.Send(new GetResourceQuery { Key = "RecycleBinTitle"}));
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
Command.Execute(null);
}, null).GetAwaiter();