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;
|
|
|
|
|
public bool IsFileSelected => !string.IsNullOrEmpty(Path);
|
2017-10-10 15:00:31 +02:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public string Name { get; private set; }
|
|
|
|
|
public string Path { get; private set; }
|
2017-11-23 15:26:57 +01:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public OpenVm(): this(App.Services.GetService<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-06 20:20:45 +02:00
|
|
|
|
Name = file.Name;
|
|
|
|
|
Path = file.Path;
|
|
|
|
|
OnPropertyChanged(nameof(Name));
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|