2017-12-01 17:59:38 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using System.Linq;
|
2018-06-20 18:41:56 +02:00
|
|
|
|
using System.Windows.Input;
|
2020-04-22 16:21:47 +02:00
|
|
|
|
using GalaSoft.MvvmLight;
|
2020-04-21 13:07:17 +02:00
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
2020-04-25 22:34:50 +02:00
|
|
|
|
using Messages;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
2020-04-20 20:02:43 +02:00
|
|
|
|
using ModernKeePass.ViewModels.ListItems;
|
2017-09-29 17:23:35 -04:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2020-05-07 16:01:59 +02:00
|
|
|
|
public class RecentVm : ViewModelBase
|
2017-09-29 17:23:35 -04:00
|
|
|
|
{
|
2020-04-06 20:20:45 +02:00
|
|
|
|
private readonly IRecentProxy _recent;
|
|
|
|
|
private ObservableCollection<RecentItemVm> _recentItems;
|
2020-05-11 10:53:14 +02:00
|
|
|
|
private int _selectedIndex;
|
2017-10-16 16:16:58 +02:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public ObservableCollection<RecentItemVm> RecentItems
|
2017-10-03 16:06:49 +02:00
|
|
|
|
{
|
|
|
|
|
get { return _recentItems; }
|
2020-04-22 16:21:47 +02:00
|
|
|
|
set { Set(() => RecentItems, ref _recentItems, value); }
|
2017-10-03 16:06:49 +02:00
|
|
|
|
}
|
2018-06-20 18:41:56 +02:00
|
|
|
|
|
|
|
|
|
public ICommand ClearAllCommand { get; }
|
2020-05-11 10:53:14 +02:00
|
|
|
|
|
|
|
|
|
public int SelectedIndex
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedIndex; }
|
|
|
|
|
set { Set(() => SelectedIndex, ref _selectedIndex, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public RecentVm(IRecentProxy recent)
|
2017-10-12 10:36:58 +02:00
|
|
|
|
{
|
2017-12-04 10:46:01 +01:00
|
|
|
|
_recent = recent;
|
2018-06-20 18:41:56 +02:00
|
|
|
|
ClearAllCommand = new RelayCommand(ClearAll);
|
2020-04-25 22:34:50 +02:00
|
|
|
|
PopulateRecentItems();
|
|
|
|
|
MessengerInstance.Register<FileNotFoundMessage>(this, _ => PopulateRecentItems());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateRecentItems()
|
|
|
|
|
{
|
2020-04-09 19:43:06 +02:00
|
|
|
|
var recentItems = _recent.GetAll().Select(r => new RecentItemVm(r));
|
2020-04-08 20:02:13 +02:00
|
|
|
|
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
2020-05-11 10:53:14 +02:00
|
|
|
|
if (RecentItems.Any()) SelectedIndex = 0;
|
2017-10-11 14:30:07 +02:00
|
|
|
|
}
|
2020-04-25 22:34:50 +02:00
|
|
|
|
|
2018-06-20 18:41:56 +02:00
|
|
|
|
private void ClearAll()
|
2017-12-04 10:46:01 +01:00
|
|
|
|
{
|
|
|
|
|
_recent.ClearAll();
|
|
|
|
|
RecentItems.Clear();
|
|
|
|
|
}
|
2021-05-10 20:28:13 +02:00
|
|
|
|
public override void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
MessengerInstance.Unregister(this);
|
|
|
|
|
base.Cleanup();
|
|
|
|
|
}
|
2017-09-29 17:23:35 -04:00
|
|
|
|
}
|
|
|
|
|
}
|