mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
Recent items list auto removes non existing files
Choosing a recent list item does not change the database file anymore
This commit is contained in:
@@ -21,7 +21,7 @@ namespace ModernKeePass.Common
|
||||
|
||||
public GroupVm RootGroup { get; set; }
|
||||
public DatabaseStatus Status { get; private set; } = DatabaseStatus.Closed;
|
||||
public string Name => _pwDatabase?.Name;
|
||||
public string Name => DatabaseFile?.Name;
|
||||
|
||||
public StorageFile DatabaseFile
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.System;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
@@ -30,11 +31,14 @@ namespace ModernKeePass.Controls
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event PasswordCheckingEventHandler ValidationChecking;
|
||||
public delegate void PasswordCheckingEventHandler(object sender, EventArgs e);
|
||||
public event PasswordCheckedEventHandler ValidationChecked;
|
||||
public delegate void PasswordCheckedEventHandler(object sender, PasswordEventArgs e);
|
||||
|
||||
private void OpenButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ValidationChecking?.Invoke(this, new EventArgs());
|
||||
var app = (App)Application.Current;
|
||||
StatusTextBlock.Text = app.Database.Open(PasswordBox.Password, CreateNew);
|
||||
if (app.Database.Status == DatabaseHelper.DatabaseStatus.Opened)
|
||||
|
@@ -22,8 +22,9 @@
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Margin="10,0,10,0">
|
||||
<TextBlock Text="{Binding Name}" Width="350" Padding="5" />
|
||||
<local:OpenDatabaseUserControl Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" ValidationChecked="PasswordUserControl_PasswordChecked" />
|
||||
<TextBlock Text="{Binding Name}" Width="350" Padding="5,0,0,0" />
|
||||
<TextBlock Text="{Binding Path}" Width="350" Padding="5,0,0,0" FontSize="10" />
|
||||
<local:OpenDatabaseUserControl Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" ValidationChecking="OpenDatabaseUserControl_OnValidationChecking" ValidationChecked="PasswordUserControl_PasswordChecked" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
@@ -1,6 +1,9 @@
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Events;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
@@ -28,5 +31,13 @@ namespace ModernKeePass.Pages
|
||||
{
|
||||
_mainFrame.Navigate(typeof(GroupDetailPage), e.RootGroup);
|
||||
}
|
||||
|
||||
private void OpenDatabaseUserControl_OnValidationChecking(object sender, EventArgs e)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
var viewModel = DataContext as RecentVm;
|
||||
var app = (App)Application.Current;
|
||||
app.Database.DatabaseFile = viewModel.SelectedItem.DatabaseFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,25 @@
|
||||
using Windows.Storage;
|
||||
using System;
|
||||
using Windows.Storage;
|
||||
using ModernKeePass.Common;
|
||||
using Windows.Storage.AccessCache;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class RecentItemVm: NotifyPropertyChangedBase
|
||||
{
|
||||
private bool _isSelected;
|
||||
public string Token { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public RecentItemVm(AccessListEntry entry, StorageFile file)
|
||||
{
|
||||
Token = entry.Token;
|
||||
Name = entry.Metadata;
|
||||
DatabaseFile = file;
|
||||
}
|
||||
|
||||
public StorageFile DatabaseFile { get; private set; }
|
||||
public string Token { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Path => DatabaseFile.Path;
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
|
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
@@ -10,7 +8,7 @@ namespace ModernKeePass.ViewModels
|
||||
public class RecentVm : NotifyPropertyChangedBase
|
||||
{
|
||||
private RecentItemVm _selectedItem;
|
||||
private ObservableCollection<RecentItemVm> _recentItems;
|
||||
private ObservableCollection<RecentItemVm> _recentItems = new ObservableCollection<RecentItemVm>();
|
||||
|
||||
public ObservableCollection<RecentItemVm> RecentItems
|
||||
{
|
||||
@@ -30,30 +28,27 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
|
||||
SetProperty(ref _selectedItem, value);
|
||||
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.IsSelected = true;
|
||||
}
|
||||
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var database = ((App)Application.Current).Database;
|
||||
try
|
||||
{
|
||||
database.DatabaseFile = mru.GetFileAsync(SelectedItem.Token).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
if (_selectedItem == null) return;
|
||||
_selectedItem.IsSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
public RecentVm()
|
||||
{
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
RecentItems = new ObservableCollection<RecentItemVm>(
|
||||
from entry in mru.Entries
|
||||
select new RecentItemVm { Name = entry.Metadata, Token = entry.Token });
|
||||
foreach (var entry in mru.Entries)
|
||||
{
|
||||
try
|
||||
{
|
||||
var file = mru.GetFileAsync(entry.Token).GetAwaiter().GetResult();
|
||||
RecentItems.Add(new RecentItemVm(entry, file));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
mru.Remove(entry.Token);
|
||||
}
|
||||
}
|
||||
if (RecentItems.Count > 0)
|
||||
SelectedItem = RecentItems[0];
|
||||
}
|
||||
|
Reference in New Issue
Block a user