mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Better global exception handling
Save error now shows a Save as button Recent list now not changed at every access (only on actual file open) Some code refactoring
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Popups;
|
||||
using ModernKeePass.Exceptions;
|
||||
using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Common
|
||||
{
|
||||
public static class MessageDialogHelper
|
||||
{
|
||||
public static async void ShowDeleteConfirmationDialog(string actionText, string contentText, UICommandInvokedHandler action)
|
||||
public static async void ShowActionDialog(string title, string contentText, string actionButtonText, string cancelButtonText, UICommandInvokedHandler action)
|
||||
{
|
||||
// Create the message dialog and set its content
|
||||
var messageDialog = new MessageDialog(contentText);
|
||||
var messageDialog = new MessageDialog(contentText, title);
|
||||
|
||||
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
||||
messageDialog.Commands.Add(new UICommand(actionText, action));
|
||||
messageDialog.Commands.Add(new UICommand("Cancel"));
|
||||
messageDialog.Commands.Add(new UICommand(actionButtonText, action));
|
||||
messageDialog.Commands.Add(new UICommand(cancelButtonText));
|
||||
|
||||
// Set the command that will be invoked by default
|
||||
messageDialog.DefaultCommandIndex = 1;
|
||||
@@ -24,6 +28,22 @@ namespace ModernKeePass.Common
|
||||
await messageDialog.ShowAsync();
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
public static async void ShowErrorDialog(Exception exception)
|
||||
{
|
||||
if (exception == null) return;
|
||||
|
Reference in New Issue
Block a user