mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Refactor in file open mechanisms: file is passed to user control
Confirmation dialogs on group and entry delete
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
@@ -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);
|
||||
|
@@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user