From b3c7683c124cd378eb13c3bb35192768cea23ae1 Mon Sep 17 00:00:00 2001 From: Geoffroy BONNEVILLE Date: Mon, 4 May 2020 14:29:52 +0200 Subject: [PATCH] Send a message on save to update commands can execute --- ModernKeePass/App.xaml.cs | 11 ++++++++--- ModernKeePass/ViewModels/EntryDetailVm.cs | 2 ++ ModernKeePass/ViewModels/GroupDetailVm.cs | 2 ++ README.md | 2 +- WinAppCommon/Messages/DatabaseSavedMessage.cs | 7 +++++++ WinAppCommon/ViewModels/SaveVm.cs | 2 ++ WinAppCommon/WinAppCommon.projitems | 1 + 7 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 WinAppCommon/Messages/DatabaseSavedMessage.cs diff --git a/ModernKeePass/App.xaml.cs b/ModernKeePass/App.xaml.cs index 0439b0d..6b8de07 100644 --- a/ModernKeePass/App.xaml.cs +++ b/ModernKeePass/App.xaml.cs @@ -41,6 +41,7 @@ namespace ModernKeePass private readonly IDialogService _dialog; private readonly INotificationService _notification; private readonly IFileProxy _file; + private readonly IMessenger _messenger; public static IServiceProvider Services { get; private set; } @@ -67,14 +68,14 @@ namespace ModernKeePass _notification = Services.GetService(); _hockey = Services.GetService(); _file = Services.GetService(); - var messenger = Services.GetService(); + _messenger = Services.GetService(); InitializeComponent(); Suspending += OnSuspending; Resuming += OnResuming; UnhandledException += OnUnhandledException; - messenger.Register(this, async message => await HandelSaveError(message.Message)); + _messenger.Register(this, async message => await HandelSaveError(message.Message)); } private async Task HandelSaveError(string message) @@ -84,7 +85,11 @@ namespace ModernKeePass var file = await _file.CreateFile($"{database.Name} - copy", Domain.Common.Constants.Extensions.Kdbx, _resource.GetResourceValue("MessageDialogSaveErrorFileTypeDesc"), true); - if (file != null) await _mediator.Send(new SaveDatabaseCommand { FilePath = file.Id }); + if (file != null) + { + await _mediator.Send(new SaveDatabaseCommand { FilePath = file.Id }); + _messenger.Send(new DatabaseSavedMessage()); + } } #region Event Handlers diff --git a/ModernKeePass/ViewModels/EntryDetailVm.cs b/ModernKeePass/ViewModels/EntryDetailVm.cs index 836c576..ce51b37 100644 --- a/ModernKeePass/ViewModels/EntryDetailVm.cs +++ b/ModernKeePass/ViewModels/EntryDetailVm.cs @@ -266,6 +266,8 @@ namespace ModernKeePass.ViewModels DeleteCommand = new RelayCommand(async () => await AskForDelete()); GoBackCommand = new RelayCommand(() => _navigation.GoBack()); GoToParentCommand = new RelayCommand(() => GoToGroup(_parent.Id)); + + MessengerInstance.Register(this, _ => SaveCommand.RaiseCanExecuteChanged()); } public async Task Initialize(string entryId) diff --git a/ModernKeePass/ViewModels/GroupDetailVm.cs b/ModernKeePass/ViewModels/GroupDetailVm.cs index 914ea0e..c04176c 100644 --- a/ModernKeePass/ViewModels/GroupDetailVm.cs +++ b/ModernKeePass/ViewModels/GroupDetailVm.cs @@ -126,6 +126,8 @@ namespace ModernKeePass.ViewModels DeleteCommand = new RelayCommand(async () => await AskForDelete(),() => IsNotRoot); GoBackCommand = new RelayCommand(() => _navigation.GoBack()); GoToParentCommand= new RelayCommand(() => GoToGroup(_parent.Id), () => _parent != null); + + MessengerInstance.Register(this, _ => SaveCommand.RaiseCanExecuteChanged()); } public async Task Initialize(string groupId) diff --git a/README.md b/README.md index 0bf430b..195f5d8 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ You can get it [here](https://www.microsoft.com/en-us/store/p/modernkeepass/9mwq # Build and Test 1. Clone the repository -2. Build the main app (the library reference dll is actually a NuGet dependency, built from the [**ModernKeePassLib** project](../ModernKeePassLib/README.md)) +2. Build the main app (the library reference dll is actually a NuGet dependency, built from the [**ModernKeePassLib** project](https://github.com/wismna/ModernKeePassLib)) 3. Edit the `.appxmanifest` file to select another certificate (you can create one using Visual Studio or *certutil.exe*) # Contribute diff --git a/WinAppCommon/Messages/DatabaseSavedMessage.cs b/WinAppCommon/Messages/DatabaseSavedMessage.cs new file mode 100644 index 0000000..9c2d28c --- /dev/null +++ b/WinAppCommon/Messages/DatabaseSavedMessage.cs @@ -0,0 +1,7 @@ +namespace Messages +{ + public class DatabaseSavedMessage + { + + } +} \ No newline at end of file diff --git a/WinAppCommon/ViewModels/SaveVm.cs b/WinAppCommon/ViewModels/SaveVm.cs index adc7365..dae39c0 100644 --- a/WinAppCommon/ViewModels/SaveVm.cs +++ b/WinAppCommon/ViewModels/SaveVm.cs @@ -34,6 +34,8 @@ namespace ModernKeePass.ViewModels SaveAsCommand = new RelayCommand(async () => await SaveAs()); SaveCommand = new RelayCommand(async () => await Save(), () => IsSaveEnabled); CloseCommand = new RelayCommand(async () => await Close()); + + MessengerInstance.Register(this, _ => SaveCommand.RaiseCanExecuteChanged()); } private async Task SaveAs() diff --git a/WinAppCommon/WinAppCommon.projitems b/WinAppCommon/WinAppCommon.projitems index c8163bb..61853f4 100644 --- a/WinAppCommon/WinAppCommon.projitems +++ b/WinAppCommon/WinAppCommon.projitems @@ -36,6 +36,7 @@ +