2020-04-06 20:20:45 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.AOP;
|
|
|
|
|
using ModernKeePass.Domain.Dtos;
|
2017-10-10 15:00:31 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-11-27 15:26:36 +01:00
|
|
|
|
public class OpenVm: NotifyPropertyChangedBase
|
2017-10-10 15:00:31 +02:00
|
|
|
|
{
|
2020-04-06 20:20:45 +02:00
|
|
|
|
private readonly IRecentProxy _recent;
|
2020-04-07 12:48:18 +02:00
|
|
|
|
private string _name;
|
|
|
|
|
private string _path;
|
|
|
|
|
private string _token;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public bool IsFileSelected => !string.IsNullOrEmpty(Path);
|
2017-10-10 15:00:31 +02:00
|
|
|
|
|
2020-04-07 12:48:18 +02:00
|
|
|
|
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); }
|
|
|
|
|
}
|
2017-11-23 15:26:57 +01:00
|
|
|
|
|
2020-04-09 19:43:06 +02:00
|
|
|
|
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
|
2020-03-30 19:43:04 +02:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public OpenVm(IRecentProxy recent)
|
2017-12-01 17:59:38 +01:00
|
|
|
|
{
|
2020-03-30 19:43:04 +02:00
|
|
|
|
_recent = recent;
|
2017-12-01 17:59:38 +01:00
|
|
|
|
}
|
2020-03-30 19:43:04 +02:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public async Task OpenFile(FileInfo file)
|
2017-10-10 15:00:31 +02:00
|
|
|
|
{
|
2020-04-07 12:48:18 +02:00
|
|
|
|
Token = file.Id;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
Name = file.Name;
|
|
|
|
|
Path = file.Path;
|
|
|
|
|
OnPropertyChanged(nameof(IsFileSelected));
|
|
|
|
|
await AddToRecentList(file);
|
2017-10-10 15:00:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
private async Task AddToRecentList(FileInfo file)
|
2017-10-10 15:00:31 +02:00
|
|
|
|
{
|
2020-04-06 20:20:45 +02:00
|
|
|
|
await _recent.Add(file);
|
2017-10-10 15:00:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|