Code cleanup

Popup discard action now works
This commit is contained in:
BONNEVILLE Geoffroy
2018-01-09 18:40:11 +01:00
parent a19519fa73
commit b46ab8db51
4 changed files with 7 additions and 53 deletions

View File

@@ -149,11 +149,12 @@ namespace ModernKeePass
/// </summary> /// </summary>
/// <param name="sender">The source of the suspend request.</param> /// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about 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(); var deferral = e.SuspendingOperation.GetDeferral();
UnhandledException -= OnUnhandledException; UnhandledException -= OnUnhandledException;
Database.Save(); Database.Save();
await Database.Close();
deferral.Complete(); deferral.Complete();
} }

View File

@@ -13,12 +13,10 @@ namespace ModernKeePass.Common
public static async void ShowActionDialog(string title, string contentText, string actionButtonText, string cancelButtonText, UICommandInvokedHandler actionCommand, UICommandInvokedHandler cancelCommand) 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 // 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 // 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)); messageDialog.Commands.Add(new UICommand(actionButtonText, actionCommand));
// TODO: correct this
//messageDialog.Commands.Add(new UICommand(cancelButtonText, cancelCommand));
// Show the message dialog // Show the message dialog
await messageDialog.ShowAsync(); await messageDialog.ShowAsync();
@@ -71,13 +69,13 @@ namespace ModernKeePass.Common
await dialog.ShowAsync(); 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 // Create the message dialog and set its content
var messageDialog = new MessageDialog(message, title); var messageDialog = new MessageDialog(message, title);
// Add commands and set their callbacks; // 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 // Set the command that will be invoked by default
messageDialog.DefaultCommandIndex = 1; messageDialog.DefaultCommandIndex = 1;

View File

@@ -17,15 +17,6 @@ namespace ModernKeePass.Services
{ {
public class DatabaseService: IDatabase 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 PwDatabase _pwDatabase = new PwDatabase();
private readonly ISettings _settings; private readonly ISettings _settings;
private StorageFile _realDatabaseFile; private StorageFile _realDatabaseFile;
@@ -44,7 +35,6 @@ namespace ModernKeePass.Services
} }
} }
//public int Status { get; set; } = (int)DatabaseStatus.Closed;
public string Name => DatabaseFile?.Name; public string Name => DatabaseFile?.Name;
public bool RecycleBinEnabled public bool RecycleBinEnabled
@@ -58,26 +48,9 @@ namespace ModernKeePass.Services
get { return _databaseFile; } get { return _databaseFile; }
set 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 (IsOpen)
{ {
//if (_pwDatabase.Modified)
throw new DatabaseOpenedException(); throw new DatabaseOpenedException();
//Close().GetAwaiter().GetResult();
} }
_databaseFile = value; _databaseFile = value;
} }
@@ -126,8 +99,6 @@ namespace ModernKeePass.Services
{ {
if (key == null) if (key == null)
{ {
//Status = (int)DatabaseStatus.NoCompositeKey;
//return;
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
} }
var ioConnection = IOConnectionInfo.FromFile(DatabaseFile); var ioConnection = IOConnectionInfo.FromFile(DatabaseFile);
@@ -164,14 +135,8 @@ namespace ModernKeePass.Services
} }
catch (InvalidCompositeKeyException ex) catch (InvalidCompositeKeyException ex)
{ {
//Status = (int)DatabaseStatus.CompositeKeyError;
throw new ArgumentException(ex.Message, ex); throw new ArgumentException(ex.Message, ex);
} }
/*catch (Exception)
{
//Status = (int)DatabaseStatus.Error;
throw;
}*/
} }
/// <summary> /// <summary>
@@ -213,10 +178,6 @@ namespace ModernKeePass.Services
DatabaseFile = oldFile; DatabaseFile = oldFile;
throw; throw;
} }
/*finally
{
Status = (int)DatabaseStatus.Opened;
}*/
} }
/// <summary> /// <summary>
@@ -234,7 +195,6 @@ namespace ModernKeePass.Services
await DatabaseFile.DeleteAsync(); await DatabaseFile.DeleteAsync();
} }
DatabaseFile = null; DatabaseFile = null;
} }
public void AddDeletedItem(PwUuid id) public void AddDeletedItem(PwUuid id)

View File

@@ -46,12 +46,7 @@ namespace ModernKeePass.ViewModels
public string Name public string Name
{ {
get get { return GetEntryValue(PwDefs.TitleField); }
{
/*var title = GetEntryValue(PwDefs.TitleField);
return title == null ? _resource.GetResourceValue("EntryNew") : title;*/
return GetEntryValue(PwDefs.TitleField);
}
set { SetEntryValue(PwDefs.TitleField, value); } set { SetEntryValue(PwDefs.TitleField, value); }
} }