mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP removing global databaseFile property
This commit is contained in:
@@ -45,8 +45,8 @@
|
||||
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToForegroungBrushConverter}}"
|
||||
Visibility="{Binding ShowComplexityIndicator, ElementName=UserControl, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0" Content="{Binding KeyFileText}" IsEnabled="{Binding HasKeyFile}" Click="KeyFileButton_Click" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Visibility="{Binding ShowComplexityIndicator, ElementName=UserControl, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding HasKeyFile}" Click="CreateKeyFileButton_Click">
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0" Content="{Binding KeyFileText}" IsEnabled="{Binding HasKeyFile}" Click="KeyFileButton_Click" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Visibility="{Binding ShowComplexityIndicator, ElementName=UserControl, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding HasKeyFile}" Style="{StaticResource MainColorHyperlinkButton}" Click="CreateKeyFileButton_Click">
|
||||
<SymbolIcon Symbol="Add">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip x:Uid="CompositeKeyNewKeyFileTooltip" />
|
||||
|
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Events;
|
||||
using ModernKeePass.Extensions;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
@@ -53,6 +57,17 @@ namespace ModernKeePass.Views.UserControls
|
||||
typeof(CompositeKeyUserControl),
|
||||
new PropertyMetadata("OK", (o, args) => { }));
|
||||
|
||||
public StorageFile DatabaseFile
|
||||
{
|
||||
get { return (StorageFile)GetValue(DatabaseFileProperty); }
|
||||
set { SetValue(DatabaseFileProperty, value); }
|
||||
}
|
||||
public static readonly DependencyProperty DatabaseFileProperty =
|
||||
DependencyProperty.Register(
|
||||
"DatabaseFile",
|
||||
typeof(StorageFile),
|
||||
typeof(CompositeKeyUserControl),
|
||||
new PropertyMetadata(null, (o, args) => { }));
|
||||
|
||||
public bool ShowComplexityIndicator => CreateNew || UpdateKey;
|
||||
|
||||
@@ -77,14 +92,30 @@ namespace ModernKeePass.Views.UserControls
|
||||
}
|
||||
else
|
||||
{
|
||||
var database = DatabaseService.Instance;
|
||||
var resource = new ResourcesService();
|
||||
var oldLabel = ButtonLabel;
|
||||
ButtonLabel = resource.GetResourceValue("CompositeKeyOpening");
|
||||
if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(CreateNew)))
|
||||
if (database.IsOpen)
|
||||
{
|
||||
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
|
||||
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("MessageDialogDBOpenTitle"),
|
||||
string.Format(resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
|
||||
resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
|
||||
resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
|
||||
async command =>
|
||||
{
|
||||
database.Save();
|
||||
database.Close(false);
|
||||
await OpenDatabase(resource);
|
||||
},
|
||||
async command =>
|
||||
{
|
||||
database.Close(false);
|
||||
await OpenDatabase(resource);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await OpenDatabase(resource);
|
||||
}
|
||||
ButtonLabel = oldLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,5 +159,17 @@ namespace ModernKeePass.Views.UserControls
|
||||
|
||||
Model.CreateKeyFile(file);
|
||||
}
|
||||
|
||||
private async Task OpenDatabase(IResourceService resource)
|
||||
{
|
||||
var oldLabel = ButtonLabel;
|
||||
ButtonLabel = resource.GetResourceValue("CompositeKeyOpening");
|
||||
if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(DatabaseFile, CreateNew)))
|
||||
{
|
||||
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
|
||||
}
|
||||
|
||||
ButtonLabel = oldLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user