Send a message on save to update commands can execute

This commit is contained in:
Geoffroy BONNEVILLE
2020-05-04 14:29:52 +02:00
parent 1e7662def7
commit b3c7683c12
7 changed files with 23 additions and 4 deletions

View File

@@ -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<INotificationService>();
_hockey = Services.GetService<IHockeyClient>();
_file = Services.GetService<IFileProxy>();
var messenger = Services.GetService<IMessenger>();
_messenger = Services.GetService<IMessenger>();
InitializeComponent();
Suspending += OnSuspending;
Resuming += OnResuming;
UnhandledException += OnUnhandledException;
messenger.Register<SaveErrorMessage>(this, async message => await HandelSaveError(message.Message));
_messenger.Register<SaveErrorMessage>(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

View File

@@ -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<DatabaseSavedMessage>(this, _ => SaveCommand.RaiseCanExecuteChanged());
}
public async Task Initialize(string entryId)

View File

@@ -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<DatabaseSavedMessage>(this, _ => SaveCommand.RaiseCanExecuteChanged());
}
public async Task Initialize(string groupId)

View File

@@ -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

View File

@@ -0,0 +1,7 @@
namespace Messages
{
public class DatabaseSavedMessage
{
}
}

View File

@@ -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<DatabaseSavedMessage>(this, _ => SaveCommand.RaiseCanExecuteChanged());
}
private async Task SaveAs()

View File

@@ -36,6 +36,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseClosedMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseOpenedMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseOpeningMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseSavedMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\FileNotFoundMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\NavigateToPageMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\SaveErrorMessage.cs" />