mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 07:30:15 -04:00
OpenDatabase control now handles status changes with VisualStateManager instead of Vm
Opening DB shows a progress ring instead
This commit is contained in:
@@ -129,9 +129,6 @@
|
||||
<data name="CompositeKeyErrorUserPassword" xml:space="preserve">
|
||||
<value>- password incorrect</value>
|
||||
</data>
|
||||
<data name="CompositeKeyOpening" xml:space="preserve">
|
||||
<value>Opening...</value>
|
||||
</data>
|
||||
<data name="CompositeKeyUpdated" xml:space="preserve">
|
||||
<value>Database credentials updated.</value>
|
||||
</data>
|
||||
@@ -264,9 +261,6 @@
|
||||
<data name="HistoryDeleteTitle" xml:space="preserve">
|
||||
<value>Delete history entry ?</value>
|
||||
</data>
|
||||
<data name="CompositeKeyOpenButtonLabel" xml:space="preserve">
|
||||
<value>Open</value>
|
||||
</data>
|
||||
<data name="FileNotFoundDescription" xml:space="preserve">
|
||||
<value>File does not exist anymore</value>
|
||||
</data>
|
||||
|
@@ -129,9 +129,6 @@
|
||||
<data name="CompositeKeyErrorUserPassword" xml:space="preserve">
|
||||
<value>- mot de passe incorrect</value>
|
||||
</data>
|
||||
<data name="CompositeKeyOpening" xml:space="preserve">
|
||||
<value>Ouverture...</value>
|
||||
</data>
|
||||
<data name="CompositeKeyUpdated" xml:space="preserve">
|
||||
<value>Identifiants de la base de données mis à jour.</value>
|
||||
</data>
|
||||
@@ -264,9 +261,6 @@
|
||||
<data name="HistoryDeleteTitle" xml:space="preserve">
|
||||
<value>Supprimer cet historique ?</value>
|
||||
</data>
|
||||
<data name="CompositeKeyOpenButtonLabel" xml:space="preserve">
|
||||
<value>Open</value>
|
||||
</data>
|
||||
<data name="FileNotFoundDescription" xml:space="preserve">
|
||||
<value>Le fichier n'existe plus.</value>
|
||||
</data>
|
||||
|
@@ -8,7 +8,7 @@
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<ProgressRing x:Name="LoadingRing" IsActive="True" Width="50" Height="50" Foreground="{StaticResource MainColor}" />
|
||||
<ProgressRing x:Name="LoadingRing" IsActive="True" Width="50" Height="50" Foreground="{StaticResource MainColorBrush}" />
|
||||
<WebView Source="https://PayPal.Me/wismna">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="DOMContentLoaded">
|
||||
|
@@ -9,10 +9,14 @@
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
mc:Ignorable="d" >
|
||||
<UserControl.Resources>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
|
||||
</UserControl.Resources>
|
||||
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=OpenDatabaseControl}">
|
||||
<Grid.Resources>
|
||||
<SolidColorBrush x:Key="ErrorBrush" Color="Red" />
|
||||
</Grid.Resources>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -24,7 +28,7 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox Grid.Row="0" Grid.Column="0" IsChecked="{Binding HasPassword, Mode=TwoWay}" />
|
||||
<PasswordBox Grid.Row="0" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding Password, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" KeyDown="PasswordBox_KeyDown" BorderBrush="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" >
|
||||
<PasswordBox x:Name="PasswordBox" Grid.Row="0" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding Password, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" KeyDown="PasswordBox_KeyDown" >
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="GotFocus">
|
||||
<core:ChangePropertyAction TargetObject="{Binding}" PropertyName="HasPassword" Value="True" />
|
||||
@@ -33,16 +37,52 @@
|
||||
</PasswordBox>
|
||||
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
|
||||
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0"
|
||||
x:Name="HyperlinkButton"
|
||||
Content="{Binding KeyFileText}"
|
||||
IsEnabled="{Binding HasKeyFile}"
|
||||
Click="KeyFileButton_Click" />
|
||||
<Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2"
|
||||
Content="{Binding OpenButtonLabel}"
|
||||
x:Uid="OpenDatabaseControlButton"
|
||||
Visibility="{Binding IsOpening, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
|
||||
Command="{Binding OpenDatabaseCommand}"
|
||||
CommandParameter="{Binding DatabaseFilePath, ElementName=UserControl}" />
|
||||
<ProgressRing Grid.Column="0" Grid.Row="2" IsActive="{Binding IsOpening}" Visibility="{Binding IsOpening, Converter={StaticResource BooleanToVisibilityConverter}}" Foreground="{StaticResource MainColorBrush}" />
|
||||
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Height="Auto" FontSize="14" FontWeight="Light"
|
||||
Text="{Binding Status}"
|
||||
Foreground="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}"
|
||||
Foreground="Red"
|
||||
Visibility="{Binding Status, Converter={StaticResource EmptyStringToVisibilityConverter}}" />
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CredentialStatus">
|
||||
<VisualState x:Name="Error">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="BorderBrush">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ErrorBrush}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HyperlinkButton" Storyboard.TargetProperty="Foreground">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ErrorBrush}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Initial">
|
||||
<Storyboard>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PasswordBox" Storyboard.TargetProperty="BorderBrush">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TextBoxBorderThemeBrush}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="HyperlinkButton" Storyboard.TargetProperty="Foreground">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource HyperlinkForegroundThemeBrush}"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:DataTriggerBehavior Binding="{Binding IsError}" Value="True">
|
||||
<core:GoToStateAction StateName="Error"/>
|
||||
</core:DataTriggerBehavior>
|
||||
<core:DataTriggerBehavior Binding="{Binding IsError}" Value="False">
|
||||
<core:GoToStateAction StateName="Initial"/>
|
||||
</core:DataTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@@ -54,7 +54,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
Model.KeyFilePath = token;
|
||||
Model.KeyFileText = file.DisplayName;
|
||||
Model.KeyFileText = file.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@
|
||||
<UserControl.Resources>
|
||||
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
|
||||
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
</UserControl.Resources>
|
||||
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=SetCredentials}">
|
||||
|
@@ -1,16 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Windows.UI;
|
||||
using GalaSoft.MvvmLight;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels.ListItems
|
||||
{
|
||||
public class EntryItemVm : NotifyPropertyChangedBase
|
||||
public class EntryItemVm : ObservableObject
|
||||
{
|
||||
private readonly ISecurityService _securityService;
|
||||
|
||||
public EntryEntity EntryEntity { get; }
|
||||
public GroupItemVm Parent { get; }
|
||||
|
||||
|
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
namespace ModernKeePass.Converters
|
||||
{
|
||||
public class DiscreteIntToSolidColorBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
var status = System.Convert.ToInt32(value);
|
||||
switch (status)
|
||||
{
|
||||
case 1: return new SolidColorBrush(Colors.Red);
|
||||
case 3: return new SolidColorBrush(Colors.Yellow);
|
||||
case 5: return new SolidColorBrush(Colors.Green);
|
||||
default: return new SolidColorBrush(Colors.Black);
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,14 +14,6 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class OpenDatabaseControlVm : ViewModelBase
|
||||
{
|
||||
public enum StatusTypes
|
||||
{
|
||||
Normal = 0,
|
||||
Error = 1,
|
||||
Warning = 3,
|
||||
Success = 5
|
||||
}
|
||||
|
||||
public bool HasPassword
|
||||
{
|
||||
get { return _hasPassword; }
|
||||
@@ -44,27 +36,19 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath));
|
||||
|
||||
public string Status
|
||||
{
|
||||
get { return _status; }
|
||||
set { Set(() => Status, ref _status, value); }
|
||||
}
|
||||
|
||||
public int StatusType
|
||||
{
|
||||
get { return _statusType; }
|
||||
set { Set(() => StatusType, ref _statusType, value); }
|
||||
}
|
||||
|
||||
public string Password
|
||||
{
|
||||
get { return _password; }
|
||||
set
|
||||
{
|
||||
_password = value;
|
||||
StatusType = (int)StatusTypes.Normal;
|
||||
IsError = false;
|
||||
Status = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -75,6 +59,7 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
_keyFilePath = value;
|
||||
IsError = false;
|
||||
RaisePropertyChanged(nameof(IsValid));
|
||||
OpenDatabaseCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
@@ -86,14 +71,22 @@ namespace ModernKeePass.ViewModels
|
||||
set { Set(() => KeyFileText, ref _keyFileText, value); }
|
||||
}
|
||||
|
||||
public string OpenButtonLabel
|
||||
public bool IsOpening
|
||||
{
|
||||
get { return _openButtonLabel; }
|
||||
set { Set(() => OpenButtonLabel, ref _openButtonLabel, value); }
|
||||
get { return _isOpening; }
|
||||
set { Set(() => IsOpening, ref _isOpening, value); }
|
||||
}
|
||||
|
||||
|
||||
public bool IsError
|
||||
{
|
||||
get { return _isError; }
|
||||
set { Set(() => IsError, ref _isError, value); }
|
||||
}
|
||||
|
||||
public bool IsValid => !IsOpening && (HasPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath));
|
||||
|
||||
public RelayCommand<string> OpenDatabaseCommand { get; }
|
||||
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly INotificationService _notification;
|
||||
@@ -102,11 +95,10 @@ namespace ModernKeePass.ViewModels
|
||||
private bool _isOpening;
|
||||
private string _password = string.Empty;
|
||||
private string _status;
|
||||
private int _statusType;
|
||||
private string _keyFilePath;
|
||||
private string _keyFileText;
|
||||
private string _openButtonLabel;
|
||||
|
||||
private bool _isError;
|
||||
|
||||
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
|
||||
{
|
||||
_mediator = mediator;
|
||||
@@ -114,7 +106,6 @@ namespace ModernKeePass.ViewModels
|
||||
_notification = notification;
|
||||
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
|
||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
|
||||
}
|
||||
|
||||
public async Task TryOpenDatabase(string databaseFilePath)
|
||||
@@ -132,9 +123,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public async Task OpenDatabase(string databaseFilePath)
|
||||
{
|
||||
var oldLabel = _openButtonLabel;
|
||||
OpenButtonLabel = _resource.GetResourceValue("CompositeKeyOpening");
|
||||
_isOpening = true;
|
||||
IsOpening = true;
|
||||
try
|
||||
{
|
||||
await _mediator.Send(new OpenDatabaseQuery
|
||||
@@ -152,7 +141,8 @@ namespace ModernKeePass.ViewModels
|
||||
var errorMessage = new StringBuilder($"{_resource.GetResourceValue("CompositeKeyErrorOpen")}\n");
|
||||
if (HasPassword) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserPassword"));
|
||||
if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile"));
|
||||
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
|
||||
Status = errorMessage.ToString();
|
||||
IsError = true;
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
@@ -160,23 +150,17 @@ namespace ModernKeePass.ViewModels
|
||||
$"{_resource.GetResourceValue("FileNotFoundTitle")}",
|
||||
$"{_resource.GetResourceValue("FileNotFoundDescription")}");
|
||||
MessengerInstance.Send(new FileNotFoundMessage());
|
||||
IsError = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";
|
||||
UpdateStatus(error, StatusTypes.Error);
|
||||
Status = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isOpening = false;
|
||||
OpenButtonLabel = oldLabel;
|
||||
IsOpening = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStatus(string text, StatusTypes type)
|
||||
{
|
||||
Status = text;
|
||||
StatusType = (int)type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\TextBoxWithButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\BooleanToVisibilityConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ColorToBrushConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\DiscreteIntToSolidColorBrushConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\DoubleToSolidColorBrushConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\EmptyStringToVisibilityConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\IconToSymbolConverter.cs" />
|
||||
|
Reference in New Issue
Block a user