Files
modernkeepass/ModernKeePass/ViewModels/OpenVm.cs
BONNEVILLE Geoffroy fcbda1e33d Adds some VM tests
New tooltip in Textbox with button control
New welcome page in Settings (shown when noting is selected)
Settings are now grouped
2017-11-27 15:26:36 +01:00

41 lines
1.2 KiB
C#

using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
namespace ModernKeePass.ViewModels
{
public class OpenVm: NotifyPropertyChangedBase
{
public bool ShowPasswordBox => _database?.Status == (int) DatabaseHelper.DatabaseStatus.Opening;
public string Name => _database?.Name;
private readonly IDatabase _database;
public OpenVm() : this((Application.Current as App)?.Database) { }
public OpenVm(IDatabase database)
{
_database = database;
if (database == null || database.Status != (int) DatabaseHelper.DatabaseStatus.Opening) return;
OpenFile(database.DatabaseFile);
}
public void OpenFile(StorageFile file)
{
_database.DatabaseFile = file;
OnPropertyChanged("Name");
OnPropertyChanged("ShowPasswordBox");
AddToRecentList(file);
}
private void AddToRecentList(StorageFile file)
{
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
mru.Add(file, file.DisplayName);
}
}
}