mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Code cleanup
Popup discard action now works
This commit is contained in:
@@ -149,11 +149,12 @@ namespace ModernKeePass
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the suspend request.</param>
|
||||
/// <param name="e">Details about the suspend request.</param>
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
private async void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
UnhandledException -= OnUnhandledException;
|
||||
Database.Save();
|
||||
await Database.Close();
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
|
@@ -13,12 +13,10 @@ namespace ModernKeePass.Common
|
||||
public static async void ShowActionDialog(string title, string contentText, string actionButtonText, string cancelButtonText, UICommandInvokedHandler actionCommand, UICommandInvokedHandler cancelCommand)
|
||||
{
|
||||
// Create the message dialog and set its content
|
||||
var messageDialog = CreateBasicDialog(title, contentText, cancelButtonText);
|
||||
var messageDialog = CreateBasicDialog(title, contentText, cancelButtonText, cancelCommand);
|
||||
|
||||
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
||||
messageDialog.Commands.Add(new UICommand(actionButtonText, actionCommand));
|
||||
// TODO: correct this
|
||||
//messageDialog.Commands.Add(new UICommand(cancelButtonText, cancelCommand));
|
||||
|
||||
// Show the message dialog
|
||||
await messageDialog.ShowAsync();
|
||||
@@ -71,13 +69,13 @@ namespace ModernKeePass.Common
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
private static MessageDialog CreateBasicDialog(string title, string message, string dismissActionText)
|
||||
private static MessageDialog CreateBasicDialog(string title, string message, string dismissActionText, UICommandInvokedHandler cancelCommand = null)
|
||||
{
|
||||
// Create the message dialog and set its content
|
||||
var messageDialog = new MessageDialog(message, title);
|
||||
|
||||
// Add commands and set their callbacks;
|
||||
messageDialog.Commands.Add(new UICommand(dismissActionText));
|
||||
messageDialog.Commands.Add(new UICommand(dismissActionText, cancelCommand));
|
||||
|
||||
// Set the command that will be invoked by default
|
||||
messageDialog.DefaultCommandIndex = 1;
|
||||
|
@@ -17,15 +17,6 @@ namespace ModernKeePass.Services
|
||||
{
|
||||
public class DatabaseService: IDatabase
|
||||
{
|
||||
/*public enum DatabaseStatus
|
||||
{
|
||||
Error = -3,
|
||||
NoCompositeKey = -2,
|
||||
CompositeKeyError = -1,
|
||||
Closed = 0,
|
||||
Opening = 1,
|
||||
Opened = 2
|
||||
}*/
|
||||
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
||||
private readonly ISettings _settings;
|
||||
private StorageFile _realDatabaseFile;
|
||||
@@ -44,7 +35,6 @@ namespace ModernKeePass.Services
|
||||
}
|
||||
}
|
||||
|
||||
//public int Status { get; set; } = (int)DatabaseStatus.Closed;
|
||||
public string Name => DatabaseFile?.Name;
|
||||
|
||||
public bool RecycleBinEnabled
|
||||
@@ -58,26 +48,9 @@ namespace ModernKeePass.Services
|
||||
get { return _databaseFile; }
|
||||
set
|
||||
{
|
||||
// No file, database is closed
|
||||
/*if (value == null)
|
||||
Status = (int) DatabaseStatus.Closed;
|
||||
else
|
||||
{
|
||||
// There already is an opened file
|
||||
if (Status == (int) DatabaseStatus.Opened)
|
||||
{
|
||||
if (_pwDatabase.Modified)
|
||||
throw new DatabaseOpenedException();
|
||||
Close().GetAwaiter().GetResult();
|
||||
}
|
||||
_databaseFile = value;
|
||||
Status = (int) DatabaseStatus.Opening;
|
||||
}*/
|
||||
if (IsOpen)
|
||||
{
|
||||
//if (_pwDatabase.Modified)
|
||||
throw new DatabaseOpenedException();
|
||||
//Close().GetAwaiter().GetResult();
|
||||
throw new DatabaseOpenedException();
|
||||
}
|
||||
_databaseFile = value;
|
||||
}
|
||||
@@ -126,8 +99,6 @@ namespace ModernKeePass.Services
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
//Status = (int)DatabaseStatus.NoCompositeKey;
|
||||
//return;
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
var ioConnection = IOConnectionInfo.FromFile(DatabaseFile);
|
||||
@@ -164,14 +135,8 @@ namespace ModernKeePass.Services
|
||||
}
|
||||
catch (InvalidCompositeKeyException ex)
|
||||
{
|
||||
//Status = (int)DatabaseStatus.CompositeKeyError;
|
||||
throw new ArgumentException(ex.Message, ex);
|
||||
}
|
||||
/*catch (Exception)
|
||||
{
|
||||
//Status = (int)DatabaseStatus.Error;
|
||||
throw;
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -213,10 +178,6 @@ namespace ModernKeePass.Services
|
||||
DatabaseFile = oldFile;
|
||||
throw;
|
||||
}
|
||||
/*finally
|
||||
{
|
||||
Status = (int)DatabaseStatus.Opened;
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -234,7 +195,6 @@ namespace ModernKeePass.Services
|
||||
await DatabaseFile.DeleteAsync();
|
||||
}
|
||||
DatabaseFile = null;
|
||||
|
||||
}
|
||||
|
||||
public void AddDeletedItem(PwUuid id)
|
||||
|
@@ -46,12 +46,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
/*var title = GetEntryValue(PwDefs.TitleField);
|
||||
return title == null ? _resource.GetResourceValue("EntryNew") : title;*/
|
||||
return GetEntryValue(PwDefs.TitleField);
|
||||
}
|
||||
get { return GetEntryValue(PwDefs.TitleField); }
|
||||
set { SetEntryValue(PwDefs.TitleField, value); }
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user