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 System;
|
||||||
using Windows.ApplicationModel;
|
using Windows.ApplicationModel;
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
|
using Windows.Storage;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
@@ -16,15 +17,15 @@ namespace ModernKeePass
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed partial class App : Application
|
sealed partial class App : Application
|
||||||
{
|
{
|
||||||
public DatabaseHelper Database { get; set; }
|
public DatabaseHelper Database { get; set; } = new DatabaseHelper();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the singleton application object. This is the first line of authored code
|
/// 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().
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
InitializeComponent();
|
||||||
this.Suspending += OnSuspending;
|
Suspending += OnSuspending;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -38,11 +39,11 @@ namespace ModernKeePass
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (System.Diagnostics.Debugger.IsAttached)
|
if (System.Diagnostics.Debugger.IsAttached)
|
||||||
{
|
{
|
||||||
this.DebugSettings.EnableFrameRateCounter = true;
|
DebugSettings.EnableFrameRateCounter = true;
|
||||||
}
|
}
|
||||||
#endif
|
#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,
|
// Do not repeat app initialization when the Window already has content,
|
||||||
// just ensure that the window is active
|
// just ensure that the window is active
|
||||||
@@ -95,8 +96,18 @@ namespace ModernKeePass
|
|||||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||||
{
|
{
|
||||||
var deferral = e.SuspendingOperation.GetDeferral();
|
var deferral = e.SuspendingOperation.GetDeferral();
|
||||||
//TODO: Save application state and stop any background activity
|
Database.Save();
|
||||||
deferral.Complete();
|
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 System;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ModernKeePass.ViewModels;
|
using ModernKeePass.ViewModels;
|
||||||
using ModernKeePassLib;
|
using ModernKeePassLib;
|
||||||
using ModernKeePassLib.Interfaces;
|
using ModernKeePassLib.Interfaces;
|
||||||
@@ -11,18 +10,27 @@ namespace ModernKeePass.Common
|
|||||||
{
|
{
|
||||||
public class DatabaseHelper
|
public class DatabaseHelper
|
||||||
{
|
{
|
||||||
|
public enum DatabaseStatus
|
||||||
|
{
|
||||||
|
Closed = 0,
|
||||||
|
Opening = 1,
|
||||||
|
Opened = 2
|
||||||
|
}
|
||||||
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
||||||
private readonly StorageFile _databaseFile;
|
private StorageFile _databaseFile;
|
||||||
|
|
||||||
public GroupVm RootGroup { get; set; }
|
public GroupVm RootGroup { get; set; }
|
||||||
|
public DatabaseStatus Status { get; private set; } = DatabaseStatus.Closed;
|
||||||
public bool IsOpen => _pwDatabase.IsOpen;
|
public string Name => DatabaseFile.Name;
|
||||||
|
|
||||||
public string Name => _databaseFile.Name;
|
public StorageFile DatabaseFile
|
||||||
|
|
||||||
public DatabaseHelper(StorageFile databaseFile)
|
|
||||||
{
|
{
|
||||||
_databaseFile = databaseFile;
|
get { return _databaseFile; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_databaseFile = value;
|
||||||
|
Status = DatabaseStatus.Opening;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public string Open(string password)
|
public string Open(string password)
|
||||||
{
|
{
|
||||||
@@ -30,9 +38,13 @@ namespace ModernKeePass.Common
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
key.AddUserKey(new KcpPassword(password));
|
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)
|
catch (ArgumentNullException)
|
||||||
{
|
{
|
||||||
@@ -51,12 +63,14 @@ namespace ModernKeePass.Common
|
|||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
_pwDatabase.Save(new NullStatusLogger());
|
if (_pwDatabase != null && _pwDatabase.IsOpen)
|
||||||
|
_pwDatabase.Save(new NullStatusLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
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.System;
|
||||||
using Windows.UI.Core;
|
using Windows.UI.Core;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Input;
|
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
|
// 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 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)
|
private void OpenButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var app = (App)Application.Current;
|
var app = (App)Application.Current;
|
||||||
StatusTextBlock.Text = app.Database.Open(PasswordBox.Password);
|
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)
|
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\ColorToBrushConverter.cs" />
|
||||||
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
|
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
|
||||||
<Compile Include="Converters\PluralizationConverter.cs" />
|
<Compile Include="Converters\PluralizationConverter.cs" />
|
||||||
|
<Compile Include="Events\PasswordEventArgs.cs" />
|
||||||
<Compile Include="Interfaces\IIsEnabled.cs" />
|
<Compile Include="Interfaces\IIsEnabled.cs" />
|
||||||
<Compile Include="MainPage.xaml.cs">
|
<Compile Include="MainPage.xaml.cs">
|
||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
@@ -148,11 +149,12 @@
|
|||||||
<DependentUpon>SaveDatabasePage.xaml</DependentUpon>
|
<DependentUpon>SaveDatabasePage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ViewModels\DatabaseVm.cs" />
|
|
||||||
<Compile Include="ViewModels\EntryVm.cs" />
|
<Compile Include="ViewModels\EntryVm.cs" />
|
||||||
<Compile Include="ViewModels\GroupVm.cs" />
|
<Compile Include="ViewModels\GroupVm.cs" />
|
||||||
<Compile Include="ViewModels\MainVm.cs" />
|
<Compile Include="ViewModels\MainVm.cs" />
|
||||||
|
<Compile Include="ViewModels\OpenVm.cs" />
|
||||||
<Compile Include="ViewModels\RecentVm.cs" />
|
<Compile Include="ViewModels\RecentVm.cs" />
|
||||||
|
<Compile Include="ViewModels\SaveVm.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AppxManifest Include="Package.appxmanifest">
|
<AppxManifest Include="Package.appxmanifest">
|
||||||
|
@@ -28,6 +28,15 @@
|
|||||||
</SupportedFileTypes>
|
</SupportedFileTypes>
|
||||||
</FileOpenPicker>
|
</FileOpenPicker>
|
||||||
</Extension>
|
</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>
|
</Extensions>
|
||||||
</Application>
|
</Application>
|
||||||
</Applications>
|
</Applications>
|
||||||
|
@@ -5,16 +5,20 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||||
xmlns:local="using:ModernKeePass.Controls"
|
xmlns:local="using:ModernKeePass.Controls"
|
||||||
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
x:Class="ModernKeePass.Pages.OpenDatabasePage"
|
x:Class="ModernKeePass.Pages.OpenDatabasePage"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
<Page.Resources>
|
||||||
|
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||||
|
</Page.Resources>
|
||||||
<Page.DataContext>
|
<Page.DataContext>
|
||||||
<viewModels:DatabaseVm/>
|
<viewModels:OpenVm/>
|
||||||
</Page.DataContext>
|
</Page.DataContext>
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<HyperlinkButton Content="Browse files..." Click="ButtonBase_OnClick" />
|
<HyperlinkButton Content="Browse files..." Click="ButtonBase_OnClick" />
|
||||||
<HyperlinkButton Content="From Url..." IsEnabled="False" />
|
<HyperlinkButton Content="From Url..." IsEnabled="False" />
|
||||||
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
<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>
|
</StackPanel>
|
||||||
</Page>
|
</Page>
|
@@ -1,14 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using Windows.Storage.Pickers;
|
using Windows.Storage.Pickers;
|
||||||
using Windows.System;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Input;
|
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Events;
|
||||||
using ModernKeePass.ViewModels;
|
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
|
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
|
|
||||||
@@ -41,34 +37,15 @@ namespace ModernKeePass.Pages
|
|||||||
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
|
||||||
};
|
};
|
||||||
picker.FileTypeFilter.Add(".kdbx");
|
picker.FileTypeFilter.Add(".kdbx");
|
||||||
|
|
||||||
var file = await picker.PickSingleFileAsync();
|
var viewModel = DataContext as OpenVm;
|
||||||
// Application now has read/write access to the picked file
|
// Application now has read/write access to the picked file
|
||||||
if (file == null) return;
|
viewModel.OpenFile(await picker.PickSingleFileAsync());
|
||||||
// Initialize KDBX database
|
|
||||||
((App)Application.Current).Database = new DatabaseHelper(file);
|
|
||||||
AddToRecentFiles(file);
|
|
||||||
ShowPassword(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddToRecentFiles(StorageFile file)
|
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
||||||
{
|
{
|
||||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
_mainFrame.Navigate(typeof(GroupDetailPage), e.RootGroup);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,6 @@
|
|||||||
<ListView
|
<ListView
|
||||||
Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
|
Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
|
||||||
ItemsSource="{Binding Source={StaticResource RecentItemsSource}}"
|
ItemsSource="{Binding Source={StaticResource RecentItemsSource}}"
|
||||||
SelectionChanged="RecentListView_SelectionChanged"
|
|
||||||
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
|
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
|
@@ -6,6 +6,7 @@ using Windows.UI.Xaml;
|
|||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
|
using ModernKeePass.Events;
|
||||||
using ModernKeePass.ViewModels;
|
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
|
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
@@ -29,23 +30,10 @@ namespace ModernKeePass.Pages
|
|||||||
base.OnNavigatedTo(e);
|
base.OnNavigatedTo(e);
|
||||||
_mainFrame = e.Parameter as Frame;
|
_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;
|
_mainFrame.Navigate(typeof(GroupDetailPage), e.RootGroup);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,11 +8,11 @@
|
|||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
<Page.DataContext>
|
<Page.DataContext>
|
||||||
<viewModels:DatabaseVm/>
|
<viewModels:SaveVm/>
|
||||||
</Page.DataContext>
|
</Page.DataContext>
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
<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" />
|
<HyperlinkButton x:Name="SaveAsButton" Content="Save as..." VerticalAlignment="Top" IsEnabled="False" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Page>
|
</Page>
|
||||||
|
@@ -22,25 +22,13 @@ namespace ModernKeePass.Pages
|
|||||||
{
|
{
|
||||||
base.OnNavigatedTo(e);
|
base.OnNavigatedTo(e);
|
||||||
_mainFrame = e.Parameter as Frame;
|
_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)
|
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var app = (App) Application.Current;
|
var viewModel = DataContext as SaveVm;
|
||||||
app.Database.Save();
|
viewModel.Save();
|
||||||
app.Database.Close();
|
|
||||||
UpdateDatabaseStatus(app, DataContext as DatabaseVm);
|
|
||||||
_mainFrame.Navigate(typeof(MainPage));
|
_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>
|
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 = "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
|
||||||
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}
|
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
|
// Auto-select the Recent Items menu item if the conditions are met
|
||||||
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
|
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
|
mainMenuItems.Add(new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = app.Database.Name,
|
Title = app.Database.Name,
|
||||||
@@ -66,7 +76,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
Group = 1,
|
Group = 1,
|
||||||
SymbolIcon = Symbol.ProtectedDocument
|
SymbolIcon = Symbol.ProtectedDocument
|
||||||
});
|
});
|
||||||
|
|
||||||
MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 System.Linq;
|
||||||
using Windows.Storage.AccessCache;
|
using Windows.Storage.AccessCache;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
@@ -43,6 +45,11 @@ namespace ModernKeePass.ViewModels
|
|||||||
{
|
{
|
||||||
_selectedItem.IsSelected = true;
|
_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