2017-10-25 18:29:50 +02:00
|
|
|
|
using System;
|
2017-11-24 12:17:41 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Windows.Storage.Pickers;
|
2017-10-25 18:29:50 +02:00
|
|
|
|
using Windows.UI.Popups;
|
2017-11-24 12:17:41 +01:00
|
|
|
|
using ModernKeePass.Exceptions;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
2017-10-25 18:29:50 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Common
|
|
|
|
|
{
|
|
|
|
|
public static class MessageDialogHelper
|
|
|
|
|
{
|
2017-11-24 12:17:41 +01:00
|
|
|
|
public static async void ShowActionDialog(string title, string contentText, string actionButtonText, string cancelButtonText, UICommandInvokedHandler action)
|
2017-10-25 18:29:50 +02:00
|
|
|
|
{
|
|
|
|
|
// Create the message dialog and set its content
|
2017-11-24 12:17:41 +01:00
|
|
|
|
var messageDialog = new MessageDialog(contentText, title);
|
2017-10-25 18:29:50 +02:00
|
|
|
|
|
|
|
|
|
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
2017-11-24 12:17:41 +01:00
|
|
|
|
messageDialog.Commands.Add(new UICommand(actionButtonText, action));
|
|
|
|
|
messageDialog.Commands.Add(new UICommand(cancelButtonText));
|
2017-10-25 18:29:50 +02:00
|
|
|
|
|
|
|
|
|
// Set the command that will be invoked by default
|
|
|
|
|
messageDialog.DefaultCommandIndex = 1;
|
|
|
|
|
|
|
|
|
|
// Set the command to be invoked when escape is pressed
|
|
|
|
|
messageDialog.CancelCommandIndex = 1;
|
|
|
|
|
|
|
|
|
|
// Show the message dialog
|
|
|
|
|
await messageDialog.ShowAsync();
|
|
|
|
|
}
|
2017-11-13 11:28:14 +01:00
|
|
|
|
|
2017-11-24 12:17:41 +01:00
|
|
|
|
public static void SaveErrorDialog(SaveException exception, IDatabase database)
|
|
|
|
|
{
|
|
|
|
|
ShowActionDialog("Save error", exception.InnerException.Message, "Save as", "Discard", async command =>
|
|
|
|
|
{
|
|
|
|
|
var savePicker = new FileSavePicker
|
|
|
|
|
{
|
|
|
|
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
|
|
|
|
|
SuggestedFileName = $"{database.DatabaseFile.DisplayName} - copy"
|
|
|
|
|
};
|
|
|
|
|
savePicker.FileTypeChoices.Add("KeePass 2.x database", new List<string> { ".kdbx" });
|
|
|
|
|
|
|
|
|
|
var file = await savePicker.PickSaveFileAsync();
|
|
|
|
|
if (file != null) database.Save(file);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 11:28:14 +01:00
|
|
|
|
public static async void ShowErrorDialog(Exception exception)
|
|
|
|
|
{
|
2017-11-23 19:02:49 +01:00
|
|
|
|
if (exception == null) return;
|
2017-11-13 11:28:14 +01:00
|
|
|
|
// Create the message dialog and set its content
|
|
|
|
|
var messageDialog = new MessageDialog(exception.Message, "Error occured");
|
|
|
|
|
|
|
|
|
|
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
|
|
|
|
messageDialog.Commands.Add(new UICommand("OK"));
|
|
|
|
|
|
|
|
|
|
// Show the message dialog
|
|
|
|
|
await messageDialog.ShowAsync();
|
|
|
|
|
}
|
2017-10-25 18:29:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|