diff --git a/ModernKeePass/App.xaml.cs b/ModernKeePass/App.xaml.cs
index 46dea56..4d4957d 100644
--- a/ModernKeePass/App.xaml.cs
+++ b/ModernKeePass/App.xaml.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
+using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Storage;
@@ -81,18 +82,17 @@ namespace ModernKeePass
/// Details about the launch request and process.
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
- OnLaunchOrActivated(args);
+ await OnLaunchOrActivated(args);
await HockeyClient.Current.SendCrashesAsync(/* sendWithoutAsking: true */);
}
- protected override void OnActivated(IActivatedEventArgs args)
+ protected override async void OnActivated(IActivatedEventArgs args)
{
- OnLaunchOrActivated(args);
+ await OnLaunchOrActivated(args);
}
- private async void OnLaunchOrActivated(IActivatedEventArgs e)
+ private async Task OnLaunchOrActivated(IActivatedEventArgs e)
{
-
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
diff --git a/ModernKeePass/Interfaces/IPwEntity.cs b/ModernKeePass/Interfaces/IPwEntity.cs
index e855a8f..f4045a7 100644
--- a/ModernKeePass/Interfaces/IPwEntity.cs
+++ b/ModernKeePass/Interfaces/IPwEntity.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Windows.Input;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Interfaces
@@ -14,6 +15,14 @@ namespace ModernKeePass.Interfaces
bool IsEditMode { get; }
bool IsRecycleOnDelete { get; }
+ ///
+ /// Save changes to Model
+ ///
+ ICommand SaveCommand { get; }
+ ///
+ /// Restore ViewModel
+ ///
+ ICommand UndoDeleteCommand { get; }
///
/// Move a entity to the destination group
///
@@ -24,14 +33,6 @@ namespace ModernKeePass.Interfaces
///
void CommitDelete();
///
- /// Restore ViewModel
- ///
- void UndoDelete();
- ///
- /// Save changes to Model
- ///
- void Save();
- ///
/// Delete from ViewModel
///
void MarkForDelete(string recycleBinTitle);
diff --git a/ModernKeePass/ViewModels/EntryVm.cs b/ModernKeePass/ViewModels/EntryVm.cs
index edd5e93..c62446c 100644
--- a/ModernKeePass/ViewModels/EntryVm.cs
+++ b/ModernKeePass/ViewModels/EntryVm.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Windows.Input;
+using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePassLib;
@@ -158,6 +160,10 @@ namespace ModernKeePass.ViewModels
}
}
+ public ICommand SaveCommand { get; }
+ public ICommand GeneratePasswordCommand { get; }
+ public ICommand UndoDeleteCommand { get; }
+
public event PropertyChangedEventHandler PropertyChanged;
private readonly PwEntry _pwEntry;
@@ -184,6 +190,10 @@ namespace ModernKeePass.ViewModels
_resource = resource;
_pwEntry = entry;
ParentGroup = parent;
+
+ SaveCommand = new RelayCommand(() => _database.Save());
+ GeneratePasswordCommand = new RelayCommand(GeneratePassword);
+ UndoDeleteCommand = new RelayCommand(() => Move(PreviousGroup));
}
public void GeneratePassword()
@@ -215,21 +225,6 @@ namespace ModernKeePass.ViewModels
NotifyPropertyChanged("PasswordComplexityIndicator");
}
- private string GetEntryValue(string key)
- {
- return _pwEntry?.Strings.GetSafe(key).ReadString();
- }
-
- private void SetEntryValue(string key, string newValue)
- {
- if (!_isDirty)
- {
- _pwEntry.Touch(true);
- _pwEntry?.CreateBackup(null);
- }
- _pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
- _isDirty = true;
- }
public void MarkForDelete(string recycleBinTitle)
{
@@ -237,12 +232,7 @@ namespace ModernKeePass.ViewModels
_database.CreateRecycleBin(recycleBinTitle);
Move(_database.RecycleBinEnabled && !ParentGroup.IsSelected ? _database.RecycleBin : null);
}
-
- public void UndoDelete()
- {
- Move(PreviousGroup);
- }
-
+
public void Move(GroupVm destination)
{
PreviousGroup = ParentGroup;
@@ -261,12 +251,7 @@ namespace ModernKeePass.ViewModels
_pwEntry.ParentGroup.Entries.Remove(_pwEntry);
if (!_database.RecycleBinEnabled || PreviousGroup.IsSelected) _database.AddDeletedItem(IdUuid);
}
-
- public void Save()
- {
- _database.Save();
- }
-
+
public PwEntry GetPwEntry()
{
return _pwEntry;
@@ -281,5 +266,20 @@ namespace ModernKeePass.ViewModels
return IsSelected ? _resource.GetResourceValue("EntryCurrent") : _pwEntry.LastModificationTime.ToString("g");
}
+ private string GetEntryValue(string key)
+ {
+ return _pwEntry?.Strings.GetSafe(key).ReadString();
+ }
+
+ private void SetEntryValue(string key, string newValue)
+ {
+ if (!_isDirty)
+ {
+ _pwEntry.Touch(true);
+ _pwEntry?.CreateBackup(null);
+ }
+ _pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
+ _isDirty = true;
+ }
}
}
diff --git a/ModernKeePass/ViewModels/GroupVm.cs b/ModernKeePass/ViewModels/GroupVm.cs
index c8c00b9..d1ab49c 100644
--- a/ModernKeePass/ViewModels/GroupVm.cs
+++ b/ModernKeePass/ViewModels/GroupVm.cs
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Input;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
@@ -106,7 +108,12 @@ namespace ModernKeePass.ViewModels
return groups;
}
}
-
+
+ public ICommand SaveCommand { get; }
+ public ICommand SortEntriesCommand { get; }
+ public ICommand SortGroupsCommand { get; }
+ public ICommand UndoDeleteCommand { get; }
+
private readonly PwGroup _pwGroup;
private readonly IDatabaseService _database;
private bool _isEditMode;
@@ -126,6 +133,13 @@ namespace ModernKeePass.ViewModels
_database = database;
ParentGroup = parent;
+ SaveCommand = new RelayCommand(() => _database.Save());
+ SortEntriesCommand = new RelayCommand(async () =>
+ await SortEntriesAsync().ConfigureAwait(false));
+ SortGroupsCommand = new RelayCommand(async () =>
+ await SortGroupsAsync().ConfigureAwait(false));
+ UndoDeleteCommand = new RelayCommand(() => Move(PreviousGroup));
+
if (recycleBinId != null && _pwGroup.Uuid.Equals(recycleBinId)) _database.RecycleBin = this;
Entries = new ObservableCollection(pwGroup.Entries.Select(e => new EntryVm(e, this)));
Entries.CollectionChanged += Entries_CollectionChanged;
@@ -199,13 +213,13 @@ namespace ModernKeePass.ViewModels
if (_database.RecycleBinEnabled && !PreviousGroup.IsSelected) _database.RecycleBin._pwGroup.AddGroup(_pwGroup, true);
else _database.AddDeletedItem(IdUuid);
}
-
- public void Save()
- {
- _database.Save();
- }
- public void SortEntries()
+ public override string ToString()
+ {
+ return Name;
+ }
+
+ private async Task SortEntriesAsync()
{
var comparer = new PwEntryComparer(PwDefs.TitleField, true, false);
try
@@ -215,11 +229,11 @@ namespace ModernKeePass.ViewModels
}
catch (Exception e)
{
- MessageDialogHelper.ShowErrorDialog(e).Wait();
+ await MessageDialogHelper.ShowErrorDialog(e);
}
}
- public void SortGroups()
+ private async Task SortGroupsAsync()
{
try
{
@@ -229,13 +243,9 @@ namespace ModernKeePass.ViewModels
}
catch (Exception e)
{
- MessageDialogHelper.ShowErrorDialog(e).Wait();
+ await MessageDialogHelper.ShowErrorDialog(e);
}
}
- public override string ToString()
- {
- return Name;
- }
}
}
diff --git a/ModernKeePass/ViewModels/RecentVm.cs b/ModernKeePass/ViewModels/RecentVm.cs
index 404ab5a..5dd3bf1 100644
--- a/ModernKeePass/ViewModels/RecentVm.cs
+++ b/ModernKeePass/ViewModels/RecentVm.cs
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
+using System.Windows.Input;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
@@ -34,6 +35,8 @@ namespace ModernKeePass.ViewModels
_selectedItem.IsSelected = true;
}
}
+
+ public ICommand ClearAllCommand { get; }
public RecentVm() : this (RecentService.Instance)
{ }
@@ -41,12 +44,14 @@ namespace ModernKeePass.ViewModels
public RecentVm(IRecentService recent)
{
_recent = recent;
+ ClearAllCommand = new RelayCommand(ClearAll);
+
RecentItems = _recent.GetAllFiles();
if (RecentItems.Count > 0)
SelectedItem = RecentItems[0] as RecentItemVm;
}
- public void ClearAll()
+ private void ClearAll()
{
_recent.ClearAll();
RecentItems.Clear();
diff --git a/ModernKeePass/Views/EntryDetailPage.xaml b/ModernKeePass/Views/EntryDetailPage.xaml
index 15cd483..51d2ae0 100644
--- a/ModernKeePass/Views/EntryDetailPage.xaml
+++ b/ModernKeePass/Views/EntryDetailPage.xaml
@@ -15,11 +15,11 @@
mc:Ignorable="d"
SizeChanged="EntryDetailPage_OnSizeChanged">
-
-
-
-
-
+
+
+
+
+
-
+
@@ -386,10 +380,9 @@
-
+
-
@@ -409,13 +402,7 @@
-
-
-
-
-
-
-
+
@@ -434,7 +421,7 @@
-
+