Refactor in file open mechanisms: file is passed to user control

Confirmation dialogs on group and entry delete
This commit is contained in:
2017-10-11 14:30:07 +02:00
committed by BONNEVILLE Geoffroy
parent 454e074c44
commit 97b1475100
12 changed files with 124 additions and 62 deletions

View File

@@ -1,4 +1,5 @@
using ModernKeePass.Common;
using Windows.Storage;
using ModernKeePass.Common;
namespace ModernKeePass.ViewModels
{
@@ -7,6 +8,7 @@ namespace ModernKeePass.ViewModels
private bool _isSelected;
public string Token { get; set; }
public string Name { get; set; }
public StorageFile File { get; set; }
public bool IsSelected
{

View File

@@ -1,31 +1,24 @@
using System.ComponentModel;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml;
using ModernKeePass.Common;
namespace ModernKeePass.ViewModels
{
public class OpenVm: INotifyPropertyChanged
{
public StorageFile File { get; set; }
public bool ShowPasswordBox
{
get { return ((App) Application.Current).Database.Status == DatabaseHelper.DatabaseStatus.Opening; }
get { return File != null; }
}
public string Name
{
get { return ((App) Application.Current).Database.Name; }
get { return File?.Name; }
}
public event PropertyChangedEventHandler PropertyChanged;
public OpenVm()
{
var database = ((App) Application.Current).Database;
if (database == null || database.Status != DatabaseHelper.DatabaseStatus.Opening) return;
OpenFile(database.DatabaseFile);
}
private void NotifyPropertyChanged(string propertyName)
{
@@ -34,8 +27,7 @@ namespace ModernKeePass.ViewModels
public void OpenFile(StorageFile file)
{
var database = ((App)Application.Current).Database;
database.DatabaseFile = file;
File = file;
NotifyPropertyChanged("Name");
NotifyPropertyChanged("ShowPasswordBox");
AddToRecentList(file);

View File

@@ -2,7 +2,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml;
using ModernKeePass.Common;
namespace ModernKeePass.ViewModels
@@ -11,17 +10,7 @@ namespace ModernKeePass.ViewModels
{
private RecentItemVm _selectedItem;
private ObservableCollection<RecentItemVm> _recentItems;
public RecentVm()
{
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
RecentItems = new ObservableCollection<RecentItemVm>(
from entry in mru.Entries
select new RecentItemVm { Name = entry.Metadata, Token = entry.Token });
if (RecentItems.Count > 0)
SelectedItem = RecentItems[0];
}
public ObservableCollection<RecentItemVm> RecentItems
{
get { return _recentItems; }
@@ -47,10 +36,19 @@ namespace ModernKeePass.ViewModels
}
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
var file = mru.GetFileAsync(SelectedItem.Token).GetAwaiter().GetResult();
var app = (App)Application.Current;
app.Database.DatabaseFile = file;
_selectedItem.File = mru.GetFileAsync(SelectedItem.Token).GetAwaiter().GetResult();
}
}
public RecentVm()
{
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
RecentItems = new ObservableCollection<RecentItemVm>(
from entry in mru.Entries
select new RecentItemVm { Name = entry.Metadata, Token = entry.Token });
if (RecentItems.Count > 0)
SelectedItem = RecentItems[0];
}
}
}