Open file from Explorer with association works

Major code refactor in Open, Save and Recent pages and VM
Main page automatically opens a sub page depending on context
This commit is contained in:
2017-10-10 15:00:31 +02:00
committed by BONNEVILLE Geoffroy
parent 98ecb0b8a1
commit ec4f2e7d88
17 changed files with 205 additions and 125 deletions

View File

@@ -0,0 +1,50 @@
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 bool ShowPasswordBox
{
get { return ((App) Application.Current).Database.Status == DatabaseHelper.DatabaseStatus.Opening; }
}
public string Name
{
get { return ((App) Application.Current).Database.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)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void OpenFile(StorageFile file)
{
var database = ((App)Application.Current).Database;
database.DatabaseFile = file;
NotifyPropertyChanged("Name");
NotifyPropertyChanged("ShowPasswordBox");
AddToRecentList(file);
}
private void AddToRecentList(StorageFile file)
{
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
mru.Add(file, file.DisplayName);
}
}
}