mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Create database works with new Vm
Refactoring
This commit is contained in:
@@ -12,12 +12,9 @@
|
||||
<UserControl.Resources>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
<viewModels:OpenDatabaseControlVm x:Key="ViewModel"/>
|
||||
</UserControl.Resources>
|
||||
<Grid x:Name="Grid">
|
||||
<!-- DataContext is not set at the root of the control because of issues happening when displaying it -->
|
||||
<Grid.DataContext>
|
||||
<viewModels:OpenDatabaseControlVm />
|
||||
</Grid.DataContext>
|
||||
<Grid DataContext="{StaticResource ViewModel}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="*" />
|
||||
|
@@ -12,8 +12,8 @@ namespace ModernKeePass.Views.UserControls
|
||||
{
|
||||
public sealed partial class OpenDatabaseUserControl
|
||||
{
|
||||
public OpenDatabaseControlVm Model => Grid.DataContext as OpenDatabaseControlVm;
|
||||
|
||||
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Resources["ViewModel"];
|
||||
|
||||
public string DatabaseFilePath
|
||||
{
|
||||
get { return (string)GetValue(DatabaseFilePathProperty); }
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<UserControl x:Name="UserControl"
|
||||
x:Class="ModernKeePass.Views.UserControls.UpdateCredentialsUserControl"
|
||||
x:Class="ModernKeePass.Views.UserControls.SetCredentialsUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@@ -14,17 +14,15 @@
|
||||
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
<viewModels:SetCredentialsViewModel x:Key="ViewModel"/>
|
||||
</UserControl.Resources>
|
||||
<Grid x:Name="Grid">
|
||||
<!-- DataContext is not set at the root of the control because of issues happening when displaying it -->
|
||||
<Grid.DataContext>
|
||||
<viewModels:SetCredentialsViewModel />
|
||||
</Grid.DataContext>
|
||||
<Grid DataContext="{StaticResource ViewModel}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="45" />
|
||||
<RowDefinition Height="45" />
|
||||
<RowDefinition Height="40" />
|
||||
<RowDefinition Height="40" />
|
||||
@@ -38,19 +36,19 @@
|
||||
</core:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</PasswordBox>
|
||||
<PasswordBox Grid.Row="0" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding Password, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" BorderBrush="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" SelectionHighlightColor="{StaticResource MainColor}" />
|
||||
<ProgressBar Grid.Row="0" Grid.Column="1"
|
||||
<PasswordBox Grid.Row="1" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding ConfirmPassword, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" BorderBrush="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" SelectionHighlightColor="{StaticResource MainColor}" />
|
||||
<ProgressBar Grid.Row="1" Grid.Column="1"
|
||||
Maximum="128" VerticalAlignment="Bottom"
|
||||
Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}, Mode=OneWay}"
|
||||
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToSolidColorBrushConverter}, Mode=OneWay}"/>
|
||||
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
|
||||
Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}}"
|
||||
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToSolidColorBrushConverter}}"/>
|
||||
<CheckBox Grid.Row="2" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0"
|
||||
Content="{Binding KeyFileText, Mode=OneWay}"
|
||||
IsEnabled="{Binding HasKeyFile, Mode=OneWay}"
|
||||
Content="{Binding KeyFileText}"
|
||||
IsEnabled="{Binding HasKeyFile}"
|
||||
Click="KeyFileButton_Click"
|
||||
Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right"
|
||||
IsEnabled="{Binding HasKeyFile, Mode=OneWay}"
|
||||
<HyperlinkButton Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right"
|
||||
IsEnabled="{Binding HasKeyFile}"
|
||||
Style="{StaticResource MainColorHyperlinkButton}"
|
||||
Click="CreateKeyFileButton_Click">
|
||||
<SymbolIcon Symbol="Add">
|
||||
@@ -59,14 +57,13 @@
|
||||
</ToolTipService.ToolTip>
|
||||
</SymbolIcon>
|
||||
</HyperlinkButton>
|
||||
<Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2"
|
||||
<Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3"
|
||||
Command="{Binding GenerateCredentialsCommand}"
|
||||
Content="{Binding ButtonLabel, ElementName=UserControl}"
|
||||
Click="UpdateButton_OnClick"
|
||||
Style="{StaticResource MainColorButton}"
|
||||
IsEnabled="{Binding IsValid, Mode=OneWay}" />
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Height="Auto" FontSize="14" FontWeight="Light"
|
||||
Text="{Binding Status, Mode=OneWay}"
|
||||
Foreground="{Binding StatusType, Mode=OneWay, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}"
|
||||
Visibility="{Binding Status, Mode=OneWay, Converter={StaticResource EmptyStringToVisibilityConverter}}" />
|
||||
Style="{StaticResource MainColorButton}" />
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4" Height="Auto" FontSize="14" FontWeight="Light"
|
||||
Text="{Binding Status}"
|
||||
Foreground="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}"
|
||||
Visibility="{Binding Status, Converter={StaticResource EmptyStringToVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -3,18 +3,16 @@ using System.Collections.Generic;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.ViewModels;
|
||||
using ModernKeePass.Extensions;
|
||||
|
||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace ModernKeePass.Views.UserControls
|
||||
{
|
||||
public sealed partial class UpdateCredentialsUserControl
|
||||
public sealed partial class SetCredentialsUserControl
|
||||
{
|
||||
public SetCredentialsViewModel ViewModel => Grid.DataContext as SetCredentialsViewModel;
|
||||
|
||||
private SetCredentialsViewModel Model => (SetCredentialsViewModel)Resources["ViewModel"];
|
||||
|
||||
public string ButtonLabel
|
||||
{
|
||||
get { return (string)GetValue(ButtonLabelProperty); }
|
||||
@@ -24,24 +22,10 @@ namespace ModernKeePass.Views.UserControls
|
||||
DependencyProperty.Register(
|
||||
nameof(ButtonLabel),
|
||||
typeof(string),
|
||||
typeof(UpdateCredentialsUserControl),
|
||||
typeof(SetCredentialsUserControl),
|
||||
new PropertyMetadata("OK", (o, args) => { }));
|
||||
|
||||
public string DatabaseFilePath
|
||||
{
|
||||
get { return (string) GetValue(DatabaseFilePathProperty); }
|
||||
set { SetValue(DatabaseFilePathProperty, value); }
|
||||
}
|
||||
public static readonly DependencyProperty DatabaseFilePathProperty =
|
||||
DependencyProperty.Register(
|
||||
"DatabaseFilePath",
|
||||
typeof(string),
|
||||
typeof(UpdateCredentialsUserControl),
|
||||
new PropertyMetadata(null, (o, args) => { }));
|
||||
|
||||
public event EventHandler CredentialsUpdated;
|
||||
|
||||
public UpdateCredentialsUserControl()
|
||||
|
||||
public SetCredentialsUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -61,7 +45,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
ViewModel.KeyFilePath = token;
|
||||
Model.KeyFilePath = token;
|
||||
}
|
||||
|
||||
private async void CreateKeyFileButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -77,25 +61,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
ViewModel.KeyFilePath = token;
|
||||
}
|
||||
|
||||
private async void UpdateButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
|
||||
if (await Dispatcher.RunTaskAsync(async () =>
|
||||
{
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = DatabaseFilePath
|
||||
};
|
||||
await ViewModel.CreateDatabase(fileInfo);
|
||||
return true;
|
||||
}))
|
||||
{
|
||||
CredentialsUpdated?.Invoke(this, new EventArgs());
|
||||
}
|
||||
Model.KeyFilePath = token;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user