mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
WIP ViewModelLocator - Messenger and Recent issues
Refactoring Code cleanup
This commit is contained in:
@@ -8,6 +8,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IDatabaseProxy
|
public interface IDatabaseProxy
|
||||||
{
|
{
|
||||||
|
// PW Database properties
|
||||||
bool IsOpen { get; }
|
bool IsOpen { get; }
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
string RootGroupId { get; }
|
string RootGroupId { get; }
|
||||||
@@ -16,6 +17,8 @@ namespace ModernKeePass.Application.Common.Interfaces
|
|||||||
string KeyDerivationId { get; set; }
|
string KeyDerivationId { get; set; }
|
||||||
string Compression { get; set; }
|
string Compression { get; set; }
|
||||||
bool IsRecycleBinEnabled { get; set; }
|
bool IsRecycleBinEnabled { get; set; }
|
||||||
|
|
||||||
|
// Custom properties
|
||||||
string FileAccessToken { get; set; }
|
string FileAccessToken { get; set; }
|
||||||
int Size { get; set; }
|
int Size { get; set; }
|
||||||
bool IsDirty { get; set; }
|
bool IsDirty { get; set; }
|
||||||
|
@@ -21,7 +21,11 @@ namespace ModernKeePass.Application.Database.Commands.CloseDatabase
|
|||||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||||
_database.CloseDatabase();
|
_database.CloseDatabase();
|
||||||
_file.ReleaseFile(_database.FileAccessToken);
|
_file.ReleaseFile(_database.FileAccessToken);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
_database.FileAccessToken = null;
|
_database.FileAccessToken = null;
|
||||||
|
_database.IsDirty = false;
|
||||||
|
_database.Size = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
|||||||
|
|
||||||
public async Task Handle(CreateDatabaseCommand message)
|
public async Task Handle(CreateDatabaseCommand message)
|
||||||
{
|
{
|
||||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
if (_database.IsDirty) throw new DatabaseOpenException();
|
||||||
|
|
||||||
var version = DatabaseVersion.V2;
|
var version = DatabaseVersion.V2;
|
||||||
switch (message.Version)
|
switch (message.Version)
|
||||||
@@ -48,8 +48,6 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
|||||||
Password = message.Password
|
Password = message.Password
|
||||||
}, message.Name, version);
|
}, message.Name, version);
|
||||||
_database.FileAccessToken = message.FilePath;
|
_database.FileAccessToken = message.FilePath;
|
||||||
var contents = await _database.SaveDatabase();
|
|
||||||
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
|
||||||
|
|
||||||
if (message.CreateSampleData)
|
if (message.CreateSampleData)
|
||||||
{
|
{
|
||||||
|
@@ -34,8 +34,7 @@ namespace ModernKeePass.Application.Database.Commands.SaveDatabase
|
|||||||
|
|
||||||
// Test DB integrity before writing changes to file
|
// Test DB integrity before writing changes to file
|
||||||
_database.CloseDatabase();
|
_database.CloseDatabase();
|
||||||
var file = await _file.OpenBinaryFile(_database.FileAccessToken);
|
await _database.ReOpen(contents);
|
||||||
await _database.ReOpen(file);
|
|
||||||
|
|
||||||
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
||||||
}
|
}
|
||||||
|
@@ -25,18 +25,19 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
|||||||
|
|
||||||
public async Task Handle(OpenDatabaseQuery message)
|
public async Task Handle(OpenDatabaseQuery message)
|
||||||
{
|
{
|
||||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
if (_database.IsDirty) throw new DatabaseOpenException();
|
||||||
|
|
||||||
var file = await _file.OpenBinaryFile(message.FilePath);
|
var file = await _file.OpenBinaryFile(message.FilePath);
|
||||||
|
var hasKeyFile = !string.IsNullOrEmpty(message.KeyFilePath);
|
||||||
await _database.Open(file, new Credentials
|
await _database.Open(file, new Credentials
|
||||||
{
|
{
|
||||||
KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath): null,
|
KeyFileContents = hasKeyFile ? await _file.OpenBinaryFile(message.KeyFilePath): null,
|
||||||
Password = message.Password
|
Password = message.Password
|
||||||
});
|
});
|
||||||
|
if (hasKeyFile) _file.ReleaseFile(message.KeyFilePath);
|
||||||
_database.Size = file.Length;
|
_database.Size = file.Length;
|
||||||
_database.FileAccessToken = message.FilePath;
|
_database.FileAccessToken = message.FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,11 +4,13 @@ namespace ModernKeePass.Domain.Exceptions
|
|||||||
{
|
{
|
||||||
public class SaveException : Exception
|
public class SaveException : Exception
|
||||||
{
|
{
|
||||||
public new Exception InnerException { get; }
|
public new string Message { get; }
|
||||||
|
public new string Source { get; }
|
||||||
|
|
||||||
public SaveException(Exception exception)
|
public SaveException(Exception exception)
|
||||||
{
|
{
|
||||||
InnerException = exception;
|
Message = exception.Message;
|
||||||
|
Source = exception.Source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -351,7 +351,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
private CompositeKey CreateCompositeKey(Credentials credentials)
|
private CompositeKey CreateCompositeKey(Credentials credentials)
|
||||||
{
|
{
|
||||||
var compositeKey = new CompositeKey();
|
var compositeKey = new CompositeKey();
|
||||||
if (!string.IsNullOrEmpty(credentials.Password)) compositeKey.AddUserKey(new KcpPassword(credentials.Password));
|
if (credentials.Password != null) compositeKey.AddUserKey(new KcpPassword(credentials.Password));
|
||||||
if (credentials.KeyFileContents != null)
|
if (credentials.KeyFileContents != null)
|
||||||
{
|
{
|
||||||
compositeKey.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromByteArray(credentials.KeyFileContents)));
|
compositeKey.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromByteArray(credentials.KeyFileContents)));
|
||||||
|
@@ -21,7 +21,7 @@ namespace ModernKeePass.Infrastructure.UWP
|
|||||||
{
|
{
|
||||||
var file = await _mru.GetFileAsync(token,
|
var file = await _mru.GetFileAsync(token,
|
||||||
updateAccessTime ? AccessCacheOptions.None : AccessCacheOptions.SuppressAccessTimeUpdate).AsTask().ConfigureAwait(false);
|
updateAccessTime ? AccessCacheOptions.None : AccessCacheOptions.SuppressAccessTimeUpdate).AsTask().ConfigureAwait(false);
|
||||||
_fal.AddOrReplace(token, file);
|
_fal.AddOrReplace(token, file, file.Name);
|
||||||
return new FileInfo
|
return new FileInfo
|
||||||
{
|
{
|
||||||
Id = token,
|
Id = token,
|
||||||
|
@@ -1,4 +1,9 @@
|
|||||||
<Application x:Class="ModernKeePass.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RequestedTheme="Light" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
|
<Application x:Class="ModernKeePass.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
RequestedTheme="Light"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
d1p1:Ignorable="d"
|
||||||
|
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
@@ -13,9 +18,9 @@
|
|||||||
<ResourceDictionary Source="ResourceDictionaries/NoBorderToggleButtonStyle.xaml">
|
<ResourceDictionary Source="ResourceDictionaries/NoBorderToggleButtonStyle.xaml">
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
<ResourceDictionary Source="ResourceDictionaries/Styles.xaml">
|
<ResourceDictionary Source="ResourceDictionaries/Styles.xaml">
|
||||||
<!--<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:ModernKeePass.ViewModel" />-->
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:ModernKeePass.ViewModels" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
@@ -88,10 +88,9 @@ namespace ModernKeePass
|
|||||||
|
|
||||||
if (realException is SaveException)
|
if (realException is SaveException)
|
||||||
{
|
{
|
||||||
var innerException = realException.InnerException;
|
|
||||||
unhandledExceptionEventArgs.Handled = true;
|
unhandledExceptionEventArgs.Handled = true;
|
||||||
_hockey.TrackException(innerException);
|
_hockey.TrackException(realException);
|
||||||
await _dialog.ShowMessage(innerException?.Message,
|
await _dialog.ShowMessage(realException.Message,
|
||||||
_resource.GetResourceValue("MessageDialogSaveErrorTitle"),
|
_resource.GetResourceValue("MessageDialogSaveErrorTitle"),
|
||||||
_resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"),
|
_resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"),
|
||||||
_resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"),
|
_resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"),
|
||||||
@@ -112,7 +111,7 @@ namespace ModernKeePass
|
|||||||
var file = await savePicker.PickSaveFileAsync().AsTask();
|
var file = await savePicker.PickSaveFileAsync().AsTask();
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
await _mediator.Send(new SaveDatabaseCommand {FilePath = token});
|
await _mediator.Send(new SaveDatabaseCommand {FilePath = token});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +251,7 @@ namespace ModernKeePass
|
|||||||
|
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
var fileInfo = new FileInfo
|
var fileInfo = new FileInfo
|
||||||
{
|
{
|
||||||
Id = token,
|
Id = token,
|
||||||
|
@@ -25,7 +25,6 @@ namespace ModernKeePass
|
|||||||
nav.Configure(Constants.Navigation.GroupPage, typeof(GroupDetailPage));
|
nav.Configure(Constants.Navigation.GroupPage, typeof(GroupDetailPage));
|
||||||
return nav;
|
return nav;
|
||||||
});
|
});
|
||||||
services.AddSingleton(provider => Messenger.Default);
|
|
||||||
services.AddTransient(typeof(IDialogService), typeof(DialogService));
|
services.AddTransient(typeof(IDialogService), typeof(DialogService));
|
||||||
|
|
||||||
services.AddSingleton(provider =>
|
services.AddSingleton(provider =>
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using Windows.Storage;
|
|
||||||
using ModernKeePass.ViewModels;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Interfaces
|
|
||||||
{
|
|
||||||
public interface IImportService<in T> where T: IFormat
|
|
||||||
{
|
|
||||||
Task Import(T format, IStorageFile source, GroupVm group);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,22 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Windows.UI.Xaml.Controls;
|
|
||||||
using ModernKeePass.Application.Group.Models;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Interfaces
|
|
||||||
{
|
|
||||||
public interface IVmEntity
|
|
||||||
{
|
|
||||||
Symbol Icon { get; }
|
|
||||||
string Id { get; }
|
|
||||||
string Title { get; set; }
|
|
||||||
IEnumerable<GroupVm> BreadCrumb { get; }
|
|
||||||
bool IsEditMode { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Move a entity to the destination group
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="destination">The destination to move the entity to</param>
|
|
||||||
Task Move(GroupVm destination);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
using GalaSoft.MvvmLight;
|
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// This class contains properties that the main View can data bind to.
|
|
||||||
/// <para>
|
|
||||||
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
|
|
||||||
/// </para>
|
|
||||||
/// <para>
|
|
||||||
/// You can also use Blend to data bind with the tool's support.
|
|
||||||
/// </para>
|
|
||||||
/// <para>
|
|
||||||
/// See http://www.galasoft.ch/mvvm
|
|
||||||
/// </para>
|
|
||||||
/// </summary>
|
|
||||||
public class MainViewModel : ViewModelBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the MainViewModel class.
|
|
||||||
/// </summary>
|
|
||||||
public MainViewModel()
|
|
||||||
{
|
|
||||||
////if (IsInDesignMode)
|
|
||||||
////{
|
|
||||||
//// // Code runs in Blend --> create design time data.
|
|
||||||
////}
|
|
||||||
////else
|
|
||||||
////{
|
|
||||||
//// // Code runs "for real"
|
|
||||||
////}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
In App.xaml:
|
|
||||||
<Application.Resources>
|
|
||||||
<vm:ViewModelLocator xmlns:vm="clr-namespace:ModernKeePass"
|
|
||||||
x:Key="Locator" />
|
|
||||||
</Application.Resources>
|
|
||||||
|
|
||||||
In the View:
|
|
||||||
DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
|
|
||||||
|
|
||||||
You can also use Blend to do all this with the tool's support.
|
|
||||||
See http://www.galasoft.ch/mvvm
|
|
||||||
*/
|
|
||||||
|
|
||||||
using CommonServiceLocator;
|
|
||||||
using GalaSoft.MvvmLight;
|
|
||||||
using GalaSoft.MvvmLight.Ioc;
|
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModel
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// This class contains static references to all the view models in the
|
|
||||||
/// application and provides an entry point for the bindings.
|
|
||||||
/// </summary>
|
|
||||||
public class ViewModelLocator
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the ViewModelLocator class.
|
|
||||||
/// </summary>
|
|
||||||
public ViewModelLocator()
|
|
||||||
{
|
|
||||||
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
|
|
||||||
|
|
||||||
////if (ViewModelBase.IsInDesignModeStatic)
|
|
||||||
////{
|
|
||||||
//// // Create design time view services and models
|
|
||||||
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
|
|
||||||
////}
|
|
||||||
////else
|
|
||||||
////{
|
|
||||||
//// // Create run time view services and models
|
|
||||||
//// SimpleIoc.Default.Register<IDataService, DataService>();
|
|
||||||
////}
|
|
||||||
|
|
||||||
SimpleIoc.Default.Register<MainViewModel>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MainViewModel Main => ServiceLocator.Current.GetInstance<MainViewModel>();
|
|
||||||
|
|
||||||
public static void Cleanup()
|
|
||||||
{
|
|
||||||
// TODO Clear the ViewModels
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,191 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using GalaSoft.MvvmLight;
|
|
||||||
using MediatR;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
|
||||||
using ModernKeePass.Application.Database.Commands.CreateDatabase;
|
|
||||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
|
||||||
using ModernKeePass.Application.Database.Queries.OpenDatabase;
|
|
||||||
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
|
|
||||||
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
|
|
||||||
using ModernKeePass.Domain.Dtos;
|
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
|
||||||
{
|
|
||||||
public class CompositeKeyVm: ObservableObject
|
|
||||||
{
|
|
||||||
public enum StatusTypes
|
|
||||||
{
|
|
||||||
Normal = 0,
|
|
||||||
Error = 1,
|
|
||||||
Warning = 3,
|
|
||||||
Success = 5
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasPassword
|
|
||||||
{
|
|
||||||
get { return _hasPassword; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Set(() => HasPassword, ref _hasPassword, value);
|
|
||||||
RaisePropertyChanged(nameof(IsValid));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasKeyFile
|
|
||||||
{
|
|
||||||
get { return _hasKeyFile; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Set(() => HasKeyFile, ref _hasKeyFile, value);
|
|
||||||
RaisePropertyChanged(nameof(IsValid));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null);
|
|
||||||
|
|
||||||
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;
|
|
||||||
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
|
|
||||||
StatusType = (int)StatusTypes.Normal;
|
|
||||||
Status = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string KeyFilePath
|
|
||||||
{
|
|
||||||
get { return _keyFilePath; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_keyFilePath = value;
|
|
||||||
RaisePropertyChanged(nameof(IsValid));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string KeyFileText
|
|
||||||
{
|
|
||||||
get { return _keyFileText; }
|
|
||||||
set { Set(() => KeyFileText, ref _keyFileText, value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RootGroupId { get; set; }
|
|
||||||
|
|
||||||
public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery { Password = Password }).GetAwaiter().GetResult();
|
|
||||||
|
|
||||||
private bool _hasPassword;
|
|
||||||
private bool _hasKeyFile;
|
|
||||||
private bool _isOpening;
|
|
||||||
private string _password = string.Empty;
|
|
||||||
private string _status;
|
|
||||||
private int _statusType;
|
|
||||||
private string _keyFilePath;
|
|
||||||
private string _keyFileText;
|
|
||||||
private readonly IMediator _mediator;
|
|
||||||
private readonly ISettingsProxy _settings;
|
|
||||||
private readonly IResourceProxy _resource;
|
|
||||||
|
|
||||||
public CompositeKeyVm() : this(
|
|
||||||
App.Services.GetRequiredService<IMediator>(),
|
|
||||||
App.Services.GetRequiredService<ISettingsProxy>(),
|
|
||||||
App.Services.GetRequiredService<IResourceProxy>()) { }
|
|
||||||
|
|
||||||
public CompositeKeyVm(IMediator mediator, ISettingsProxy settings, IResourceProxy resource)
|
|
||||||
{
|
|
||||||
_mediator = mediator;
|
|
||||||
_settings = settings;
|
|
||||||
_resource = resource;
|
|
||||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> OpenDatabase(string databaseFilePath, bool createNew)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_isOpening = true;
|
|
||||||
RaisePropertyChanged(nameof(IsValid));
|
|
||||||
if (createNew)
|
|
||||||
{
|
|
||||||
await _mediator.Send(new CreateDatabaseCommand
|
|
||||||
{
|
|
||||||
FilePath = databaseFilePath,
|
|
||||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
|
||||||
Password = HasPassword ? Password : null,
|
|
||||||
Name = "New Database",
|
|
||||||
CreateSampleData = _settings.GetSetting<bool>("Sample")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await _mediator.Send(new OpenDatabaseQuery {
|
|
||||||
FilePath = databaseFilePath,
|
|
||||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
|
||||||
Password = HasPassword ? Password : null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
RootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
var error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}{e.Message}";
|
|
||||||
UpdateStatus(error, StatusTypes.Error);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_isOpening = false;
|
|
||||||
RaisePropertyChanged(nameof(IsValid));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateKey()
|
|
||||||
{
|
|
||||||
await _mediator.Send(new UpdateCredentialsCommand
|
|
||||||
{
|
|
||||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
|
||||||
Password = HasPassword ? Password : null,
|
|
||||||
});
|
|
||||||
UpdateStatus(_resource.GetResourceValue("CompositeKeyUpdated"), StatusTypes.Success);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task CreateKeyFile(FileInfo file)
|
|
||||||
{
|
|
||||||
// TODO: implement entropy generator
|
|
||||||
await _mediator.Send(new GenerateKeyFileCommand {KeyFilePath = file.Id});
|
|
||||||
KeyFilePath = file.Path;
|
|
||||||
KeyFileText = file.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateStatus(string text, StatusTypes type)
|
|
||||||
{
|
|
||||||
Status = text;
|
|
||||||
StatusType = (int)type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
|
using GalaSoft.MvvmLight.Command;
|
||||||
using GalaSoft.MvvmLight.Views;
|
using GalaSoft.MvvmLight.Views;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -26,14 +27,12 @@ using ModernKeePass.Application.Group.Queries.GetGroup;
|
|||||||
using ModernKeePass.Application.Security.Commands.GeneratePassword;
|
using ModernKeePass.Application.Security.Commands.GeneratePassword;
|
||||||
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
|
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
|
||||||
using ModernKeePass.Domain.Enums;
|
using ModernKeePass.Domain.Enums;
|
||||||
using ModernKeePass.Interfaces;
|
|
||||||
using ModernKeePass.Application.Group.Models;
|
using ModernKeePass.Application.Group.Models;
|
||||||
using ModernKeePass.Extensions;
|
using ModernKeePass.Extensions;
|
||||||
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
|
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class EntryDetailVm : ObservableObject, IVmEntity
|
public class EntryDetailVm : ObservableObject
|
||||||
{
|
{
|
||||||
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
||||||
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
|
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
|
||||||
@@ -230,6 +229,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
private readonly INavigationService _navigation;
|
private readonly INavigationService _navigation;
|
||||||
private readonly IResourceProxy _resource;
|
private readonly IResourceProxy _resource;
|
||||||
private readonly IDialogService _dialog;
|
private readonly IDialogService _dialog;
|
||||||
|
private readonly INotificationService _notification;
|
||||||
private readonly GroupVm _parent;
|
private readonly GroupVm _parent;
|
||||||
private EntryVm _selectedItem;
|
private EntryVm _selectedItem;
|
||||||
private int _selectedIndex;
|
private int _selectedIndex;
|
||||||
@@ -244,14 +244,16 @@ namespace ModernKeePass.ViewModels
|
|||||||
App.Services.GetRequiredService<IMediator>(),
|
App.Services.GetRequiredService<IMediator>(),
|
||||||
App.Services.GetRequiredService<INavigationService>(),
|
App.Services.GetRequiredService<INavigationService>(),
|
||||||
App.Services.GetRequiredService<IResourceProxy>(),
|
App.Services.GetRequiredService<IResourceProxy>(),
|
||||||
App.Services.GetRequiredService<IDialogService>()) { }
|
App.Services.GetRequiredService<IDialogService>(),
|
||||||
|
App.Services.GetRequiredService<INotificationService>()) { }
|
||||||
|
|
||||||
public EntryDetailVm(string entryId, IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog)
|
public EntryDetailVm(string entryId, IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog, INotificationService notification)
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_navigation = navigation;
|
_navigation = navigation;
|
||||||
_resource = resource;
|
_resource = resource;
|
||||||
_dialog = dialog;
|
_dialog = dialog;
|
||||||
|
_notification = notification;
|
||||||
SelectedItem = _mediator.Send(new GetEntryQuery { Id = entryId }).GetAwaiter().GetResult();
|
SelectedItem = _mediator.Send(new GetEntryQuery { Id = entryId }).GetAwaiter().GetResult();
|
||||||
_parent = _mediator.Send(new GetGroupQuery { Id = SelectedItem.ParentGroupId }).GetAwaiter().GetResult();
|
_parent = _mediator.Send(new GetGroupQuery { Id = SelectedItem.ParentGroupId }).GetAwaiter().GetResult();
|
||||||
History = new ObservableCollection<EntryVm> { SelectedItem };
|
History = new ObservableCollection<EntryVm> { SelectedItem };
|
||||||
@@ -273,31 +275,22 @@ namespace ModernKeePass.ViewModels
|
|||||||
{
|
{
|
||||||
if (IsCurrentEntry)
|
if (IsCurrentEntry)
|
||||||
{
|
{
|
||||||
var isRecycleOnDelete = IsRecycleOnDelete;
|
if (IsRecycleOnDelete)
|
||||||
|
{
|
||||||
var message = isRecycleOnDelete
|
await Delete();
|
||||||
? _resource.GetResourceValue("EntryRecyclingConfirmation")
|
_notification.Show(_resource.GetResourceValue("EntryRecyclingConfirmation"), _resource.GetResourceValue("EntryRecycled"));
|
||||||
: _resource.GetResourceValue("EntryDeletingConfirmation");
|
}
|
||||||
await _dialog.ShowMessage(message,
|
else
|
||||||
|
{
|
||||||
|
await _dialog.ShowMessage(_resource.GetResourceValue("EntryDeletingConfirmation"),
|
||||||
_resource.GetResourceValue("EntityDeleteTitle"),
|
_resource.GetResourceValue("EntityDeleteTitle"),
|
||||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||||
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
||||||
async isOk =>
|
async isOk =>
|
||||||
{
|
{
|
||||||
if (isOk)
|
if (isOk) await Delete();
|
||||||
{
|
|
||||||
var text = isRecycleOnDelete
|
|
||||||
? _resource.GetResourceValue("EntryRecycled")
|
|
||||||
: _resource.GetResourceValue("EntryDeleted");
|
|
||||||
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
|
|
||||||
await _mediator.Send(new DeleteEntryCommand
|
|
||||||
{
|
|
||||||
EntryId = Id, ParentGroupId = SelectedItem.ParentGroupId,
|
|
||||||
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
|
|
||||||
});
|
});
|
||||||
_navigation.GoBack();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -305,14 +298,11 @@ namespace ModernKeePass.ViewModels
|
|||||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||||
_resource.GetResourceValue("EntityDeleteCancelButton"), async isOk =>
|
_resource.GetResourceValue("EntityDeleteCancelButton"), async isOk =>
|
||||||
{
|
{
|
||||||
if (isOk)
|
if (!isOk) return;
|
||||||
{
|
|
||||||
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
|
|
||||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||||
History.RemoveAt(SelectedIndex);
|
History.RemoveAt(SelectedIndex);
|
||||||
SelectedIndex = 0;
|
SelectedIndex = 0;
|
||||||
SaveCommand.RaiseCanExecuteChanged();
|
SaveCommand.RaiseCanExecuteChanged();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,5 +358,16 @@ namespace ModernKeePass.ViewModels
|
|||||||
SaveCommand.RaiseCanExecuteChanged();
|
SaveCommand.RaiseCanExecuteChanged();
|
||||||
_isDirty = false;
|
_isDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task Delete()
|
||||||
|
{
|
||||||
|
await _mediator.Send(new DeleteEntryCommand
|
||||||
|
{
|
||||||
|
EntryId = Id,
|
||||||
|
ParentGroupId = SelectedItem.ParentGroupId,
|
||||||
|
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
|
||||||
|
});
|
||||||
|
_navigation.GoBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
|
using GalaSoft.MvvmLight.Command;
|
||||||
using GalaSoft.MvvmLight.Views;
|
using GalaSoft.MvvmLight.Views;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -29,13 +30,11 @@ using ModernKeePass.Application.Group.Queries.GetGroup;
|
|||||||
using ModernKeePass.Application.Group.Queries.SearchEntries;
|
using ModernKeePass.Application.Group.Queries.SearchEntries;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
using ModernKeePass.Domain.Enums;
|
using ModernKeePass.Domain.Enums;
|
||||||
using ModernKeePass.Interfaces;
|
|
||||||
using ModernKeePass.Models;
|
using ModernKeePass.Models;
|
||||||
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
|
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class GroupDetailVm : ObservableObject, IVmEntity
|
public class GroupDetailVm : ObservableObject
|
||||||
{
|
{
|
||||||
public ObservableCollection<EntryVm> Entries { get; }
|
public ObservableCollection<EntryVm> Entries { get; }
|
||||||
|
|
||||||
@@ -102,6 +101,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
private readonly IResourceProxy _resource;
|
private readonly IResourceProxy _resource;
|
||||||
private readonly INavigationService _navigation;
|
private readonly INavigationService _navigation;
|
||||||
private readonly IDialogService _dialog;
|
private readonly IDialogService _dialog;
|
||||||
|
private readonly INotificationService _notification;
|
||||||
private readonly GroupVm _group;
|
private readonly GroupVm _group;
|
||||||
private readonly GroupVm _parent;
|
private readonly GroupVm _parent;
|
||||||
private bool _isEditMode;
|
private bool _isEditMode;
|
||||||
@@ -113,15 +113,17 @@ namespace ModernKeePass.ViewModels
|
|||||||
App.Services.GetRequiredService<IMediator>(),
|
App.Services.GetRequiredService<IMediator>(),
|
||||||
App.Services.GetRequiredService<IResourceProxy>(),
|
App.Services.GetRequiredService<IResourceProxy>(),
|
||||||
App.Services.GetRequiredService<INavigationService>(),
|
App.Services.GetRequiredService<INavigationService>(),
|
||||||
App.Services.GetRequiredService<IDialogService>())
|
App.Services.GetRequiredService<IDialogService>(),
|
||||||
|
App.Services.GetRequiredService<INotificationService>())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public GroupDetailVm(string groupId, IMediator mediator, IResourceProxy resource, INavigationService navigation, IDialogService dialog)
|
public GroupDetailVm(string groupId, IMediator mediator, IResourceProxy resource, INavigationService navigation, IDialogService dialog, INotificationService notification)
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_resource = resource;
|
_resource = resource;
|
||||||
_navigation = navigation;
|
_navigation = navigation;
|
||||||
_dialog = dialog;
|
_dialog = dialog;
|
||||||
|
_notification = notification;
|
||||||
_group = _mediator.Send(new GetGroupQuery { Id = groupId }).GetAwaiter().GetResult();
|
_group = _mediator.Send(new GetGroupQuery { Id = groupId }).GetAwaiter().GetResult();
|
||||||
if (!string.IsNullOrEmpty(_group.ParentGroupId))
|
if (!string.IsNullOrEmpty(_group.ParentGroupId))
|
||||||
{
|
{
|
||||||
@@ -145,29 +147,21 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
private async Task AskForDelete()
|
private async Task AskForDelete()
|
||||||
{
|
{
|
||||||
var message = IsRecycleOnDelete
|
if (IsRecycleOnDelete)
|
||||||
? _resource.GetResourceValue("GroupRecyclingConfirmation")
|
{
|
||||||
: _resource.GetResourceValue("GroupDeletingConfirmation");
|
await Delete();
|
||||||
|
_notification.Show(_resource.GetResourceValue("GroupRecyclingConfirmation"), _resource.GetResourceValue("GroupRecycled"));
|
||||||
await _dialog.ShowMessage(message, _resource.GetResourceValue("EntityDeleteTitle"),
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _dialog.ShowMessage(_resource.GetResourceValue("GroupDeletingConfirmation"), _resource.GetResourceValue("EntityDeleteTitle"),
|
||||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||||
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
||||||
async isOk =>
|
async isOk =>
|
||||||
{
|
{
|
||||||
if (isOk)
|
if (isOk) await Delete();
|
||||||
{
|
|
||||||
var text = IsRecycleOnDelete
|
|
||||||
? _resource.GetResourceValue("GroupRecycled")
|
|
||||||
: _resource.GetResourceValue("GroupDeleted");
|
|
||||||
//ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
|
|
||||||
await _mediator.Send(new DeleteGroupCommand
|
|
||||||
{
|
|
||||||
GroupId = _group.Id, ParentGroupId = _group.ParentGroupId,
|
|
||||||
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
|
|
||||||
});
|
});
|
||||||
_navigation.GoBack();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -244,5 +238,16 @@ namespace ModernKeePass.ViewModels
|
|||||||
RaisePropertyChanged(nameof(Groups));
|
RaisePropertyChanged(nameof(Groups));
|
||||||
SaveCommand.RaiseCanExecuteChanged();
|
SaveCommand.RaiseCanExecuteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task Delete()
|
||||||
|
{
|
||||||
|
await _mediator.Send(new DeleteGroupCommand
|
||||||
|
{
|
||||||
|
GroupId = _group.Id,
|
||||||
|
ParentGroupId = _group.ParentGroupId,
|
||||||
|
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
|
||||||
|
});
|
||||||
|
_navigation.GoBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ using Windows.ApplicationModel;
|
|||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Messages;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||||
@@ -12,11 +13,23 @@ using ModernKeePass.Domain.Interfaces;
|
|||||||
using ModernKeePass.Models;
|
using ModernKeePass.Models;
|
||||||
using ModernKeePass.ViewModels.ListItems;
|
using ModernKeePass.ViewModels.ListItems;
|
||||||
using ModernKeePass.Views;
|
using ModernKeePass.Views;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using GalaSoft.MvvmLight.Views;
|
||||||
|
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
||||||
|
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
||||||
|
using ModernKeePass.Common;
|
||||||
|
using ModernKeePass.Domain.Exceptions;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class MainVm : ObservableObject, IHasSelectableObject
|
public class MainVm : ViewModelBase, IHasSelectableObject
|
||||||
{
|
{
|
||||||
|
private readonly IMediator _mediator;
|
||||||
|
private readonly IRecentProxy _recent;
|
||||||
|
private readonly IResourceProxy _resource;
|
||||||
|
private readonly IDialogService _dialog;
|
||||||
|
private readonly INotificationService _notification;
|
||||||
|
private readonly INavigationService _navigation;
|
||||||
private IOrderedEnumerable<IGrouping<string, MainMenuItemVm>> _mainMenuItems;
|
private IOrderedEnumerable<IGrouping<string, MainMenuItemVm>> _mainMenuItems;
|
||||||
private ISelectableModel _selectedItem;
|
private ISelectableModel _selectedItem;
|
||||||
|
|
||||||
@@ -56,18 +69,44 @@ namespace ModernKeePass.ViewModels
|
|||||||
App.Services.GetRequiredService<IMediator>(),
|
App.Services.GetRequiredService<IMediator>(),
|
||||||
App.Services.GetRequiredService<IRecentProxy>(),
|
App.Services.GetRequiredService<IRecentProxy>(),
|
||||||
App.Services.GetRequiredService<IResourceProxy>(),
|
App.Services.GetRequiredService<IResourceProxy>(),
|
||||||
|
App.Services.GetRequiredService<IDialogService>(),
|
||||||
|
App.Services.GetRequiredService<INotificationService>(),
|
||||||
|
App.Services.GetRequiredService<INavigationService>(),
|
||||||
databaseFile)
|
databaseFile)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public MainVm(Frame referenceFrame, Frame destinationFrame, IMediator mediator, IRecentProxy recent, IResourceProxy resource, FileInfo databaseFile = null)
|
public MainVm(
|
||||||
|
Frame referenceFrame,
|
||||||
|
Frame destinationFrame,
|
||||||
|
IMediator mediator,
|
||||||
|
IRecentProxy recent,
|
||||||
|
IResourceProxy resource,
|
||||||
|
IDialogService dialog,
|
||||||
|
INotificationService notification,
|
||||||
|
INavigationService navigation,
|
||||||
|
FileInfo databaseFile = null)
|
||||||
{
|
{
|
||||||
var database = mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
_mediator = mediator;
|
||||||
|
_recent = recent;
|
||||||
|
_resource = resource;
|
||||||
|
_dialog = dialog;
|
||||||
|
_notification = notification;
|
||||||
|
_navigation = navigation;
|
||||||
|
|
||||||
|
BuildMainMenuItems(referenceFrame, destinationFrame, databaseFile);
|
||||||
|
|
||||||
|
MessengerInstance.Register<DatabaseOpenedMessage>(this, NavigateToPage);
|
||||||
|
MessengerInstance.Register<DatabaseAlreadyOpenedMessage>(this, async message => await DisplaySaveConfirmation(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildMainMenuItems(Frame referenceFrame, Frame destinationFrame, FileInfo databaseFile)
|
||||||
|
{
|
||||||
|
var database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||||
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
|
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
|
||||||
{
|
{
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemOpen"),
|
Title = _resource.GetResourceValue("MainMenuItemOpen"),
|
||||||
PageType = typeof(OpenDatabasePage),
|
PageType = typeof(OpenDatabasePage),
|
||||||
Destination = destinationFrame,
|
Destination = destinationFrame,
|
||||||
Parameter = databaseFile,
|
Parameter = databaseFile,
|
||||||
@@ -76,14 +115,14 @@ namespace ModernKeePass.ViewModels
|
|||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemNew"),
|
Title = _resource.GetResourceValue("MainMenuItemNew"),
|
||||||
PageType = typeof(NewDatabasePage),
|
PageType = typeof(NewDatabasePage),
|
||||||
Destination = destinationFrame,
|
Destination = destinationFrame,
|
||||||
SymbolIcon = Symbol.Add
|
SymbolIcon = Symbol.Add
|
||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemSave"),
|
Title = _resource.GetResourceValue("MainMenuItemSave"),
|
||||||
PageType = typeof(SaveDatabasePage),
|
PageType = typeof(SaveDatabasePage),
|
||||||
Destination = destinationFrame,
|
Destination = destinationFrame,
|
||||||
Parameter = referenceFrame,
|
Parameter = referenceFrame,
|
||||||
@@ -93,31 +132,31 @@ namespace ModernKeePass.ViewModels
|
|||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemRecent"),
|
Title = _resource.GetResourceValue("MainMenuItemRecent"),
|
||||||
PageType = typeof(RecentDatabasesPage),
|
PageType = typeof(RecentDatabasesPage),
|
||||||
Destination = destinationFrame,
|
Destination = destinationFrame,
|
||||||
Parameter = referenceFrame,
|
Parameter = referenceFrame,
|
||||||
SymbolIcon = Symbol.Copy,
|
SymbolIcon = Symbol.Copy,
|
||||||
IsSelected = !database.IsOpen && recent.EntryCount > 0,
|
IsSelected = !database.IsOpen && _recent.EntryCount > 0,
|
||||||
IsEnabled = recent.EntryCount > 0
|
IsEnabled = _recent.EntryCount > 0
|
||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemSettings"),
|
Title = _resource.GetResourceValue("MainMenuItemSettings"),
|
||||||
PageType = typeof(SettingsPage),
|
PageType = typeof(SettingsPage),
|
||||||
Destination = referenceFrame,
|
Destination = referenceFrame,
|
||||||
SymbolIcon = Symbol.Setting
|
SymbolIcon = Symbol.Setting
|
||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemAbout"),
|
Title = _resource.GetResourceValue("MainMenuItemAbout"),
|
||||||
PageType = typeof(AboutPage),
|
PageType = typeof(AboutPage),
|
||||||
Destination = destinationFrame,
|
Destination = destinationFrame,
|
||||||
SymbolIcon = Symbol.Help
|
SymbolIcon = Symbol.Help
|
||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = resource.GetResourceValue("MainMenuItemDonate"),
|
Title = _resource.GetResourceValue("MainMenuItemDonate"),
|
||||||
PageType = typeof(DonatePage),
|
PageType = typeof(DonatePage),
|
||||||
Destination = destinationFrame,
|
Destination = destinationFrame,
|
||||||
SymbolIcon = Symbol.Shop
|
SymbolIcon = Symbol.Shop
|
||||||
@@ -140,5 +179,38 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void NavigateToPage(DatabaseOpenedMessage message)
|
||||||
|
{
|
||||||
|
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DisplaySaveConfirmation(DatabaseAlreadyOpenedMessage message)
|
||||||
|
{
|
||||||
|
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||||
|
await _dialog.ShowMessage(string.Format(_resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
|
||||||
|
_resource.GetResourceValue("MessageDialogDBOpenTitle"),
|
||||||
|
_resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
|
||||||
|
_resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
|
||||||
|
async isOk =>
|
||||||
|
{
|
||||||
|
if (isOk)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _mediator.Send(new SaveDatabaseCommand());
|
||||||
|
_notification.Show(database.Name, _resource.GetResourceValue("ToastSavedMessage"));
|
||||||
|
}
|
||||||
|
catch (SaveException exception)
|
||||||
|
{
|
||||||
|
_notification.Show(exception.Source, exception.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _mediator.Send(new CloseDatabaseCommand());
|
||||||
|
MessengerInstance.Send(new DatabaseClosedMessage { Parameter = message.Parameter });
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,8 +44,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<IResourceProxy>()) { }
|
|
||||||
|
|
||||||
public SettingsVm(IMediator mediator, IResourceProxy resource)
|
public SettingsVm(IMediator mediator, IResourceProxy resource)
|
||||||
{
|
{
|
||||||
var database = mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
var database = mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||||
|
@@ -3,6 +3,7 @@ using Windows.UI.Xaml;
|
|||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Data;
|
using Windows.UI.Xaml.Data;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
using GalaSoft.MvvmLight.Command;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
using ModernKeePass.Domain.Interfaces;
|
using ModernKeePass.Domain.Interfaces;
|
||||||
|
|
||||||
|
@@ -22,15 +22,6 @@ namespace ModernKeePass.Views
|
|||||||
|
|
||||||
#region Inscription de NavigationHelper
|
#region Inscription de NavigationHelper
|
||||||
|
|
||||||
/// Les méthodes fournies dans cette section sont utilisées simplement pour permettre
|
|
||||||
/// NavigationHelper pour répondre aux méthodes de navigation de la page.
|
|
||||||
///
|
|
||||||
/// La logique spécifique à la page doit être placée dans les gestionnaires d'événements pour
|
|
||||||
/// <see cref="Common.NavigationHelper.LoadState"/>
|
|
||||||
/// et <see cref="Common.NavigationHelper.SaveState"/>.
|
|
||||||
/// Le paramètre de navigation est disponible dans la méthode LoadState
|
|
||||||
/// en plus de l'état de page conservé durant une session antérieure.
|
|
||||||
|
|
||||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||||
{
|
{
|
||||||
var args = e.Parameter as NavigationItem;
|
var args = e.Parameter as NavigationItem;
|
||||||
|
@@ -38,15 +38,6 @@ namespace ModernKeePass.Views
|
|||||||
|
|
||||||
#region NavigationHelper registration
|
#region NavigationHelper registration
|
||||||
|
|
||||||
/// The methods provided in this section are simply used to allow
|
|
||||||
/// NavigationHelper to respond to the page's navigation methods.
|
|
||||||
///
|
|
||||||
/// Page specific logic should be placed in event handlers for the
|
|
||||||
/// <see cref="Common.NavigationHelper.LoadState"/>
|
|
||||||
/// and <see cref="Common.NavigationHelper.SaveState"/>.
|
|
||||||
/// The navigation parameter is available in the LoadState method
|
|
||||||
/// in addition to page state preserved during an earlier session.
|
|
||||||
///
|
|
||||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||||
{
|
{
|
||||||
var navigationItem = e.Parameter as NavigationItem;
|
var navigationItem = e.Parameter as NavigationItem;
|
||||||
|
@@ -18,10 +18,16 @@ namespace ModernKeePass.Views
|
|||||||
public MainPage()
|
public MainPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Unloaded += MainPage_Unloaded;
|
||||||
ListView = MenuListView;
|
ListView = MenuListView;
|
||||||
ListViewSource = MenuItemsSource;
|
ListViewSource = MenuItemsSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MainPage_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Model.Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
private new void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private new void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
base.ListView_SelectionChanged(sender, e);
|
base.ListView_SelectionChanged(sender, e);
|
||||||
|
@@ -5,15 +5,14 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:converters="using:ModernKeePass.Converters"
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
|
||||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding Source={StaticResource Locator}, Path=New}">
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||||
<viewModels:NewVm x:Key="ViewModel"/>
|
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<HyperlinkButton x:Uid="NewCreateButton" Click="CreateDatabaseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
<HyperlinkButton x:Uid="NewCreateButton" Click="CreateDatabaseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" />
|
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" />
|
||||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||||
|
@@ -20,7 +20,7 @@ namespace ModernKeePass.Views
|
|||||||
public sealed partial class NewDatabasePage
|
public sealed partial class NewDatabasePage
|
||||||
{
|
{
|
||||||
private readonly IResourceProxy _resource;
|
private readonly IResourceProxy _resource;
|
||||||
private NewVm Model => (NewVm)Resources["ViewModel"];
|
private NewVm Model => (NewVm)DataContext;
|
||||||
|
|
||||||
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
|
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
|
||||||
public NewDatabasePage(IResourceProxy resource)
|
public NewDatabasePage(IResourceProxy resource)
|
||||||
@@ -41,7 +41,7 @@ namespace ModernKeePass.Views
|
|||||||
var file = await savePicker.PickSaveFileAsync().AsTask();
|
var file = await savePicker.PickSaveFileAsync().AsTask();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
var fileInfo = new FileInfo
|
var fileInfo = new FileInfo
|
||||||
{
|
{
|
||||||
Id = token,
|
Id = token,
|
||||||
|
@@ -3,17 +3,16 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
|
||||||
xmlns:converters="using:ModernKeePass.Converters"
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||||
x:Class="ModernKeePass.Views.OpenDatabasePage"
|
x:Class="ModernKeePass.Views.OpenDatabasePage"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding Source={StaticResource Locator}, Path=Open}">
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||||
<viewModels:OpenVm x:Key="ViewModel"/>
|
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<HyperlinkButton x:Uid="OpenBrowseButton" Click="ButtonBase_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
<HyperlinkButton x:Uid="OpenBrowseButton" Click="ButtonBase_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" />
|
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" />
|
||||||
<!--<HyperlinkButton x:Uid="OpenUrlButton" IsEnabled="False" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
<!--<HyperlinkButton x:Uid="OpenUrlButton" IsEnabled="False" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||||
|
@@ -3,13 +3,7 @@ using Windows.Storage.AccessCache;
|
|||||||
using Windows.Storage.Pickers;
|
using Windows.Storage.Pickers;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
using GalaSoft.MvvmLight.Messaging;
|
|
||||||
using GalaSoft.MvvmLight.Views;
|
|
||||||
using Messages;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Common;
|
|
||||||
using ModernKeePass.Domain.Dtos;
|
using ModernKeePass.Domain.Dtos;
|
||||||
using ModernKeePass.Models;
|
|
||||||
using ModernKeePass.ViewModels;
|
using ModernKeePass.ViewModels;
|
||||||
|
|
||||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
@@ -21,24 +15,11 @@ namespace ModernKeePass.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class OpenDatabasePage
|
public sealed partial class OpenDatabasePage
|
||||||
{
|
{
|
||||||
private readonly INavigationService _navigation;
|
private OpenVm Model => (OpenVm)DataContext;
|
||||||
private OpenVm Model => (OpenVm)Resources["ViewModel"];
|
|
||||||
|
|
||||||
public OpenDatabasePage(): this(
|
public OpenDatabasePage()
|
||||||
App.Services.GetRequiredService<INavigationService>(),
|
|
||||||
App.Services.GetRequiredService<IMessenger>()) { }
|
|
||||||
|
|
||||||
public OpenDatabasePage(INavigationService navigation, IMessenger messenger)
|
|
||||||
{
|
{
|
||||||
_navigation = navigation;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void NavigateToPage(DatabaseOpenedMessage message)
|
|
||||||
{
|
|
||||||
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||||
@@ -64,8 +45,7 @@ namespace ModernKeePass.Views
|
|||||||
var file = await picker.PickSingleFileAsync().AsTask();
|
var file = await picker.PickSingleFileAsync().AsTask();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
|
||||||
var fileInfo = new FileInfo
|
var fileInfo = new FileInfo
|
||||||
{
|
{
|
||||||
Path = file.Path,
|
Path = file.Path,
|
||||||
|
@@ -3,16 +3,15 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
|
||||||
xmlns:converters="using:ModernKeePass.Converters"
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||||
x:Class="ModernKeePass.Views.RecentDatabasesPage"
|
x:Class="ModernKeePass.Views.RecentDatabasesPage"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding Source={StaticResource Locator}, Path=Recent}">
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||||
<viewModels:RecentVm x:Key="ViewModel"/>
|
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="40" />
|
<RowDefinition Height="40" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
|
@@ -1,11 +1,5 @@
|
|||||||
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
|
|
||||||
using GalaSoft.MvvmLight.Messaging;
|
|
||||||
using GalaSoft.MvvmLight.Views;
|
|
||||||
using Messages;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Common;
|
|
||||||
using ModernKeePass.Models;
|
|
||||||
using ModernKeePass.ViewModels;
|
using ModernKeePass.ViewModels;
|
||||||
|
|
||||||
namespace ModernKeePass.Views
|
namespace ModernKeePass.Views
|
||||||
@@ -15,29 +9,11 @@ namespace ModernKeePass.Views
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class RecentDatabasesPage
|
public sealed partial class RecentDatabasesPage
|
||||||
{
|
{
|
||||||
private RecentVm Model => (RecentVm)Resources["ViewModel"];
|
private RecentVm Model => (RecentVm)DataContext;
|
||||||
|
|
||||||
private readonly INavigationService _navigation;
|
public RecentDatabasesPage()
|
||||||
private readonly IMessenger _messenger;
|
|
||||||
|
|
||||||
public RecentDatabasesPage(): this(
|
|
||||||
App.Services.GetRequiredService<INavigationService>(),
|
|
||||||
App.Services.GetRequiredService<IMessenger>())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public RecentDatabasesPage(INavigationService navigation, IMessenger messenger)
|
|
||||||
{
|
{
|
||||||
_navigation = navigation;
|
|
||||||
_messenger = messenger;
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
messenger.Register<DatabaseOpeningMessage>(this, action => Model.UpdateAccessTime(action.Token));
|
|
||||||
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void NavigateToPage(DatabaseOpenedMessage message)
|
|
||||||
{
|
|
||||||
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,12 +3,9 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
|
||||||
x:Class="ModernKeePass.Views.SaveDatabasePage"
|
x:Class="ModernKeePass.Views.SaveDatabasePage"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d"
|
||||||
<Page.DataContext>
|
DataContext="{Binding Source={StaticResource Locator}, Path=Save}">
|
||||||
<viewModels:SaveVm/>
|
|
||||||
</Page.DataContext>
|
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<HyperlinkButton x:Uid="SaveButton" Command="{Binding SaveCommand}" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
<HyperlinkButton x:Uid="SaveButton" Command="{Binding SaveCommand}" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||||
|
@@ -4,17 +4,14 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:controls="using:ModernKeePass.Controls"
|
xmlns:controls="using:ModernKeePass.Controls"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
|
||||||
xmlns:basePages="using:ModernKeePass.Views.BasePages"
|
xmlns:basePages="using:ModernKeePass.Views.BasePages"
|
||||||
x:Name="PageRoot"
|
x:Name="PageRoot"
|
||||||
x:Class="ModernKeePass.Views.SettingsPage"
|
x:Class="ModernKeePass.Views.SettingsPage"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d"
|
||||||
|
DataContext="{Binding Source={StaticResource Locator}, Path=Settings}">
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<CollectionViewSource x:Name="MenuItemsSource" Source="{Binding MenuItems}" IsSourceGrouped="True" />
|
<CollectionViewSource x:Name="MenuItemsSource" Source="{Binding MenuItems}" IsSourceGrouped="True" />
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
<Page.DataContext>
|
|
||||||
<viewModels:SettingsVm />
|
|
||||||
</Page.DataContext>
|
|
||||||
|
|
||||||
<Page.Background>
|
<Page.Background>
|
||||||
<StaticResource ResourceKey="ApplicationPageBackgroundThemeBrush"/>
|
<StaticResource ResourceKey="ApplicationPageBackgroundThemeBrush"/>
|
||||||
|
@@ -5,12 +5,11 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:converters="using:ModernKeePass.Converters"
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
mc:Ignorable="d"
|
||||||
mc:Ignorable="d">
|
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsDatabase}">
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||||
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
|
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
|
||||||
<listItems:SettingsDatabaseVm x:Key="ViewModel"/>
|
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||||
|
@@ -4,13 +4,10 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
mc:Ignorable="d"
|
||||||
mc:Ignorable="d">
|
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsNew}">
|
||||||
<Page.Resources>
|
|
||||||
<listItems:SettingsNewVm x:Key="ViewModel"/>
|
|
||||||
</Page.Resources>
|
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<StackPanel.Resources>
|
<StackPanel.Resources>
|
||||||
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding FileFormats}" />
|
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding FileFormats}" />
|
||||||
</StackPanel.Resources>
|
</StackPanel.Resources>
|
||||||
|
@@ -4,13 +4,10 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
mc:Ignorable="d"
|
||||||
mc:Ignorable="d">
|
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsSave}">
|
||||||
<Page.Resources>
|
|
||||||
<listItems:SettingsSaveVm x:Name="ViewModel"/>
|
|
||||||
</Page.Resources>
|
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<TextBlock x:Uid="SettingsSaveDatabaseSuspendTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,10"/>
|
<TextBlock x:Uid="SettingsSaveDatabaseSuspendTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,10"/>
|
||||||
<TextBlock x:Uid="SettingsSaveDatabaseSuspendDesc" TextWrapping="WrapWholeWords" Margin="5,0,0,10"/>
|
<TextBlock x:Uid="SettingsSaveDatabaseSuspendDesc" TextWrapping="WrapWholeWords" Margin="5,0,0,10"/>
|
||||||
<ToggleSwitch x:Uid="SettingsSaveDatabaseSuspend" IsOn="{Binding IsSaveSuspend, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" />
|
<ToggleSwitch x:Uid="SettingsSaveDatabaseSuspend" IsOn="{Binding IsSaveSuspend, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" />
|
||||||
|
@@ -5,13 +5,10 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
mc:Ignorable="d"
|
||||||
mc:Ignorable="d">
|
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsSecurity}">
|
||||||
<Page.Resources>
|
|
||||||
<listItems:SettingsSecurityVm x:Key="ViewModel"/>
|
|
||||||
</Page.Resources>
|
|
||||||
|
|
||||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<TextBlock x:Uid="SettingsSecurityTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,0" />
|
<TextBlock x:Uid="SettingsSecurityTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,0" />
|
||||||
<TextBlock TextWrapping="WrapWholeWords" Margin="5,0,0,0">
|
<TextBlock TextWrapping="WrapWholeWords" Margin="5,0,0,0">
|
||||||
<Run x:Uid="SettingsSecurityDesc1" />
|
<Run x:Uid="SettingsSecurityDesc1" />
|
||||||
|
@@ -7,14 +7,12 @@
|
|||||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:converters="using:ModernKeePass.Converters"
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
|
||||||
mc:Ignorable="d" >
|
mc:Ignorable="d" >
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||||
<viewModels:OpenDatabaseControlVm x:Key="ViewModel"/>
|
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<Grid DataContext="{StaticResource ViewModel}">
|
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=OpenDatabaseControl}">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="50" />
|
<ColumnDefinition Width="50" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
|
@@ -12,7 +12,7 @@ namespace ModernKeePass.Views.UserControls
|
|||||||
{
|
{
|
||||||
public sealed partial class OpenDatabaseUserControl
|
public sealed partial class OpenDatabaseUserControl
|
||||||
{
|
{
|
||||||
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Resources["ViewModel"];
|
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Grid.DataContext;
|
||||||
|
|
||||||
public string DatabaseFilePath
|
public string DatabaseFilePath
|
||||||
{
|
{
|
||||||
@@ -52,7 +52,7 @@ namespace ModernKeePass.Views.UserControls
|
|||||||
var file = await picker.PickSingleFileAsync();
|
var file = await picker.PickSingleFileAsync();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
Model.KeyFilePath = token;
|
Model.KeyFilePath = token;
|
||||||
Model.KeyFileText = file.DisplayName;
|
Model.KeyFileText = file.DisplayName;
|
||||||
}
|
}
|
||||||
|
@@ -7,16 +7,14 @@
|
|||||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:converters="using:ModernKeePass.Converters"
|
xmlns:converters="using:ModernKeePass.Converters"
|
||||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
mc:Ignorable="d">
|
||||||
mc:Ignorable="d" >
|
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
|
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
|
||||||
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
|
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
|
||||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||||
<viewModels:SetCredentialsVm x:Key="ViewModel"/>
|
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<Grid DataContext="{StaticResource ViewModel}">
|
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=SetCredentials}">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="50" />
|
<ColumnDefinition Width="50" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
|
@@ -11,7 +11,7 @@ namespace ModernKeePass.Views.UserControls
|
|||||||
{
|
{
|
||||||
public sealed partial class SetCredentialsUserControl
|
public sealed partial class SetCredentialsUserControl
|
||||||
{
|
{
|
||||||
private SetCredentialsVm Model => (SetCredentialsVm)Resources["ViewModel"];
|
private SetCredentialsVm Model => (SetCredentialsVm)Grid.DataContext;
|
||||||
|
|
||||||
public string ButtonLabel
|
public string ButtonLabel
|
||||||
{
|
{
|
||||||
@@ -44,7 +44,7 @@ namespace ModernKeePass.Views.UserControls
|
|||||||
var file = await picker.PickSingleFileAsync();
|
var file = await picker.PickSingleFileAsync();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
Model.KeyFilePath = token;
|
Model.KeyFilePath = token;
|
||||||
Model.KeyFileText = file.DisplayName;
|
Model.KeyFileText = file.DisplayName;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ namespace ModernKeePass.Views.UserControls
|
|||||||
var file = await savePicker.PickSaveFileAsync();
|
var file = await savePicker.PickSaveFileAsync();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
Model.KeyFilePath = token;
|
Model.KeyFilePath = token;
|
||||||
Model.KeyFileText = file.DisplayName;
|
Model.KeyFileText = file.DisplayName;
|
||||||
await Model.GenerateKeyFile();
|
await Model.GenerateKeyFile();
|
||||||
|
@@ -94,8 +94,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="DependencyInjection.cs" />
|
<Compile Include="DependencyInjection.cs" />
|
||||||
<Compile Include="Models\NavigationItem.cs" />
|
<Compile Include="Models\NavigationItem.cs" />
|
||||||
<Compile Include="ViewModel\MainViewModel.cs" />
|
|
||||||
<Compile Include="ViewModel\ViewModelLocator.cs" />
|
|
||||||
<Compile Include="Views\MainPageFrames\DonatePage.xaml.cs">
|
<Compile Include="Views\MainPageFrames\DonatePage.xaml.cs">
|
||||||
<DependentUpon>DonatePage.xaml</DependentUpon>
|
<DependentUpon>DonatePage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -124,7 +122,6 @@
|
|||||||
<Compile Include="Views\UserControls\ColorPickerUserControl.xaml.cs">
|
<Compile Include="Views\UserControls\ColorPickerUserControl.xaml.cs">
|
||||||
<DependentUpon>ColorPickerUserControl.xaml</DependentUpon>
|
<DependentUpon>ColorPickerUserControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Interfaces\IVmEntity.cs" />
|
|
||||||
<Compile Include="Views\MainPage.xaml.cs">
|
<Compile Include="Views\MainPage.xaml.cs">
|
||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -140,7 +137,6 @@
|
|||||||
<Compile Include="Views\MainPageFrames\WelcomePage.xaml.cs">
|
<Compile Include="Views\MainPageFrames\WelcomePage.xaml.cs">
|
||||||
<DependentUpon>WelcomePage.xaml</DependentUpon>
|
<DependentUpon>WelcomePage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="ViewModels\CompositeKeyVm.cs" />
|
|
||||||
<Compile Include="Views\EntryDetailPage.xaml.cs">
|
<Compile Include="Views\EntryDetailPage.xaml.cs">
|
||||||
<DependentUpon>EntryDetailPage.xaml</DependentUpon>
|
<DependentUpon>EntryDetailPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@@ -5,6 +5,7 @@ using Windows.UI.Core;
|
|||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
using GalaSoft.MvvmLight.Command;
|
||||||
|
|
||||||
namespace ModernKeePass.Common
|
namespace ModernKeePass.Common
|
||||||
{
|
{
|
||||||
@@ -77,8 +78,8 @@ namespace ModernKeePass.Common
|
|||||||
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
|
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
|
||||||
#else
|
#else
|
||||||
// Keyboard and mouse navigation only apply when occupying the entire window
|
// Keyboard and mouse navigation only apply when occupying the entire window
|
||||||
if (this.Page.ActualHeight == Window.Current.Bounds.Height &&
|
if (Page.ActualHeight == Window.Current.Bounds.Height &&
|
||||||
this.Page.ActualWidth == Window.Current.Bounds.Width)
|
Page.ActualWidth == Window.Current.Bounds.Width)
|
||||||
{
|
{
|
||||||
// Listen to the window directly so focus isn't required
|
// Listen to the window directly so focus isn't required
|
||||||
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated +=
|
Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated +=
|
||||||
|
@@ -1,156 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Windows.Foundation.Collections;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Common
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Implementation of IObservableMap that supports reentrancy for use as a default view
|
|
||||||
/// model.
|
|
||||||
/// </summary>
|
|
||||||
public class ObservableDictionary : IObservableMap<string, object>
|
|
||||||
{
|
|
||||||
private class ObservableDictionaryChangedEventArgs : IMapChangedEventArgs<string>
|
|
||||||
{
|
|
||||||
public ObservableDictionaryChangedEventArgs(CollectionChange change, string key)
|
|
||||||
{
|
|
||||||
CollectionChange = change;
|
|
||||||
Key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CollectionChange CollectionChange { get; private set; }
|
|
||||||
public string Key { get; private set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<string, object> _dictionary = new Dictionary<string, object>();
|
|
||||||
public event MapChangedEventHandler<string, object> MapChanged;
|
|
||||||
|
|
||||||
private void InvokeMapChanged(CollectionChange change, string key)
|
|
||||||
{
|
|
||||||
var eventHandler = MapChanged;
|
|
||||||
if (eventHandler != null)
|
|
||||||
{
|
|
||||||
eventHandler(this, new ObservableDictionaryChangedEventArgs(change, key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(string key, object value)
|
|
||||||
{
|
|
||||||
_dictionary.Add(key, value);
|
|
||||||
InvokeMapChanged(CollectionChange.ItemInserted, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(KeyValuePair<string, object> item)
|
|
||||||
{
|
|
||||||
Add(item.Key, item.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddRange(IEnumerable<KeyValuePair<string, object>> values)
|
|
||||||
{
|
|
||||||
foreach (var value in values)
|
|
||||||
{
|
|
||||||
Add(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(string key)
|
|
||||||
{
|
|
||||||
if (_dictionary.Remove(key))
|
|
||||||
{
|
|
||||||
InvokeMapChanged(CollectionChange.ItemRemoved, key);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(KeyValuePair<string, object> item)
|
|
||||||
{
|
|
||||||
object currentValue;
|
|
||||||
if (_dictionary.TryGetValue(item.Key, out currentValue) &&
|
|
||||||
Equals(item.Value, currentValue) && _dictionary.Remove(item.Key))
|
|
||||||
{
|
|
||||||
InvokeMapChanged(CollectionChange.ItemRemoved, item.Key);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object this[string key]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _dictionary[key];
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_dictionary[key] = value;
|
|
||||||
InvokeMapChanged(CollectionChange.ItemChanged, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
var priorKeys = _dictionary.Keys.ToArray();
|
|
||||||
_dictionary.Clear();
|
|
||||||
foreach (var key in priorKeys)
|
|
||||||
{
|
|
||||||
InvokeMapChanged(CollectionChange.ItemRemoved, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICollection<string> Keys
|
|
||||||
{
|
|
||||||
get { return _dictionary.Keys; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ContainsKey(string key)
|
|
||||||
{
|
|
||||||
return _dictionary.ContainsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetValue(string key, out object value)
|
|
||||||
{
|
|
||||||
return _dictionary.TryGetValue(key, out value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICollection<object> Values
|
|
||||||
{
|
|
||||||
get { return _dictionary.Values; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Contains(KeyValuePair<string, object> item)
|
|
||||||
{
|
|
||||||
return _dictionary.Contains(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Count
|
|
||||||
{
|
|
||||||
get { return _dictionary.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsReadOnly
|
|
||||||
{
|
|
||||||
get { return false; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
|
|
||||||
{
|
|
||||||
return _dictionary.GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return _dictionary.GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
|
|
||||||
{
|
|
||||||
int arraySize = array.Length;
|
|
||||||
foreach (var pair in _dictionary)
|
|
||||||
{
|
|
||||||
if (arrayIndex >= arraySize) break;
|
|
||||||
array[arrayIndex++] = pair;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,78 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Windows.Input;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Common
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A command whose sole purpose is to relay its functionality
|
|
||||||
/// to other objects by invoking delegates.
|
|
||||||
/// The default return value for the CanExecute method is 'true'.
|
|
||||||
/// <see cref="RaiseCanExecuteChanged"/> needs to be called whenever
|
|
||||||
/// <see cref="CanExecute"/> is expected to return a different value.
|
|
||||||
/// </summary>
|
|
||||||
public class RelayCommand : ICommand
|
|
||||||
{
|
|
||||||
private readonly Action _execute;
|
|
||||||
private readonly Func<bool> _canExecute;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Raised when RaiseCanExecuteChanged is called.
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler CanExecuteChanged;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new command that can always execute.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="execute">The execution logic.</param>
|
|
||||||
public RelayCommand(Action execute)
|
|
||||||
: this(execute, null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new command.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="execute">The execution logic.</param>
|
|
||||||
/// <param name="canExecute">The execution status logic.</param>
|
|
||||||
public RelayCommand(Action execute, Func<bool> canExecute)
|
|
||||||
{
|
|
||||||
if (execute == null)
|
|
||||||
throw new ArgumentNullException(nameof(execute));
|
|
||||||
_execute = execute;
|
|
||||||
_canExecute = canExecute;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether this <see cref="RelayCommand"/> can execute in its current state.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="parameter">
|
|
||||||
/// Data used by the command. If the command does not require data to be passed, this object can be set to null.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>true if this command can be executed; otherwise, false.</returns>
|
|
||||||
public bool CanExecute(object parameter)
|
|
||||||
{
|
|
||||||
return _canExecute?.Invoke() ?? true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Executes the <see cref="RelayCommand"/> on the current command target.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="parameter">
|
|
||||||
/// Data used by the command. If the command does not require data to be passed, this object can be set to null.
|
|
||||||
/// </param>
|
|
||||||
public void Execute(object parameter)
|
|
||||||
{
|
|
||||||
_execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Method used to raise the <see cref="CanExecuteChanged"/> event
|
|
||||||
/// to indicate that the return value of the <see cref="CanExecute"/>
|
|
||||||
/// method has changed.
|
|
||||||
/// </summary>
|
|
||||||
public void RaiseCanExecuteChanged()
|
|
||||||
{
|
|
||||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Events
|
|
||||||
{
|
|
||||||
public class PasswordEventArgs: EventArgs
|
|
||||||
{
|
|
||||||
public string RootGroupId { get; set; }
|
|
||||||
|
|
||||||
public PasswordEventArgs(string groupId)
|
|
||||||
{
|
|
||||||
RootGroupId = groupId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -4,6 +4,6 @@ namespace Messages
|
|||||||
{
|
{
|
||||||
public class DatabaseAlreadyOpenedMessage
|
public class DatabaseAlreadyOpenedMessage
|
||||||
{
|
{
|
||||||
public DatabaseVm OpenedDatabase { get; set; }
|
public object Parameter { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,6 +2,6 @@
|
|||||||
{
|
{
|
||||||
public class DatabaseClosedMessage
|
public class DatabaseClosedMessage
|
||||||
{
|
{
|
||||||
|
public object Parameter { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -3,7 +3,6 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Application.Database.Models;
|
using ModernKeePass.Application.Database.Models;
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||||
@@ -77,8 +76,6 @@ namespace ModernKeePass.ViewModels.ListItems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsDatabaseVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
|
||||||
|
|
||||||
public SettingsDatabaseVm(IMediator mediator)
|
public SettingsDatabaseVm(IMediator mediator)
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
|
|
||||||
@@ -10,9 +9,6 @@ namespace ModernKeePass.ViewModels.ListItems
|
|||||||
{
|
{
|
||||||
private readonly ISettingsProxy _settings;
|
private readonly ISettingsProxy _settings;
|
||||||
|
|
||||||
public SettingsNewVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public SettingsNewVm(ISettingsProxy settings)
|
public SettingsNewVm(ISettingsProxy settings)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
|
|
||||||
@@ -8,9 +7,6 @@ namespace ModernKeePass.ViewModels.ListItems
|
|||||||
{
|
{
|
||||||
private readonly ISettingsProxy _settings;
|
private readonly ISettingsProxy _settings;
|
||||||
|
|
||||||
public SettingsSaveVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public SettingsSaveVm(ISettingsProxy settings)
|
public SettingsSaveVm(ISettingsProxy settings)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
@@ -1,34 +1,26 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GalaSoft.MvvmLight.Messaging;
|
using GalaSoft.MvvmLight;
|
||||||
using GalaSoft.MvvmLight.Views;
|
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Messages;
|
using Messages;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels.ListItems
|
namespace ModernKeePass.ViewModels.ListItems
|
||||||
{
|
{
|
||||||
public class SettingsSecurityVm
|
public class SettingsSecurityVm: ViewModelBase
|
||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly IResourceProxy _resource;
|
private readonly IResourceProxy _resource;
|
||||||
private readonly INotificationService _notification;
|
private readonly INotificationService _notification;
|
||||||
|
|
||||||
public SettingsSecurityVm(): this(
|
public SettingsSecurityVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
|
||||||
App.Services.GetRequiredService<IMediator>(),
|
|
||||||
App.Services.GetRequiredService<IMessenger>(),
|
|
||||||
App.Services.GetRequiredService<IResourceProxy>(),
|
|
||||||
App.Services.GetRequiredService<INotificationService>()) { }
|
|
||||||
|
|
||||||
public SettingsSecurityVm(IMediator mediator, IMessenger messenger, IResourceProxy resource, INotificationService notification)
|
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_resource = resource;
|
_resource = resource;
|
||||||
_notification = notification;
|
_notification = notification;
|
||||||
|
|
||||||
messenger.Register<CredentialsSetMessage>(this, async message => await UpdateDatabaseCredentials(message));
|
MessengerInstance.Register<CredentialsSetMessage>(this, async message => await UpdateDatabaseCredentials(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateDatabaseCredentials(CredentialsSetMessage message)
|
public async Task UpdateDatabaseCredentials(CredentialsSetMessage message)
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using GalaSoft.MvvmLight.Messaging;
|
|
||||||
using GalaSoft.MvvmLight.Views;
|
using GalaSoft.MvvmLight.Views;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Messages;
|
using Messages;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Application.Database.Commands.CreateDatabase;
|
using ModernKeePass.Application.Database.Commands.CreateDatabase;
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||||
@@ -38,22 +36,27 @@ namespace ModernKeePass.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NewVm(): this(
|
public NewVm(IMediator mediator, IRecentProxy recent, ISettingsProxy settings, INavigationService navigation) : base(recent)
|
||||||
App.Services.GetRequiredService<IMediator>(),
|
|
||||||
App.Services.GetRequiredService<ISettingsProxy>(),
|
|
||||||
App.Services.GetRequiredService<IMessenger>(),
|
|
||||||
App.Services.GetRequiredService<INavigationService>()) { }
|
|
||||||
|
|
||||||
public NewVm(IMediator mediator, ISettingsProxy settings, IMessenger messenger, INavigationService navigation)
|
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_navigation = navigation;
|
_navigation = navigation;
|
||||||
|
|
||||||
messenger.Register<CredentialsSetMessage>(this, async message => await CreateDatabase(message));
|
MessengerInstance.Register<CredentialsSetMessage>(this, async m => await TryCreateDatabase(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateDatabase(CredentialsSetMessage message)
|
private async Task TryCreateDatabase(CredentialsSetMessage message)
|
||||||
|
{
|
||||||
|
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||||
|
if (database.IsDirty)
|
||||||
|
{
|
||||||
|
MessengerInstance.Register<DatabaseClosedMessage>(this, async m => await CreateDatabase(m.Parameter as CredentialsSetMessage));
|
||||||
|
MessengerInstance.Send(new DatabaseAlreadyOpenedMessage { Parameter = message });
|
||||||
|
}
|
||||||
|
else await CreateDatabase(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CreateDatabase(CredentialsSetMessage message)
|
||||||
{
|
{
|
||||||
await _mediator.Send(new CreateDatabaseCommand
|
await _mediator.Send(new CreateDatabaseCommand
|
||||||
{
|
{
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Domain.Dtos;
|
using ModernKeePass.Domain.Dtos;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class OpenVm: ObservableObject
|
public class OpenVm: ViewModelBase
|
||||||
{
|
{
|
||||||
private readonly IRecentProxy _recent;
|
private readonly IRecentProxy _recent;
|
||||||
private string _name;
|
private string _name;
|
||||||
@@ -32,8 +31,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
private set { Set(() => Path, ref _path, value); }
|
private set { Set(() => Path, ref _path, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
|
|
||||||
|
|
||||||
public OpenVm(IRecentProxy recent)
|
public OpenVm(IRecentProxy recent)
|
||||||
{
|
{
|
||||||
_recent = recent;
|
_recent = recent;
|
||||||
|
@@ -1,16 +1,17 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using GalaSoft.MvvmLight.Command;
|
using GalaSoft.MvvmLight.Command;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Messages;
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Domain.Interfaces;
|
using ModernKeePass.Domain.Interfaces;
|
||||||
using ModernKeePass.ViewModels.ListItems;
|
using ModernKeePass.ViewModels.ListItems;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class RecentVm : ObservableObject, IHasSelectableObject
|
public class RecentVm : ViewModelBase, IHasSelectableObject
|
||||||
{
|
{
|
||||||
private readonly IRecentProxy _recent;
|
private readonly IRecentProxy _recent;
|
||||||
private ISelectableModel _selectedItem;
|
private ISelectableModel _selectedItem;
|
||||||
@@ -42,8 +43,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
public ICommand ClearAllCommand { get; }
|
public ICommand ClearAllCommand { get; }
|
||||||
|
|
||||||
public RecentVm() : this (App.Services.GetRequiredService<IRecentProxy>()) { }
|
|
||||||
|
|
||||||
public RecentVm(IRecentProxy recent)
|
public RecentVm(IRecentProxy recent)
|
||||||
{
|
{
|
||||||
_recent = recent;
|
_recent = recent;
|
||||||
@@ -53,11 +52,13 @@ namespace ModernKeePass.ViewModels
|
|||||||
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
||||||
if (RecentItems.Count > 0)
|
if (RecentItems.Count > 0)
|
||||||
SelectedItem = RecentItems[0];
|
SelectedItem = RecentItems[0];
|
||||||
|
|
||||||
|
MessengerInstance.Register<DatabaseOpeningMessage>(this, async action => await UpdateAccessTime(action.Token));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateAccessTime(string token)
|
private async Task UpdateAccessTime(string token)
|
||||||
{
|
{
|
||||||
_recent.Get(token, true).Wait();
|
await _recent.Get(token, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearAll()
|
private void ClearAll()
|
||||||
|
@@ -3,7 +3,6 @@ using Windows.Storage;
|
|||||||
using Windows.Storage.AccessCache;
|
using Windows.Storage.AccessCache;
|
||||||
using GalaSoft.MvvmLight.Views;
|
using GalaSoft.MvvmLight.Views;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
||||||
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||||
@@ -22,8 +21,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly INavigationService _navigation;
|
private readonly INavigationService _navigation;
|
||||||
|
|
||||||
public SaveVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<INavigationService>()) { }
|
|
||||||
|
|
||||||
public SaveVm(IMediator mediator, INavigationService navigation)
|
public SaveVm(IMediator mediator, INavigationService navigation)
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
@@ -41,7 +38,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
public async Task Save(StorageFile file)
|
public async Task Save(StorageFile file)
|
||||||
{
|
{
|
||||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||||
await _mediator.Send(new SaveDatabaseCommand { FilePath = token });
|
await _mediator.Send(new SaveDatabaseCommand { FilePath = token });
|
||||||
_navigation.NavigateTo(Constants.Navigation.MainPage);
|
_navigation.NavigateTo(Constants.Navigation.MainPage);
|
||||||
}
|
}
|
||||||
|
@@ -3,20 +3,15 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using GalaSoft.MvvmLight.Command;
|
using GalaSoft.MvvmLight.Command;
|
||||||
using GalaSoft.MvvmLight.Messaging;
|
|
||||||
using GalaSoft.MvvmLight.Views;
|
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Messages;
|
using Messages;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
|
||||||
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
|
||||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||||
using ModernKeePass.Application.Database.Queries.OpenDatabase;
|
using ModernKeePass.Application.Database.Queries.OpenDatabase;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class OpenDatabaseControlVm : ObservableObject
|
public class OpenDatabaseControlVm : ViewModelBase
|
||||||
{
|
{
|
||||||
public enum StatusTypes
|
public enum StatusTypes
|
||||||
{
|
{
|
||||||
@@ -100,9 +95,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly IResourceProxy _resource;
|
private readonly IResourceProxy _resource;
|
||||||
private readonly IMessenger _messenger;
|
|
||||||
private readonly IDialogService _dialog;
|
|
||||||
private readonly INotificationService _notification;
|
|
||||||
private bool _hasPassword;
|
private bool _hasPassword;
|
||||||
private bool _hasKeyFile;
|
private bool _hasKeyFile;
|
||||||
private bool _isOpening;
|
private bool _isOpening;
|
||||||
@@ -113,21 +105,10 @@ namespace ModernKeePass.ViewModels
|
|||||||
private string _keyFileText;
|
private string _keyFileText;
|
||||||
private string _openButtonLabel;
|
private string _openButtonLabel;
|
||||||
|
|
||||||
public OpenDatabaseControlVm() : this(
|
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource)
|
||||||
App.Services.GetRequiredService<IMediator>(),
|
|
||||||
App.Services.GetRequiredService<IResourceProxy>(),
|
|
||||||
App.Services.GetRequiredService<IMessenger>(),
|
|
||||||
App.Services.GetRequiredService<IDialogService>(),
|
|
||||||
App.Services.GetRequiredService<INotificationService>())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, IMessenger messenger, IDialogService dialog, INotificationService notification)
|
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_resource = resource;
|
_resource = resource;
|
||||||
_messenger = messenger;
|
|
||||||
_dialog = dialog;
|
|
||||||
_notification = notification;
|
|
||||||
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
|
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
|
||||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||||
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
|
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
|
||||||
@@ -135,30 +116,13 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
public async Task TryOpenDatabase(string databaseFilePath)
|
public async Task TryOpenDatabase(string databaseFilePath)
|
||||||
{
|
{
|
||||||
_messenger.Send(new DatabaseOpeningMessage {Token = databaseFilePath});
|
MessengerInstance.Send(new DatabaseOpeningMessage {Token = databaseFilePath});
|
||||||
|
|
||||||
var database = await _mediator.Send(new GetDatabaseQuery());
|
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||||
if (database.IsOpen)
|
if (database.IsDirty)
|
||||||
{
|
{
|
||||||
await _dialog.ShowMessage(_resource.GetResourceValue("MessageDialogDBOpenTitle"),
|
MessengerInstance.Register<DatabaseClosedMessage>(this, async message => await OpenDatabase(message.Parameter as string));
|
||||||
string.Format(_resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
|
MessengerInstance.Send(new DatabaseAlreadyOpenedMessage {Parameter = databaseFilePath});
|
||||||
_resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
|
|
||||||
_resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
|
|
||||||
async isOk =>
|
|
||||||
{
|
|
||||||
if (isOk)
|
|
||||||
{
|
|
||||||
await _mediator.Send(new SaveDatabaseCommand());
|
|
||||||
_notification.Show(database.Name, _resource.GetResourceValue("ToastSavedMessage"));
|
|
||||||
await _mediator.Send(new CloseDatabaseCommand());
|
|
||||||
await OpenDatabase(databaseFilePath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await _mediator.Send(new CloseDatabaseCommand());
|
|
||||||
await OpenDatabase(databaseFilePath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else await OpenDatabase(databaseFilePath);
|
else await OpenDatabase(databaseFilePath);
|
||||||
}
|
}
|
||||||
@@ -180,7 +144,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
});
|
});
|
||||||
var rootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
var rootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
||||||
|
|
||||||
_messenger.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
|
MessengerInstance.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
|
@@ -1,20 +1,17 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
using GalaSoft.MvvmLight.Command;
|
using GalaSoft.MvvmLight.Command;
|
||||||
using GalaSoft.MvvmLight.Messaging;
|
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Messages;
|
using Messages;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
|
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
public class SetCredentialsVm : ObservableObject
|
public class SetCredentialsVm : ViewModelBase
|
||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly ICredentialsProxy _credentials;
|
private readonly ICredentialsProxy _credentials;
|
||||||
private readonly IMessenger _messenger;
|
|
||||||
|
|
||||||
public bool HasPassword
|
public bool HasPassword
|
||||||
{
|
{
|
||||||
@@ -104,17 +101,10 @@ namespace ModernKeePass.ViewModels
|
|||||||
private string _keyFileText;
|
private string _keyFileText;
|
||||||
private string _openButtonLabel;
|
private string _openButtonLabel;
|
||||||
|
|
||||||
public SetCredentialsVm(): this(
|
public SetCredentialsVm(IMediator mediator, ICredentialsProxy credentials, IResourceProxy resource)
|
||||||
App.Services.GetRequiredService<IMediator>(),
|
|
||||||
App.Services.GetRequiredService<ICredentialsProxy>(),
|
|
||||||
App.Services.GetRequiredService<IMessenger>(),
|
|
||||||
App.Services.GetRequiredService<IResourceProxy>()) { }
|
|
||||||
|
|
||||||
public SetCredentialsVm(IMediator mediator, ICredentialsProxy credentials, IMessenger messenger, IResourceProxy resource)
|
|
||||||
{
|
{
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_credentials = credentials;
|
_credentials = credentials;
|
||||||
_messenger = messenger;
|
|
||||||
GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid);
|
GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid);
|
||||||
|
|
||||||
_keyFileText = resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
_keyFileText = resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||||
@@ -127,7 +117,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
private void GenerateCredentials()
|
private void GenerateCredentials()
|
||||||
{
|
{
|
||||||
_messenger.Send(new CredentialsSetMessage
|
MessengerInstance.Send(new CredentialsSetMessage
|
||||||
{
|
{
|
||||||
Password = HasPassword ? Password : null,
|
Password = HasPassword ? Password : null,
|
||||||
KeyFilePath = HasKeyFile ? KeyFilePath : null
|
KeyFilePath = HasKeyFile ? KeyFilePath : null
|
||||||
|
@@ -69,17 +69,17 @@ namespace ModernKeePass.ViewModels
|
|||||||
SimpleIoc.Default.Register<SaveVm>();
|
SimpleIoc.Default.Register<SaveVm>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainVm Main => ServiceLocator.Current.GetInstance<MainVm>();
|
public MainVm Main => ServiceLocator.Current.GetInstance<MainVm>(Guid.NewGuid().ToString());
|
||||||
public SettingsVm Settings => ServiceLocator.Current.GetInstance<SettingsVm>();
|
public SettingsVm Settings => ServiceLocator.Current.GetInstance<SettingsVm>(Guid.NewGuid().ToString());
|
||||||
public SettingsDatabaseVm SettingsDatabase => ServiceLocator.Current.GetInstance<SettingsDatabaseVm>();
|
public SettingsDatabaseVm SettingsDatabase => ServiceLocator.Current.GetInstance<SettingsDatabaseVm>(Guid.NewGuid().ToString());
|
||||||
public SettingsNewVm SettingsNew => ServiceLocator.Current.GetInstance<SettingsNewVm>();
|
public SettingsNewVm SettingsNew => ServiceLocator.Current.GetInstance<SettingsNewVm>(Guid.NewGuid().ToString());
|
||||||
public SettingsSaveVm SettingsSave => ServiceLocator.Current.GetInstance<SettingsSaveVm>();
|
public SettingsSaveVm SettingsSave => ServiceLocator.Current.GetInstance<SettingsSaveVm>(Guid.NewGuid().ToString());
|
||||||
public SettingsSecurityVm SettingsSecurity => ServiceLocator.Current.GetInstance<SettingsSecurityVm>();
|
public SettingsSecurityVm SettingsSecurity => ServiceLocator.Current.GetInstance<SettingsSecurityVm>(Guid.NewGuid().ToString());
|
||||||
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance<OpenDatabaseControlVm>(Guid.NewGuid().ToString());
|
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance<OpenDatabaseControlVm>(Guid.NewGuid().ToString());
|
||||||
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
|
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
|
||||||
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>();
|
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>();
|
||||||
public OpenVm Open => ServiceLocator.Current.GetInstance<OpenVm>();
|
public OpenVm Open => ServiceLocator.Current.GetInstance<OpenVm>();
|
||||||
public RecentVm Recent => ServiceLocator.Current.GetInstance<RecentVm>();
|
public RecentVm Recent => ServiceLocator.Current.GetInstance<RecentVm>(Guid.NewGuid().ToString());
|
||||||
public SaveVm Save => ServiceLocator.Current.GetInstance<SaveVm>();
|
public SaveVm Save => ServiceLocator.Current.GetInstance<SaveVm>();
|
||||||
|
|
||||||
public static void Cleanup()
|
public static void Cleanup()
|
||||||
|
@@ -15,8 +15,6 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Actions\ToastAction.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Actions\ToastAction.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Common\Constants.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Common\Constants.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Common\NavigationHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Common\NavigationHelper.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Common\ObservableDictionary.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Common\RelayCommand.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Common\SuspensionManager.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Common\SuspensionManager.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\ListViewWithDisable.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\ListViewWithDisable.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\TextBoxWithButton.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\TextBoxWithButton.cs" />
|
||||||
@@ -31,7 +29,6 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\PluralizationConverter.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Converters\PluralizationConverter.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ProgressBarLegalValuesConverter.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Converters\ProgressBarLegalValuesConverter.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\TextToWidthConverter.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Converters\TextToWidthConverter.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Events\PasswordEventArgs.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ColorExtensions.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ColorExtensions.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DispatcherTaskExtensions.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DispatcherTaskExtensions.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\CredentialsMessage.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Messages\CredentialsMessage.cs" />
|
||||||
@@ -57,5 +54,6 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\SaveVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\SaveVm.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\OpenDatabaseControlVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\OpenDatabaseControlVm.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\SetCredentialsVm.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\SetCredentialsVm.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelLocator.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Reference in New Issue
Block a user