Added some translations in file pickers

Corrected key file creation picker issue (any not allowed)
Fixed some Sonar issues
This commit is contained in:
Geoffroy BONNEVILLE
2020-05-05 17:32:07 +02:00
parent 8fb468358e
commit 2e22a2bd92
13 changed files with 52 additions and 18 deletions

View File

@@ -17,15 +17,17 @@ namespace ModernKeePass.ViewModels
private readonly ISettingsProxy _settings;
private readonly INavigationService _navigation;
private readonly IFileProxy _file;
private readonly IResourceProxy _resource;
public RelayCommand CreateDatabaseFileCommand { get; }
public NewVm(IMediator mediator, ISettingsProxy settings, INavigationService navigation, IFileProxy file): base(file)
public NewVm(IMediator mediator, ISettingsProxy settings, INavigationService navigation, IFileProxy file, IResourceProxy resource): base(file)
{
_mediator = mediator;
_settings = settings;
_navigation = navigation;
_file = file;
_resource = resource;
CreateDatabaseFileCommand = new RelayCommand(async () => await CreateDatabaseFile());
@@ -34,8 +36,11 @@ namespace ModernKeePass.ViewModels
private async Task CreateDatabaseFile()
{
// TODO: get these from resource
var file = await _file.CreateFile("New Database", Domain.Common.Constants.Extensions.Kdbx, "KeePass 2.x database", true);
var file = await _file.CreateFile(_resource.GetResourceValue("MessageDialogSaveNameSuggestion"),
Domain.Common.Constants.Extensions.Kdbx,
_resource.GetResourceValue("MessageDialogSaveErrorFileTypeDesc"),
true);
if (file == null) return;
Token = file.Id;
Path = file.Path;
Name = file.Name;

View File

@@ -24,12 +24,14 @@ namespace ModernKeePass.ViewModels
private readonly IMediator _mediator;
private readonly INavigationService _navigation;
private readonly IFileProxy _file;
private readonly IResourceProxy _resource;
public SaveVm(IMediator mediator, INavigationService navigation, IFileProxy file)
public SaveVm(IMediator mediator, INavigationService navigation, IFileProxy file, IResourceProxy resource)
{
_mediator = mediator;
_navigation = navigation;
_file = file;
_resource = resource;
SaveAsCommand = new RelayCommand(async () => await SaveAs());
SaveCommand = new RelayCommand(async () => await Save(), () => IsSaveEnabled);
@@ -40,9 +42,11 @@ namespace ModernKeePass.ViewModels
private async Task SaveAs()
{
// TODO: get these from resource
var file = await _file.CreateFile("New Database", Domain.Common.Constants.Extensions.Kdbx, "KeePass 2.x database", true);
var file = await _file.CreateFile(_resource.GetResourceValue("MessageDialogSaveNameSuggestion"),
Domain.Common.Constants.Extensions.Kdbx,
_resource.GetResourceValue("MessageDialogSaveErrorFileTypeDesc"),
true);
if (file == null) return;
await _mediator.Send(new SaveDatabaseCommand { FilePath = file.Id });
_navigation.NavigateTo(Constants.Navigation.MainPage);
}

View File

@@ -14,6 +14,7 @@ namespace ModernKeePass.ViewModels
{
private readonly IMediator _mediator;
private readonly ICredentialsProxy _credentials;
private readonly IResourceProxy _resource;
private readonly IFileProxy _file;
public bool HasPassword
@@ -105,6 +106,7 @@ namespace ModernKeePass.ViewModels
{
_mediator = mediator;
_credentials = credentials;
_resource = resource;
_file = file;
OpenKeyFileCommand = new RelayCommand(async () => await OpenKeyFile(), () => HasKeyFile);
@@ -117,12 +119,16 @@ namespace ModernKeePass.ViewModels
private async Task OpenKeyFile()
{
var file = await _file.OpenFile(string.Empty, Constants.Extensions.Any, false);
if (file == null) return;
SetKeyFileInfo(file);
}
private async Task CreateKeyFile()
{
var file = await _file.CreateFile("Key", Constants.Extensions.Any, "Key file", false);
var file = await _file.CreateFile(_resource.GetResourceValue("CompositeKeyFileNameSuggestion"),
Constants.Extensions.Key, _resource.GetResourceValue("CompositeKeyFileTypeDesc"),
false);
if (file == null) return;
SetKeyFileInfo(file);
await _mediator.Send(new GenerateKeyFileCommand { KeyFilePath = KeyFilePath });
@@ -130,7 +136,6 @@ namespace ModernKeePass.ViewModels
private void SetKeyFileInfo(FileInfo file)
{
if (file == null) return;
KeyFilePath = file.Id;
KeyFileText = file.Name;
HasKeyFile = true;