Recycle bin restore function (actually implemented a move functionality, for later)

This commit is contained in:
2017-10-31 18:49:18 +01:00
committed by BONNEVILLE Geoffroy
parent d32f312d60
commit 7e642e3b73
16 changed files with 163 additions and 141 deletions

View File

@@ -10,67 +10,14 @@ namespace ModernKeePass.Common
{
public static class ToastNotificationHelper
{
public static /*async*/ void ShowUndoToast(IPwEntity entity)
public static void ShowMovedToast(IPwEntity entity, string action, string text)
{
// This is for Windows 10
// Construct the visuals of the toast
/*var visual = new ToastVisual
{
BindingGeneric = new ToastBindingGeneric
{
Children =
{
new AdaptiveText
{
Text = $"{entityType} {entity.Name} deleted."
}
}
}
};
// Construct the actions for the toast (inputs and buttons)
var actions = new ToastActionsCustom
{
Buttons =
{
new ToastButton("Undo", new QueryString
{
{ "action", "undo" },
{ "entityType", entityType },
{ "entityId", entity.Id }
}.ToString())
}
};
// Now we can construct the final toast content
var toastContent = new ToastContent
{
Visual = visual,
Actions = actions,
// Arguments when the user taps body of toast
Launch = new QueryString()
{
{ "action", "undo" },
{ "entityType", "group" },
{ "entityId", entity.Id }
}.ToString()
};
// And create the toast notification
var toastXml = new XmlDocument();
toastXml.LoadXml(toastContent.GetContent());
var toast = new ToastNotification(toastXml) {ExpirationTime = DateTime.Now.AddSeconds(5)};
toast.Dismissed += Toast_Dismissed;
*/
var app = (App)Application.Current;
var entityType = entity is GroupVm ? "Group" : "Entry";
var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var toastElements = notificationXml.GetElementsByTagName("text");
toastElements[0].AppendChild(notificationXml.CreateTextNode($"{entityType} {entity.Name} deleted"));
toastElements[1].AppendChild(notificationXml.CreateTextNode("Click me to undo"));
toastElements[0].AppendChild(notificationXml.CreateTextNode($"{action} {entityType} {entity.Name}"));
toastElements[1].AppendChild(notificationXml.CreateTextNode(text));
var toastNode = notificationXml.SelectSingleNode("/toast");
var launch = new JsonObject
@@ -84,19 +31,8 @@ namespace ModernKeePass.Common
{
ExpirationTime = DateTime.Now.AddSeconds(5)
};
toast.Dismissed += Toast_Dismissed;
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
private static void Toast_Dismissed(ToastNotification sender, ToastDismissedEventArgs args)
{
var toastNode = sender.Content.SelectSingleNode("/toast");
if (toastNode == null) return;
var launchArguments = JsonObject.Parse(((XmlElement)toastNode).GetAttribute("launch"));
var app = (App)Application.Current;
var entity = app.PendingDeleteEntities[launchArguments["entityId"].GetString()];
app.PendingDeleteEntities.Remove(launchArguments["entityId"].GetString());
entity.CommitDelete();
}
}
}