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:
@@ -23,6 +23,7 @@ namespace ModernKeePass.Views
|
||||
private new void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
base.ListView_SelectionChanged(sender, e);
|
||||
|
||||
var selectedItem = Model.SelectedItem as MainMenuItemVm;
|
||||
if (selectedItem == null) MenuFrame.Navigate(typeof(WelcomePage));
|
||||
else selectedItem.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter);
|
||||
|
@@ -23,7 +23,7 @@
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<StackPanel Margin="25,0,25,0">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<userControls:CompositeKeyUserControl CreateNew="True" x:Uid="CompositeKeyNewButton">
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFile="{Binding DatabaseFile}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />
|
||||
|
@@ -24,7 +24,7 @@
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<StackPanel Margin="25,0,25,0">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton">
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFile="{Binding DatabaseFile}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<Core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<Core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
@@ -14,8 +14,6 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class OpenDatabasePage
|
||||
{
|
||||
private Frame _mainFrame;
|
||||
|
||||
public OpenVm Model => (OpenVm)DataContext;
|
||||
|
||||
public OpenDatabasePage()
|
||||
@@ -26,7 +24,11 @@ namespace ModernKeePass.Views
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
var file = e.Parameter as StorageFile;
|
||||
if (file != null)
|
||||
{
|
||||
Model.OpenFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||
|
@@ -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