2017-10-25 18:29:50 +02:00
|
|
|
|
using System;
|
2018-06-20 17:20:15 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-10-25 18:29:50 +02:00
|
|
|
|
using Windows.UI.Popups;
|
|
|
|
|
|
2017-12-01 17:59:38 +01:00
|
|
|
|
namespace ModernKeePass.Common
|
2017-10-25 18:29:50 +02:00
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
public static class MessageDialogHelper
|
2017-10-25 18:29:50 +02:00
|
|
|
|
{
|
2018-06-20 17:20:15 +02:00
|
|
|
|
public static async Task ShowActionDialog(string title, string contentText, string actionButtonText, string cancelButtonText, UICommandInvokedHandler actionCommand, UICommandInvokedHandler cancelCommand)
|
2017-10-25 18:29:50 +02:00
|
|
|
|
{
|
|
|
|
|
// Create the message dialog and set its content
|
2018-01-09 18:40:11 +01:00
|
|
|
|
var messageDialog = CreateBasicDialog(title, contentText, cancelButtonText, cancelCommand);
|
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
|
2018-01-08 18:52:03 +01:00
|
|
|
|
messageDialog.Commands.Add(new UICommand(actionButtonText, actionCommand));
|
2017-12-08 19:38:33 +01:00
|
|
|
|
|
2017-10-25 18:29:50 +02:00
|
|
|
|
// Show the message dialog
|
2020-04-15 12:02:30 +02:00
|
|
|
|
await messageDialog.ShowAsync().AsTask().ConfigureAwait(false);
|
2017-10-25 18:29:50 +02:00
|
|
|
|
}
|
2018-06-19 18:47:37 +02:00
|
|
|
|
|
2018-06-20 17:20:15 +02:00
|
|
|
|
public static async Task ShowErrorDialog(Exception exception)
|
2017-11-13 11:28:14 +01:00
|
|
|
|
{
|
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
|
2018-03-09 18:06:06 +01:00
|
|
|
|
var messageDialog = CreateBasicDialog(exception.Message, exception.StackTrace, "OK");
|
2017-11-13 11:28:14 +01:00
|
|
|
|
|
|
|
|
|
// Show the message dialog
|
2020-04-15 12:02:30 +02:00
|
|
|
|
await messageDialog.ShowAsync().AsTask().ConfigureAwait(false);
|
2017-11-13 11:28:14 +01:00
|
|
|
|
}
|
2017-12-08 19:38:33 +01:00
|
|
|
|
|
2018-06-20 17:20:15 +02:00
|
|
|
|
public static async Task ShowNotificationDialog(string title, string message)
|
2017-12-08 19:38:33 +01:00
|
|
|
|
{
|
|
|
|
|
var dialog = CreateBasicDialog(title, message, "OK");
|
|
|
|
|
|
|
|
|
|
// Show the message dialog
|
2020-04-15 12:02:30 +02:00
|
|
|
|
await dialog.ShowAsync().AsTask().ConfigureAwait(false);
|
2017-12-08 19:38:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 18:40:11 +01:00
|
|
|
|
private static MessageDialog CreateBasicDialog(string title, string message, string dismissActionText, UICommandInvokedHandler cancelCommand = null)
|
2017-12-08 19:38:33 +01:00
|
|
|
|
{
|
|
|
|
|
// Create the message dialog and set its content
|
|
|
|
|
var messageDialog = new MessageDialog(message, title);
|
|
|
|
|
|
2018-06-18 14:58:01 +02:00
|
|
|
|
// Add commands and set their callbacks
|
2018-01-09 18:40:11 +01:00
|
|
|
|
messageDialog.Commands.Add(new UICommand(dismissActionText, cancelCommand));
|
2017-12-08 19:38:33 +01: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;
|
|
|
|
|
|
|
|
|
|
return messageDialog;
|
|
|
|
|
}
|
2017-10-25 18:29:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|