Files
modernkeepass/ModernKeePass/ViewModels/OpenVm.cs
Geoffroy BONNEVILLE d972b6cb5a Added the option to close DB without saving
Changed the way recent files are retrieved
Stopped showing the DB Closed exception on suspend
Reordering entries works
Moved code from infra to application
Cleanup
2020-04-09 19:43:06 +02:00

57 lines
1.5 KiB
C#

using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels
{
public class OpenVm: NotifyPropertyChangedBase
{
private readonly IRecentProxy _recent;
private string _name;
private string _path;
private string _token;
public bool IsFileSelected => !string.IsNullOrEmpty(Path);
public string Token
{
get { return _token; }
set { SetProperty(ref _token, value); }
}
public string Name
{
get { return _name; }
private set { SetProperty(ref _name, value); }
}
public string Path
{
get { return _path; }
private set { SetProperty(ref _path, value); }
}
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
public OpenVm(IRecentProxy recent)
{
_recent = recent;
}
public async Task OpenFile(FileInfo file)
{
Token = file.Id;
Name = file.Name;
Path = file.Path;
OnPropertyChanged(nameof(IsFileSelected));
await AddToRecentList(file);
}
private async Task AddToRecentList(FileInfo file)
{
await _recent.Add(file);
}
}
}