mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Moved application code to the Application layer
Imported Win10 project Code cleanup WIP - Use common UWP services for Win8.1 and Win10
This commit is contained in:
@@ -5,7 +5,6 @@ using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Views.BasePages
|
||||
{
|
||||
|
@@ -1,6 +1,6 @@
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
@@ -33,7 +33,7 @@ namespace ModernKeePass.Views
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
var file = e.Parameter as StorageFile;
|
||||
var file = e.Parameter as FileInfo;
|
||||
DataContext = new MainVm(Frame, MenuFrame, file);
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<StackPanel Margin="25,0,25,0">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFile="{Binding DatabaseFile}" ValidationChecked="CompositeKeyUserControl_OnValidationChecked" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFilePath="{Binding Path}" ValidationChecked="CompositeKeyUserControl_OnValidationChecked" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<CheckBox x:Name="CheckBox" x:Uid="NewImportCheckbox" Margin="15,10,0,0" IsChecked="{Binding IsImportChecked, Mode=TwoWay}" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
|
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Events;
|
||||
using ModernKeePass.ImportFormats;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePass.Infrastructure.File;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
@@ -44,22 +46,26 @@ namespace ModernKeePass.Views
|
||||
|
||||
var file = await savePicker.PickSaveFileAsync();
|
||||
if (file == null) return;
|
||||
Model.OpenFile(file);
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Name = file.DisplayName
|
||||
};
|
||||
await Model.OpenFile(fileInfo);
|
||||
}
|
||||
|
||||
private void ImportFormatComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var resources = new ResourcesService();
|
||||
var resource = new ResourceHelper();
|
||||
var comboBox = sender as ComboBox;
|
||||
switch (comboBox?.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
Model.ImportFormat = new CsvImportFormat();
|
||||
Model.ImportFileExtensionFilter = ".csv";
|
||||
Model.ImportFormatHelp = resources.GetResourceValue("NewImportFormatHelpCSV");
|
||||
break;
|
||||
default:
|
||||
Model.ImportFormat = new NullImportFormat();
|
||||
Model.ImportFormatHelp = resource.GetResourceValue("NewImportFormatHelpCSV");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,8 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
x:Class="ModernKeePass.Views.OpenDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
@@ -24,11 +25,11 @@
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<StackPanel Margin="25,0,25,0">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFile="{Binding DatabaseFile}">
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFilePath="{Binding Path}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<Core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<Core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />
|
||||
</Core:EventTriggerBehavior>
|
||||
<core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />
|
||||
</core:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</userControls:CompositeKeyUserControl>
|
||||
</StackPanel>
|
||||
|
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
@@ -21,13 +22,13 @@ namespace ModernKeePass.Views
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
var file = e.Parameter as StorageFile;
|
||||
var file = e.Parameter as FileInfo;
|
||||
if (file != null)
|
||||
{
|
||||
Model.OpenFile(file);
|
||||
await Model.OpenFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +44,15 @@ namespace ModernKeePass.Views
|
||||
// Application now has read/write access to the picked file
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file == null) return;
|
||||
Model.OpenFile(file);
|
||||
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Name = file.DisplayName
|
||||
};
|
||||
await Model.OpenFile(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="{Binding Name}" Padding="5,0,0,0" />
|
||||
<TextBlock Grid.Row="1" Text="{Binding Path}" Padding="5,0,0,0" FontSize="10" />
|
||||
<userControls:CompositeKeyUserControl Grid.Row="2" x:Name="DatabaseUserControl" x:Uid="CompositeKeyOpenButton" HorizontalAlignment="Stretch" MinWidth="400" Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" DatabaseFile="{Binding DatabaseFile}">
|
||||
<userControls:CompositeKeyUserControl Grid.Row="2" x:Name="DatabaseUserControl" x:Uid="CompositeKeyOpenButton" HorizontalAlignment="Stretch" MinWidth="400" Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" DatabaseFilePath="{Binding Path}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<core:CallMethodAction TargetObject="{Binding}" MethodName="UpdateAccessTime" />
|
||||
|
@@ -11,7 +11,7 @@
|
||||
mc:Ignorable="d" >
|
||||
<UserControl.Resources>
|
||||
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
|
||||
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToForegroungBrushConverter"/>
|
||||
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToForegroundBrushConverter"/>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
@@ -42,7 +42,7 @@
|
||||
<ProgressBar Grid.Row="0" Grid.Column="1"
|
||||
Maximum="128" VerticalAlignment="Bottom"
|
||||
Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}}"
|
||||
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToForegroungBrushConverter}}"
|
||||
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToForegroundBrushConverter}}"
|
||||
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" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
|
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
||||
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Events;
|
||||
using ModernKeePass.Extensions;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
@@ -24,6 +24,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
public sealed partial class CompositeKeyUserControl
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ResourceHelper _resource;
|
||||
public CompositeKeyVm Model => Grid.DataContext as CompositeKeyVm;
|
||||
|
||||
public bool CreateNew
|
||||
@@ -62,26 +63,27 @@ namespace ModernKeePass.Views.UserControls
|
||||
typeof(CompositeKeyUserControl),
|
||||
new PropertyMetadata("OK", (o, args) => { }));
|
||||
|
||||
public StorageFile DatabaseFile
|
||||
public string DatabaseFilePath
|
||||
{
|
||||
get { return (StorageFile)GetValue(DatabaseFileProperty); }
|
||||
set { SetValue(DatabaseFileProperty, value); }
|
||||
get { return (string)GetValue(DatabaseFilePathProperty); }
|
||||
set { SetValue(DatabaseFilePathProperty, value); }
|
||||
}
|
||||
public static readonly DependencyProperty DatabaseFileProperty =
|
||||
public static readonly DependencyProperty DatabaseFilePathProperty =
|
||||
DependencyProperty.Register(
|
||||
"DatabaseFile",
|
||||
typeof(StorageFile),
|
||||
"DatabaseFilePath",
|
||||
typeof(string),
|
||||
typeof(CompositeKeyUserControl),
|
||||
new PropertyMetadata(null, (o, args) => { }));
|
||||
|
||||
public bool ShowComplexityIndicator => CreateNew || UpdateKey;
|
||||
|
||||
public CompositeKeyUserControl(): this(App.Mediator)
|
||||
public CompositeKeyUserControl(): this(App.Services.GetService<IMediator>())
|
||||
{ }
|
||||
|
||||
public CompositeKeyUserControl(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_resource = new ResourceHelper();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -100,31 +102,30 @@ namespace ModernKeePass.Views.UserControls
|
||||
else
|
||||
{
|
||||
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||
var resource = new ResourcesService();
|
||||
if (database.IsOpen)
|
||||
{
|
||||
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("MessageDialogDBOpenTitle"),
|
||||
string.Format(resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
|
||||
resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
|
||||
resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
|
||||
await MessageDialogHelper.ShowActionDialog(_resource.GetResourceValue("MessageDialogDBOpenTitle"),
|
||||
string.Format(_resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
|
||||
_resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
|
||||
_resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
|
||||
async command =>
|
||||
{
|
||||
await _mediator.Send(new SaveDatabaseCommand());
|
||||
ToastNotificationHelper.ShowGenericToast(
|
||||
database.Name,
|
||||
resource.GetResourceValue("ToastSavedMessage"));
|
||||
_resource.GetResourceValue("ToastSavedMessage"));
|
||||
await _mediator.Send(new CloseDatabaseCommand());
|
||||
await OpenDatabase(resource);
|
||||
await OpenDatabase();
|
||||
},
|
||||
async command =>
|
||||
{
|
||||
await _mediator.Send(new CloseDatabaseCommand());
|
||||
await OpenDatabase(resource);
|
||||
await OpenDatabase();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await OpenDatabase(resource);
|
||||
await OpenDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,7 +152,9 @@ namespace ModernKeePass.Views.UserControls
|
||||
// Application now has read/write access to the picked file
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file == null) return;
|
||||
Model.KeyFile = file;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
Model.KeyFilePath = token;
|
||||
}
|
||||
|
||||
private async void CreateKeyFileButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -166,14 +169,19 @@ namespace ModernKeePass.Views.UserControls
|
||||
var file = await savePicker.PickSaveFileAsync();
|
||||
if (file == null) return;
|
||||
|
||||
await Model.CreateKeyFile(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
await Model.CreateKeyFile(new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Name = file.DisplayName
|
||||
});
|
||||
}
|
||||
|
||||
private async Task OpenDatabase(IResourceService resource)
|
||||
private async Task OpenDatabase()
|
||||
{
|
||||
var oldLabel = ButtonLabel;
|
||||
ButtonLabel = resource.GetResourceValue("CompositeKeyOpening");
|
||||
if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(DatabaseFile, CreateNew)))
|
||||
ButtonLabel = _resource.GetResourceValue("CompositeKeyOpening");
|
||||
if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(DatabaseFilePath, CreateNew)))
|
||||
{
|
||||
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroupId));
|
||||
}
|
||||
|
Reference in New Issue
Block a user