mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Send a message on save to update commands can execute
This commit is contained in:
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
7
WinAppCommon/Messages/DatabaseSavedMessage.cs
Normal file
7
WinAppCommon/Messages/DatabaseSavedMessage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Messages
|
||||
{
|
||||
public class DatabaseSavedMessage
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -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()
|
||||
|
@@ -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" />
|
||||
|
Reference in New Issue
Block a user