Remove entry from mru when it does not exist anymore

This commit is contained in:
Geoffroy BONNEVILLE
2020-04-25 22:34:50 +02:00
parent 7778e45deb
commit 59ab43ca9c
7 changed files with 54 additions and 6 deletions

View File

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

View File

@@ -3,13 +3,14 @@ using System.Linq;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Messages;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.ViewModels.ListItems;
namespace ModernKeePass.ViewModels
{
public class RecentVm : ObservableObject, IHasSelectableObject
public class RecentVm : ViewModelBase, IHasSelectableObject
{
private readonly IRecentProxy _recent;
private ISelectableModel _selectedItem;
@@ -45,13 +46,18 @@ namespace ModernKeePass.ViewModels
{
_recent = recent;
ClearAllCommand = new RelayCommand(ClearAll);
PopulateRecentItems();
MessengerInstance.Register<FileNotFoundMessage>(this, _ => PopulateRecentItems());
}
private void PopulateRecentItems()
{
var recentItems = _recent.GetAll().Select(r => new RecentItemVm(r));
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
if (RecentItems.Count > 0)
SelectedItem = RecentItems[0];
}
private void ClearAll()
{
_recent.ClearAll();

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
@@ -95,6 +96,7 @@ namespace ModernKeePass.ViewModels
private readonly IMediator _mediator;
private readonly IResourceProxy _resource;
private readonly INotificationService _notification;
private bool _hasPassword;
private bool _hasKeyFile;
private bool _isOpening;
@@ -105,10 +107,11 @@ namespace ModernKeePass.ViewModels
private string _keyFileText;
private string _openButtonLabel;
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource)
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
{
_mediator = mediator;
_resource = resource;
_notification = notification;
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
@@ -153,6 +156,13 @@ namespace ModernKeePass.ViewModels
if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile"));
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
}
catch (FileNotFoundException)
{
_notification.Show(
$"{_resource.GetResourceValue("FileNotFoundTitle")}",
$"{_resource.GetResourceValue("FileNotFoundDescription")}");
MessengerInstance.Send(new FileNotFoundMessage());
}
catch (Exception e)
{
var error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";

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\FileNotFoundMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\NavigateToPageMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\SaveErrorMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\FirstItemDataTemplateSelector.cs" />