mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
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:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
@@ -16,15 +17,15 @@ namespace ModernKeePass
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
public DatabaseHelper Database { get; set; }
|
||||
public DatabaseHelper Database { get; set; } = new DatabaseHelper();
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Suspending += OnSuspending;
|
||||
InitializeComponent();
|
||||
Suspending += OnSuspending;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,11 +39,11 @@ namespace ModernKeePass
|
||||
#if DEBUG
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
this.DebugSettings.EnableFrameRateCounter = true;
|
||||
DebugSettings.EnableFrameRateCounter = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
Frame rootFrame = Window.Current.Content as Frame;
|
||||
var rootFrame = Window.Current.Content as Frame;
|
||||
|
||||
// Do not repeat app initialization when the Window already has content,
|
||||
// just ensure that the window is active
|
||||
@@ -95,8 +96,18 @@ namespace ModernKeePass
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
//TODO: Save application state and stop any background activity
|
||||
Database.Save();
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
protected override void OnFileActivated(FileActivatedEventArgs args)
|
||||
{
|
||||
base.OnFileActivated(args);
|
||||
Database.DatabaseFile = args.Files[0] as StorageFile;
|
||||
var rootFrame = new Frame();
|
||||
rootFrame.Navigate(typeof(MainPage), args);
|
||||
Window.Current.Content = rootFrame;
|
||||
Window.Current.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Windows.Storage;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.ViewModels;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Interfaces;
|
||||
@@ -11,18 +10,27 @@ namespace ModernKeePass.Common
|
||||
{
|
||||
public class DatabaseHelper
|
||||
{
|
||||
public enum DatabaseStatus
|
||||
{
|
||||
Closed = 0,
|
||||
Opening = 1,
|
||||
Opened = 2
|
||||
}
|
||||
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
||||
private readonly StorageFile _databaseFile;
|
||||
private StorageFile _databaseFile;
|
||||
|
||||
public GroupVm RootGroup { get; set; }
|
||||
public DatabaseStatus Status { get; private set; } = DatabaseStatus.Closed;
|
||||
public string Name => DatabaseFile.Name;
|
||||
|
||||
public bool IsOpen => _pwDatabase.IsOpen;
|
||||
|
||||
public string Name => _databaseFile.Name;
|
||||
|
||||
public DatabaseHelper(StorageFile databaseFile)
|
||||
public StorageFile DatabaseFile
|
||||
{
|
||||
_databaseFile = databaseFile;
|
||||
get { return _databaseFile; }
|
||||
set
|
||||
{
|
||||
_databaseFile = value;
|
||||
Status = DatabaseStatus.Opening;
|
||||
}
|
||||
}
|
||||
public string Open(string password)
|
||||
{
|
||||
@@ -30,9 +38,13 @@ namespace ModernKeePass.Common
|
||||
try
|
||||
{
|
||||
key.AddUserKey(new KcpPassword(password));
|
||||
_pwDatabase.Open(IOConnectionInfo.FromFile(_databaseFile), key, new NullStatusLogger());
|
||||
_pwDatabase.Open(IOConnectionInfo.FromFile(DatabaseFile), key, new NullStatusLogger());
|
||||
|
||||
if (IsOpen) RootGroup = new GroupVm(_pwDatabase.RootGroup, null);
|
||||
if (_pwDatabase.IsOpen)
|
||||
{
|
||||
Status = DatabaseStatus.Opened;
|
||||
RootGroup = new GroupVm(_pwDatabase.RootGroup, null);
|
||||
}
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
@@ -51,12 +63,14 @@ namespace ModernKeePass.Common
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (_pwDatabase != null && _pwDatabase.IsOpen)
|
||||
_pwDatabase.Save(new NullStatusLogger());
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_pwDatabase.Close();
|
||||
_pwDatabase?.Close();
|
||||
Status = DatabaseStatus.Closed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.System;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Events;
|
||||
|
||||
// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
@@ -18,13 +19,14 @@ namespace ModernKeePass.Controls
|
||||
}
|
||||
|
||||
public event PasswordCheckedEventHandler ValidationChecked;
|
||||
public delegate void PasswordCheckedEventHandler(object sender, EventArgs e);
|
||||
public delegate void PasswordCheckedEventHandler(object sender, PasswordEventArgs e);
|
||||
|
||||
private void OpenButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
StatusTextBlock.Text = app.Database.Open(PasswordBox.Password);
|
||||
ValidationChecked?.Invoke(this, new EventArgs());
|
||||
if (app.Database.Status == DatabaseHelper.DatabaseStatus.Opened)
|
||||
ValidationChecked?.Invoke(this, new PasswordEventArgs(app.Database.RootGroup));
|
||||
}
|
||||
|
||||
private void PasswordBox_KeyDown(object sender, KeyRoutedEventArgs e)
|
||||
|
15
ModernKeePass/Events/PasswordEventArgs.cs
Normal file
15
ModernKeePass/Events/PasswordEventArgs.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
namespace ModernKeePass.Events
|
||||
{
|
||||
public class PasswordEventArgs: EventArgs
|
||||
{
|
||||
public GroupVm RootGroup { get; set; }
|
||||
|
||||
public PasswordEventArgs(GroupVm groupVm)
|
||||
{
|
||||
RootGroup = groupVm;
|
||||
}
|
||||
}
|
||||
}
|
@@ -125,6 +125,7 @@
|
||||
<Compile Include="Converters\ColorToBrushConverter.cs" />
|
||||
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
|
||||
<Compile Include="Converters\PluralizationConverter.cs" />
|
||||
<Compile Include="Events\PasswordEventArgs.cs" />
|
||||
<Compile Include="Interfaces\IIsEnabled.cs" />
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
@@ -148,11 +149,12 @@
|
||||
<DependentUpon>SaveDatabasePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewModels\DatabaseVm.cs" />
|
||||
<Compile Include="ViewModels\EntryVm.cs" />
|
||||
<Compile Include="ViewModels\GroupVm.cs" />
|
||||
<Compile Include="ViewModels\MainVm.cs" />
|
||||
<Compile Include="ViewModels\OpenVm.cs" />
|
||||
<Compile Include="ViewModels\RecentVm.cs" />
|
||||
<Compile Include="ViewModels\SaveVm.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
|
@@ -28,6 +28,15 @@
|
||||
</SupportedFileTypes>
|
||||
</FileOpenPicker>
|
||||
</Extension>
|
||||
<Extension Category="windows.fileTypeAssociation">
|
||||
<FileTypeAssociation Name="kdbx">
|
||||
<DisplayName>KeePass 2.x database</DisplayName>
|
||||
<EditFlags OpenIsSafe="true" />
|
||||
<SupportedFileTypes>
|
||||
<FileType ContentType="application/xml">.kdbx</FileType>
|
||||
</SupportedFileTypes>
|
||||
</FileTypeAssociation>
|
||||
</Extension>
|
||||
</Extensions>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
@@ -5,16 +5,20 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:local="using:ModernKeePass.Controls"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
x:Class="ModernKeePass.Pages.OpenDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
</Page.Resources>
|
||||
<Page.DataContext>
|
||||
<viewModels:DatabaseVm/>
|
||||
<viewModels:OpenVm/>
|
||||
</Page.DataContext>
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton Content="Browse files..." Click="ButtonBase_OnClick" />
|
||||
<HyperlinkButton Content="From Url..." IsEnabled="False" />
|
||||
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||
<local:OpenDatabaseUserControl Visibility="{Binding SelectedVisibility}" ValidationChecked="PasswordUserControl_PasswordChecked" />
|
||||
<local:OpenDatabaseUserControl Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}" ValidationChecked="PasswordUserControl_PasswordChecked" />
|
||||
</StackPanel>
|
||||
</Page>
|
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Events;
|
||||
using ModernKeePass.ViewModels;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.Storage;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
@@ -42,33 +38,14 @@ namespace ModernKeePass.Pages
|
||||
};
|
||||
picker.FileTypeFilter.Add(".kdbx");
|
||||
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
var viewModel = DataContext as OpenVm;
|
||||
// Application now has read/write access to the picked file
|
||||
if (file == null) return;
|
||||
// Initialize KDBX database
|
||||
((App)Application.Current).Database = new DatabaseHelper(file);
|
||||
AddToRecentFiles(file);
|
||||
ShowPassword(file);
|
||||
viewModel.OpenFile(await picker.PickSingleFileAsync());
|
||||
}
|
||||
|
||||
private void AddToRecentFiles(StorageFile file)
|
||||
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
||||
{
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
mru.Add(file, file.DisplayName);
|
||||
}
|
||||
|
||||
private void ShowPassword(StorageFile file)
|
||||
{
|
||||
var databaseVm = DataContext as DatabaseVm;
|
||||
if (databaseVm == null) return;
|
||||
databaseVm.SelectedVisibility = Visibility.Visible;
|
||||
databaseVm.Name = file.Name;
|
||||
}
|
||||
|
||||
private void PasswordUserControl_PasswordChecked(object sender, EventArgs e)
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
if (app.Database.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
|
||||
_mainFrame.Navigate(typeof(GroupDetailPage), e.RootGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@
|
||||
<ListView
|
||||
Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
|
||||
ItemsSource="{Binding Source={StaticResource RecentItemsSource}}"
|
||||
SelectionChanged="RecentListView_SelectionChanged"
|
||||
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
@@ -6,6 +6,7 @@ using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
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
|
||||
@@ -30,22 +31,9 @@ namespace ModernKeePass.Pages
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
}
|
||||
|
||||
private async void RecentListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
||||
{
|
||||
var recentVm = DataContext as RecentVm;
|
||||
if (recentVm.SelectedItem == null) return;
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var file = await mru.GetFileAsync(recentVm.SelectedItem.Token);
|
||||
|
||||
// TODO: this closes the current opened database
|
||||
var app = (App)Application.Current;
|
||||
app.Database = new DatabaseHelper(file);
|
||||
}
|
||||
|
||||
private void PasswordUserControl_PasswordChecked(object sender, EventArgs e)
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
if (app.Database.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
|
||||
_mainFrame.Navigate(typeof(GroupDetailPage), e.RootGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,11 +8,11 @@
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Page.DataContext>
|
||||
<viewModels:DatabaseVm/>
|
||||
<viewModels:SaveVm/>
|
||||
</Page.DataContext>
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton x:Name="SaveButton" Content="Save and close" Click="SaveButton_OnClick" VerticalAlignment="Top" IsEnabled="{Binding IsOpen}" />
|
||||
<HyperlinkButton x:Name="SaveButton" Content="Save and close" Click="SaveButton_OnClick" VerticalAlignment="Top" IsEnabled="{Binding IsSaveEnabled}" />
|
||||
<HyperlinkButton x:Name="SaveAsButton" Content="Save as..." VerticalAlignment="Top" IsEnabled="False" />
|
||||
</StackPanel>
|
||||
</Page>
|
||||
|
@@ -22,25 +22,13 @@ namespace ModernKeePass.Pages
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
var app = (App)Application.Current;
|
||||
if (app.Database == null) return;
|
||||
var databaseVm = DataContext as DatabaseVm;
|
||||
if (databaseVm == null) return;
|
||||
UpdateDatabaseStatus(app, databaseVm);
|
||||
}
|
||||
|
||||
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var app = (App) Application.Current;
|
||||
app.Database.Save();
|
||||
app.Database.Close();
|
||||
UpdateDatabaseStatus(app, DataContext as DatabaseVm);
|
||||
var viewModel = DataContext as SaveVm;
|
||||
viewModel.Save();
|
||||
_mainFrame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
private void UpdateDatabaseStatus(App app, DatabaseVm databaseVm)
|
||||
{
|
||||
databaseVm.IsOpen = app.Database.IsOpen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,29 +0,0 @@
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class DatabaseVm : NotifyPropertyChangedBase
|
||||
{
|
||||
private string _name;
|
||||
private Visibility _selectedVisibility = Visibility.Collapsed;
|
||||
private bool _isOpen;
|
||||
|
||||
public Visibility SelectedVisibility
|
||||
{
|
||||
get { return _selectedVisibility; }
|
||||
set { SetProperty(ref _selectedVisibility, value); }
|
||||
}
|
||||
|
||||
public bool IsOpen
|
||||
{
|
||||
get { return _isOpen; }
|
||||
set { SetProperty(ref _isOpen, value); }
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get { return string.IsNullOrEmpty(_name) ? string.Empty : $"Database {_name} selected"; }
|
||||
set { SetProperty(ref _name, value); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,15 +48,25 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
|
||||
{
|
||||
new MainMenuItemVm {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Page2},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = "Open", PageType = typeof(OpenDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Page2,
|
||||
IsSelected = app.Database.Status == DatabaseHelper.DatabaseStatus.Opening
|
||||
},
|
||||
new MainMenuItemVm {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = destinationFrame, SymbolIcon = Symbol.Add},
|
||||
new MainMenuItemVm {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Save},
|
||||
new MainMenuItemVm {Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Copy,
|
||||
IsSelected = (app.Database == null || !app.Database.IsOpen) && mru.Entries.Count > 0}
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Save,
|
||||
IsSelected = app.Database != null && app.Database.Status == DatabaseHelper.DatabaseStatus.Opened
|
||||
},
|
||||
new MainMenuItemVm {
|
||||
Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Copy,
|
||||
IsSelected = (app.Database == null || app.Database.Status == DatabaseHelper.DatabaseStatus.Closed) && mru.Entries.Count > 0
|
||||
}
|
||||
};
|
||||
// Auto-select the Recent Items menu item if the conditions are met
|
||||
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
|
||||
if (app.Database != null && app.Database.IsOpen)
|
||||
if (app.Database != null && app.Database.Status == DatabaseHelper.DatabaseStatus.Opened)
|
||||
mainMenuItems.Add(new MainMenuItemVm
|
||||
{
|
||||
Title = app.Database.Name,
|
||||
|
50
ModernKeePass/ViewModels/OpenVm.cs
Normal file
50
ModernKeePass/ViewModels/OpenVm.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
@@ -43,6 +45,11 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
_selectedItem.IsSelected = true;
|
||||
}
|
||||
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var file = mru.GetFileAsync(SelectedItem.Token).GetAwaiter().GetResult();
|
||||
var app = (App)Application.Current;
|
||||
app.Database.DatabaseFile = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
33
ModernKeePass/ViewModels/SaveVm.cs
Normal file
33
ModernKeePass/ViewModels/SaveVm.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.ComponentModel;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SaveVm: INotifyPropertyChanged
|
||||
{
|
||||
public bool IsSaveEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
return app.Database.Status == DatabaseHelper.DatabaseStatus.Opened;
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public void Save(bool close = true)
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
app.Database.Save();
|
||||
if (!close) return;
|
||||
app.Database.Close();
|
||||
NotifyPropertyChanged("IsSaveEnabled");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user