mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40: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
|
||||
{
|
||||
// PW Database properties
|
||||
bool IsOpen { get; }
|
||||
string Name { get; }
|
||||
string RootGroupId { get; }
|
||||
@@ -16,6 +17,8 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
string KeyDerivationId { get; set; }
|
||||
string Compression { get; set; }
|
||||
bool IsRecycleBinEnabled { get; set; }
|
||||
|
||||
// Custom properties
|
||||
string FileAccessToken { get; set; }
|
||||
int Size { get; set; }
|
||||
bool IsDirty { get; set; }
|
||||
|
@@ -21,7 +21,11 @@ namespace ModernKeePass.Application.Database.Commands.CloseDatabase
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
_database.CloseDatabase();
|
||||
_file.ReleaseFile(_database.FileAccessToken);
|
||||
|
||||
// Cleanup
|
||||
_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)
|
||||
{
|
||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
||||
if (_database.IsDirty) throw new DatabaseOpenException();
|
||||
|
||||
var version = DatabaseVersion.V2;
|
||||
switch (message.Version)
|
||||
@@ -48,8 +48,6 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
Password = message.Password
|
||||
}, message.Name, version);
|
||||
_database.FileAccessToken = message.FilePath;
|
||||
var contents = await _database.SaveDatabase();
|
||||
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
||||
|
||||
if (message.CreateSampleData)
|
||||
{
|
||||
|
@@ -34,8 +34,7 @@ namespace ModernKeePass.Application.Database.Commands.SaveDatabase
|
||||
|
||||
// Test DB integrity before writing changes to file
|
||||
_database.CloseDatabase();
|
||||
var file = await _file.OpenBinaryFile(_database.FileAccessToken);
|
||||
await _database.ReOpen(file);
|
||||
await _database.ReOpen(contents);
|
||||
|
||||
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
||||
}
|
||||
|
@@ -25,18 +25,19 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
|
||||
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 hasKeyFile = !string.IsNullOrEmpty(message.KeyFilePath);
|
||||
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
|
||||
});
|
||||
if (hasKeyFile) _file.ReleaseFile(message.KeyFilePath);
|
||||
_database.Size = file.Length;
|
||||
_database.FileAccessToken = message.FilePath;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,11 +4,13 @@ namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class SaveException : Exception
|
||||
{
|
||||
public new Exception InnerException { get; }
|
||||
public new string Message { get; }
|
||||
public new string Source { get; }
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
compositeKey.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromByteArray(credentials.KeyFileContents)));
|
||||
|
@@ -21,7 +21,7 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
var file = await _mru.GetFileAsync(token,
|
||||
updateAccessTime ? AccessCacheOptions.None : AccessCacheOptions.SuppressAccessTimeUpdate).AsTask().ConfigureAwait(false);
|
||||
_fal.AddOrReplace(token, file);
|
||||
_fal.AddOrReplace(token, file, file.Name);
|
||||
return new FileInfo
|
||||
{
|
||||
Id = token,
|
||||
|
@@ -1,21 +1,26 @@
|
||||
<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>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ResourceDictionaries/TextBoxWithButtonStyle.xaml">
|
||||
<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>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ResourceDictionaries/TextBoxWithButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/HamburgerButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/ListViewLeftIndicatorStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/NoBorderButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/NoBorderToggleButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/Styles.xaml">
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:ModernKeePass.ViewModels" />
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/HamburgerButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/ListViewLeftIndicatorStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/NoBorderButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/NoBorderToggleButtonStyle.xaml">
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary Source="ResourceDictionaries/Styles.xaml">
|
||||
<!--<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="using:ModernKeePass.ViewModel" />-->
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application.Resources>
|
||||
</Application>
|
@@ -88,10 +88,9 @@ namespace ModernKeePass
|
||||
|
||||
if (realException is SaveException)
|
||||
{
|
||||
var innerException = realException.InnerException;
|
||||
unhandledExceptionEventArgs.Handled = true;
|
||||
_hockey.TrackException(innerException);
|
||||
await _dialog.ShowMessage(innerException?.Message,
|
||||
_hockey.TrackException(realException);
|
||||
await _dialog.ShowMessage(realException.Message,
|
||||
_resource.GetResourceValue("MessageDialogSaveErrorTitle"),
|
||||
_resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"),
|
||||
_resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"),
|
||||
@@ -112,7 +111,7 @@ namespace ModernKeePass
|
||||
var file = await savePicker.PickSaveFileAsync().AsTask();
|
||||
if (file != null)
|
||||
{
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
await _mediator.Send(new SaveDatabaseCommand {FilePath = token});
|
||||
}
|
||||
}
|
||||
@@ -252,7 +251,7 @@ namespace ModernKeePass
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Id = token,
|
||||
|
@@ -25,7 +25,6 @@ namespace ModernKeePass
|
||||
nav.Configure(Constants.Navigation.GroupPage, typeof(GroupDetailPage));
|
||||
return nav;
|
||||
});
|
||||
services.AddSingleton(provider => Messenger.Default);
|
||||
services.AddTransient(typeof(IDialogService), typeof(DialogService));
|
||||
|
||||
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.Media;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -26,14 +27,12 @@ using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Security.Commands.GeneratePassword;
|
||||
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Extensions;
|
||||
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class EntryDetailVm : ObservableObject, IVmEntity
|
||||
public class EntryDetailVm : ObservableObject
|
||||
{
|
||||
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
||||
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
|
||||
@@ -230,6 +229,7 @@ namespace ModernKeePass.ViewModels
|
||||
private readonly INavigationService _navigation;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly IDialogService _dialog;
|
||||
private readonly INotificationService _notification;
|
||||
private readonly GroupVm _parent;
|
||||
private EntryVm _selectedItem;
|
||||
private int _selectedIndex;
|
||||
@@ -244,14 +244,16 @@ namespace ModernKeePass.ViewModels
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
App.Services.GetRequiredService<INavigationService>(),
|
||||
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;
|
||||
_navigation = navigation;
|
||||
_resource = resource;
|
||||
_dialog = dialog;
|
||||
_notification = notification;
|
||||
SelectedItem = _mediator.Send(new GetEntryQuery { Id = entryId }).GetAwaiter().GetResult();
|
||||
_parent = _mediator.Send(new GetGroupQuery { Id = SelectedItem.ParentGroupId }).GetAwaiter().GetResult();
|
||||
History = new ObservableCollection<EntryVm> { SelectedItem };
|
||||
@@ -273,31 +275,22 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
if (IsCurrentEntry)
|
||||
{
|
||||
var isRecycleOnDelete = IsRecycleOnDelete;
|
||||
|
||||
var message = isRecycleOnDelete
|
||||
? _resource.GetResourceValue("EntryRecyclingConfirmation")
|
||||
: _resource.GetResourceValue("EntryDeletingConfirmation");
|
||||
await _dialog.ShowMessage(message,
|
||||
_resource.GetResourceValue("EntityDeleteTitle"),
|
||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
||||
async isOk =>
|
||||
{
|
||||
if (isOk)
|
||||
if (IsRecycleOnDelete)
|
||||
{
|
||||
await Delete();
|
||||
_notification.Show(_resource.GetResourceValue("EntryRecyclingConfirmation"), _resource.GetResourceValue("EntryRecycled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
await _dialog.ShowMessage(_resource.GetResourceValue("EntryDeletingConfirmation"),
|
||||
_resource.GetResourceValue("EntityDeleteTitle"),
|
||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
||||
async isOk =>
|
||||
{
|
||||
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();
|
||||
}
|
||||
});
|
||||
if (isOk) await Delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -305,14 +298,11 @@ namespace ModernKeePass.ViewModels
|
||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||
_resource.GetResourceValue("EntityDeleteCancelButton"), async isOk =>
|
||||
{
|
||||
if (isOk)
|
||||
{
|
||||
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
|
||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
History.RemoveAt(SelectedIndex);
|
||||
SelectedIndex = 0;
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
if (!isOk) return;
|
||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
History.RemoveAt(SelectedIndex);
|
||||
SelectedIndex = 0;
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -368,5 +358,16 @@ namespace ModernKeePass.ViewModels
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
_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 Windows.UI.Xaml.Controls;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -29,13 +30,11 @@ using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Group.Queries.SearchEntries;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Models;
|
||||
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupDetailVm : ObservableObject, IVmEntity
|
||||
public class GroupDetailVm : ObservableObject
|
||||
{
|
||||
public ObservableCollection<EntryVm> Entries { get; }
|
||||
|
||||
@@ -102,6 +101,7 @@ namespace ModernKeePass.ViewModels
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly INavigationService _navigation;
|
||||
private readonly IDialogService _dialog;
|
||||
private readonly INotificationService _notification;
|
||||
private readonly GroupVm _group;
|
||||
private readonly GroupVm _parent;
|
||||
private bool _isEditMode;
|
||||
@@ -113,15 +113,17 @@ namespace ModernKeePass.ViewModels
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
App.Services.GetRequiredService<IResourceProxy>(),
|
||||
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;
|
||||
_resource = resource;
|
||||
_navigation = navigation;
|
||||
_dialog = dialog;
|
||||
_notification = notification;
|
||||
_group = _mediator.Send(new GetGroupQuery { Id = groupId }).GetAwaiter().GetResult();
|
||||
if (!string.IsNullOrEmpty(_group.ParentGroupId))
|
||||
{
|
||||
@@ -145,29 +147,21 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
private async Task AskForDelete()
|
||||
{
|
||||
var message = IsRecycleOnDelete
|
||||
? _resource.GetResourceValue("GroupRecyclingConfirmation")
|
||||
: _resource.GetResourceValue("GroupDeletingConfirmation");
|
||||
|
||||
await _dialog.ShowMessage(message, _resource.GetResourceValue("EntityDeleteTitle"),
|
||||
if (IsRecycleOnDelete)
|
||||
{
|
||||
await Delete();
|
||||
_notification.Show(_resource.GetResourceValue("GroupRecyclingConfirmation"), _resource.GetResourceValue("GroupRecycled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
await _dialog.ShowMessage(_resource.GetResourceValue("GroupDeletingConfirmation"), _resource.GetResourceValue("EntityDeleteTitle"),
|
||||
_resource.GetResourceValue("EntityDeleteActionButton"),
|
||||
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
||||
async isOk =>
|
||||
{
|
||||
if (isOk)
|
||||
{
|
||||
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();
|
||||
}
|
||||
if (isOk) await Delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -244,5 +238,16 @@ namespace ModernKeePass.ViewModels
|
||||
RaisePropertyChanged(nameof(Groups));
|
||||
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 GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
@@ -12,11 +13,23 @@ using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.ViewModels.ListItems;
|
||||
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
|
||||
{
|
||||
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 ISelectableModel _selectedItem;
|
||||
|
||||
@@ -55,19 +68,45 @@ namespace ModernKeePass.ViewModels
|
||||
destinationFrame,
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
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)
|
||||
{ }
|
||||
|
||||
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>
|
||||
{
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemOpen"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemOpen"),
|
||||
PageType = typeof(OpenDatabasePage),
|
||||
Destination = destinationFrame,
|
||||
Parameter = databaseFile,
|
||||
@@ -76,14 +115,14 @@ namespace ModernKeePass.ViewModels
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemNew"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemNew"),
|
||||
PageType = typeof(NewDatabasePage),
|
||||
Destination = destinationFrame,
|
||||
SymbolIcon = Symbol.Add
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemSave"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemSave"),
|
||||
PageType = typeof(SaveDatabasePage),
|
||||
Destination = destinationFrame,
|
||||
Parameter = referenceFrame,
|
||||
@@ -93,31 +132,31 @@ namespace ModernKeePass.ViewModels
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemRecent"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemRecent"),
|
||||
PageType = typeof(RecentDatabasesPage),
|
||||
Destination = destinationFrame,
|
||||
Parameter = referenceFrame,
|
||||
SymbolIcon = Symbol.Copy,
|
||||
IsSelected = !database.IsOpen && recent.EntryCount > 0,
|
||||
IsEnabled = recent.EntryCount > 0
|
||||
IsSelected = !database.IsOpen && _recent.EntryCount > 0,
|
||||
IsEnabled = _recent.EntryCount > 0
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemSettings"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemSettings"),
|
||||
PageType = typeof(SettingsPage),
|
||||
Destination = referenceFrame,
|
||||
SymbolIcon = Symbol.Setting
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemAbout"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemAbout"),
|
||||
PageType = typeof(AboutPage),
|
||||
Destination = destinationFrame,
|
||||
SymbolIcon = Symbol.Help
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemDonate"),
|
||||
Title = _resource.GetResourceValue("MainMenuItemDonate"),
|
||||
PageType = typeof(DonatePage),
|
||||
Destination = destinationFrame,
|
||||
SymbolIcon = Symbol.Shop
|
||||
@@ -137,8 +176,41 @@ namespace ModernKeePass.ViewModels
|
||||
Group = "Databases",
|
||||
SymbolIcon = Symbol.ProtectedDocument
|
||||
});
|
||||
|
||||
|
||||
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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -43,9 +43,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<IResourceProxy>()) { }
|
||||
|
||||
|
||||
public SettingsVm(IMediator mediator, IResourceProxy resource)
|
||||
{
|
||||
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.Data;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
|
@@ -22,15 +22,6 @@ namespace ModernKeePass.Views
|
||||
|
||||
#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)
|
||||
{
|
||||
var args = e.Parameter as NavigationItem;
|
||||
|
@@ -37,16 +37,7 @@ namespace ModernKeePass.Views
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
var navigationItem = e.Parameter as NavigationItem;
|
||||
|
@@ -18,10 +18,16 @@ namespace ModernKeePass.Views
|
||||
public MainPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
Unloaded += MainPage_Unloaded;
|
||||
ListView = MenuListView;
|
||||
ListViewSource = MenuItemsSource;
|
||||
}
|
||||
|
||||
private void MainPage_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
Model.Cleanup();
|
||||
}
|
||||
|
||||
private new void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
base.ListView_SelectionChanged(sender, e);
|
||||
|
@@ -5,15 +5,14 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=New}">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<viewModels:NewVm x:Key="ViewModel"/>
|
||||
</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}" />
|
||||
<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}}">
|
||||
|
@@ -20,7 +20,7 @@ namespace ModernKeePass.Views
|
||||
public sealed partial class NewDatabasePage
|
||||
{
|
||||
private readonly IResourceProxy _resource;
|
||||
private NewVm Model => (NewVm)Resources["ViewModel"];
|
||||
private NewVm Model => (NewVm)DataContext;
|
||||
|
||||
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
|
||||
public NewDatabasePage(IResourceProxy resource)
|
||||
@@ -41,7 +41,7 @@ namespace ModernKeePass.Views
|
||||
var file = await savePicker.PickSaveFileAsync().AsTask();
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Id = token,
|
||||
|
@@ -3,17 +3,16 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
x:Class="ModernKeePass.Views.OpenDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Open}">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<viewModels:OpenVm x:Key="ViewModel"/>
|
||||
</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}" />
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" />
|
||||
<!--<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.UI.Xaml;
|
||||
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.Models;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
@@ -21,24 +15,11 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class OpenDatabasePage
|
||||
{
|
||||
private readonly INavigationService _navigation;
|
||||
private OpenVm Model => (OpenVm)Resources["ViewModel"];
|
||||
|
||||
public OpenDatabasePage(): this(
|
||||
App.Services.GetRequiredService<INavigationService>(),
|
||||
App.Services.GetRequiredService<IMessenger>()) { }
|
||||
|
||||
public OpenDatabasePage(INavigationService navigation, IMessenger messenger)
|
||||
private OpenVm Model => (OpenVm)DataContext;
|
||||
|
||||
public OpenDatabasePage()
|
||||
{
|
||||
_navigation = navigation;
|
||||
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)
|
||||
@@ -64,8 +45,7 @@ namespace ModernKeePass.Views
|
||||
var file = await picker.PickSingleFileAsync().AsTask();
|
||||
if (file == null) return;
|
||||
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = file.Path,
|
||||
|
@@ -3,16 +3,15 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
x:Class="ModernKeePass.Views.RecentDatabasesPage"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Recent}">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<viewModels:RecentVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40" />
|
||||
<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
|
||||
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
namespace ModernKeePass.Views
|
||||
@@ -15,29 +9,11 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class RecentDatabasesPage
|
||||
{
|
||||
private RecentVm Model => (RecentVm)Resources["ViewModel"];
|
||||
|
||||
private readonly INavigationService _navigation;
|
||||
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();
|
||||
|
||||
messenger.Register<DatabaseOpeningMessage>(this, action => Model.UpdateAccessTime(action.Token));
|
||||
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
|
||||
}
|
||||
private RecentVm Model => (RecentVm)DataContext;
|
||||
|
||||
private void NavigateToPage(DatabaseOpenedMessage message)
|
||||
public RecentDatabasesPage()
|
||||
{
|
||||
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,12 +3,9 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
x:Class="ModernKeePass.Views.SaveDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
<Page.DataContext>
|
||||
<viewModels:SaveVm/>
|
||||
</Page.DataContext>
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Save}">
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="using:ModernKeePass.Controls"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:basePages="using:ModernKeePass.Views.BasePages"
|
||||
x:Name="PageRoot"
|
||||
x:Class="ModernKeePass.Views.SettingsPage"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Settings}">
|
||||
<Page.Resources>
|
||||
<CollectionViewSource x:Name="MenuItemsSource" Source="{Binding MenuItems}" IsSourceGrouped="True" />
|
||||
</Page.Resources>
|
||||
<Page.DataContext>
|
||||
<viewModels:SettingsVm />
|
||||
</Page.DataContext>
|
||||
|
||||
<Page.Background>
|
||||
<StaticResource ResourceKey="ApplicationPageBackgroundThemeBrush"/>
|
||||
|
@@ -5,12 +5,11 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
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>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
|
||||
<listItems:SettingsDatabaseVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
|
@@ -4,13 +4,10 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
||||
mc:Ignorable="d">
|
||||
<Page.Resources>
|
||||
<listItems:SettingsNewVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsNew}">
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<StackPanel.Resources>
|
||||
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding FileFormats}" />
|
||||
</StackPanel.Resources>
|
||||
|
@@ -4,13 +4,10 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
||||
mc:Ignorable="d">
|
||||
<Page.Resources>
|
||||
<listItems:SettingsSaveVm x:Name="ViewModel"/>
|
||||
</Page.Resources>
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsSave}">
|
||||
|
||||
<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="SettingsSaveDatabaseSuspendDesc" TextWrapping="WrapWholeWords" Margin="5,0,0,10"/>
|
||||
<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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
|
||||
mc:Ignorable="d">
|
||||
<Page.Resources>
|
||||
<listItems:SettingsSecurityVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=SettingsSecurity}">
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<TextBlock x:Uid="SettingsSecurityTitle" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,0" />
|
||||
<TextBlock TextWrapping="WrapWholeWords" Margin="5,0,0,0">
|
||||
<Run x:Uid="SettingsSecurityDesc1" />
|
||||
|
@@ -7,14 +7,12 @@
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
mc:Ignorable="d" >
|
||||
<UserControl.Resources>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
<viewModels:OpenDatabaseControlVm x:Key="ViewModel"/>
|
||||
</UserControl.Resources>
|
||||
<Grid DataContext="{StaticResource ViewModel}">
|
||||
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=OpenDatabaseControl}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="*" />
|
||||
|
@@ -12,7 +12,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
{
|
||||
public sealed partial class OpenDatabaseUserControl
|
||||
{
|
||||
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Resources["ViewModel"];
|
||||
private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Grid.DataContext;
|
||||
|
||||
public string DatabaseFilePath
|
||||
{
|
||||
@@ -52,7 +52,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
Model.KeyFilePath = token;
|
||||
Model.KeyFileText = file.DisplayName;
|
||||
}
|
||||
|
@@ -7,16 +7,14 @@
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
mc:Ignorable="d" >
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter"/>
|
||||
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
|
||||
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
|
||||
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
|
||||
<viewModels:SetCredentialsVm x:Key="ViewModel"/>
|
||||
</UserControl.Resources>
|
||||
<Grid DataContext="{StaticResource ViewModel}">
|
||||
<Grid x:Name="Grid" DataContext="{Binding Source={StaticResource Locator}, Path=SetCredentials}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50" />
|
||||
<ColumnDefinition Width="*" />
|
||||
|
@@ -11,7 +11,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
{
|
||||
public sealed partial class SetCredentialsUserControl
|
||||
{
|
||||
private SetCredentialsVm Model => (SetCredentialsVm)Resources["ViewModel"];
|
||||
private SetCredentialsVm Model => (SetCredentialsVm)Grid.DataContext;
|
||||
|
||||
public string ButtonLabel
|
||||
{
|
||||
@@ -44,7 +44,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
Model.KeyFilePath = token;
|
||||
Model.KeyFileText = file.DisplayName;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
var file = await savePicker.PickSaveFileAsync();
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
Model.KeyFilePath = token;
|
||||
Model.KeyFileText = file.DisplayName;
|
||||
await Model.GenerateKeyFile();
|
||||
|
@@ -94,8 +94,6 @@
|
||||
</Compile>
|
||||
<Compile Include="DependencyInjection.cs" />
|
||||
<Compile Include="Models\NavigationItem.cs" />
|
||||
<Compile Include="ViewModel\MainViewModel.cs" />
|
||||
<Compile Include="ViewModel\ViewModelLocator.cs" />
|
||||
<Compile Include="Views\MainPageFrames\DonatePage.xaml.cs">
|
||||
<DependentUpon>DonatePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -124,7 +122,6 @@
|
||||
<Compile Include="Views\UserControls\ColorPickerUserControl.xaml.cs">
|
||||
<DependentUpon>ColorPickerUserControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Interfaces\IVmEntity.cs" />
|
||||
<Compile Include="Views\MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -140,7 +137,6 @@
|
||||
<Compile Include="Views\MainPageFrames\WelcomePage.xaml.cs">
|
||||
<DependentUpon>WelcomePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewModels\CompositeKeyVm.cs" />
|
||||
<Compile Include="Views\EntryDetailPage.xaml.cs">
|
||||
<DependentUpon>EntryDetailPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@@ -5,6 +5,7 @@ using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
|
||||
namespace ModernKeePass.Common
|
||||
{
|
||||
@@ -77,8 +78,8 @@ namespace ModernKeePass.Common
|
||||
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
|
||||
#else
|
||||
// Keyboard and mouse navigation only apply when occupying the entire window
|
||||
if (this.Page.ActualHeight == Window.Current.Bounds.Height &&
|
||||
this.Page.ActualWidth == Window.Current.Bounds.Width)
|
||||
if (Page.ActualHeight == Window.Current.Bounds.Height &&
|
||||
Page.ActualWidth == Window.Current.Bounds.Width)
|
||||
{
|
||||
// Listen to the window directly so focus isn't required
|
||||
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 DatabaseVm OpenedDatabase { get; set; }
|
||||
public object Parameter { get; set; }
|
||||
}
|
||||
}
|
@@ -2,6 +2,6 @@
|
||||
{
|
||||
public class DatabaseClosedMessage
|
||||
{
|
||||
|
||||
public object Parameter { get; set; }
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
@@ -76,9 +75,7 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
if (!IsNewRecycleBin) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id}).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsDatabaseVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
|
||||
public SettingsDatabaseVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
@@ -9,10 +8,7 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
public class SettingsNewVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsNewVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
||||
{ }
|
||||
|
||||
|
||||
public SettingsNewVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
@@ -7,10 +6,7 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
public class SettingsSaveVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsSaveVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
||||
{ }
|
||||
|
||||
|
||||
public SettingsSaveVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
@@ -1,34 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using GalaSoft.MvvmLight;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
|
||||
namespace ModernKeePass.ViewModels.ListItems
|
||||
{
|
||||
public class SettingsSecurityVm
|
||||
public class SettingsSecurityVm: ViewModelBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly INotificationService _notification;
|
||||
|
||||
public SettingsSecurityVm(): this(
|
||||
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)
|
||||
|
||||
public SettingsSecurityVm(IMediator mediator, IResourceProxy resource, INotificationService notification)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_resource = resource;
|
||||
_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)
|
||||
|
@@ -1,10 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Commands.CreateDatabase;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
@@ -37,23 +35,28 @@ namespace ModernKeePass.ViewModels
|
||||
RaisePropertyChanged(nameof(ImportFormatHelp));
|
||||
}
|
||||
}
|
||||
|
||||
public NewVm(): this(
|
||||
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)
|
||||
|
||||
public NewVm(IMediator mediator, IRecentProxy recent, ISettingsProxy settings, INavigationService navigation) : base(recent)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_settings = settings;
|
||||
_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
|
||||
{
|
||||
|
@@ -1,12 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class OpenVm: ObservableObject
|
||||
public class OpenVm: ViewModelBase
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private string _name;
|
||||
@@ -31,9 +30,7 @@ namespace ModernKeePass.ViewModels
|
||||
get { return _path; }
|
||||
private set { Set(() => Path, ref _path, value); }
|
||||
}
|
||||
|
||||
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
|
||||
|
||||
|
||||
public OpenVm(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
|
@@ -1,16 +1,17 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Messages;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.ViewModels.ListItems;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class RecentVm : ObservableObject, IHasSelectableObject
|
||||
public class RecentVm : ViewModelBase, IHasSelectableObject
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private ISelectableModel _selectedItem;
|
||||
@@ -41,9 +42,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
|
||||
public ICommand ClearAllCommand { get; }
|
||||
|
||||
public RecentVm() : this (App.Services.GetRequiredService<IRecentProxy>()) { }
|
||||
|
||||
|
||||
public RecentVm(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
@@ -53,11 +52,13 @@ namespace ModernKeePass.ViewModels
|
||||
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
||||
if (RecentItems.Count > 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()
|
||||
|
@@ -3,7 +3,6 @@ using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
||||
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
@@ -21,9 +20,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
private readonly INavigationService _navigation;
|
||||
|
||||
public SaveVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<INavigationService>()) { }
|
||||
|
||||
|
||||
public SaveVm(IMediator mediator, INavigationService navigation)
|
||||
{
|
||||
_mediator = mediator;
|
||||
@@ -41,7 +38,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
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 });
|
||||
_navigation.NavigateTo(Constants.Navigation.MainPage);
|
||||
}
|
||||
|
@@ -3,20 +3,15 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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.OpenDatabase;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class OpenDatabaseControlVm : ObservableObject
|
||||
public class OpenDatabaseControlVm : ViewModelBase
|
||||
{
|
||||
public enum StatusTypes
|
||||
{
|
||||
@@ -100,9 +95,6 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly IMessenger _messenger;
|
||||
private readonly IDialogService _dialog;
|
||||
private readonly INotificationService _notification;
|
||||
private bool _hasPassword;
|
||||
private bool _hasKeyFile;
|
||||
private bool _isOpening;
|
||||
@@ -112,22 +104,11 @@ namespace ModernKeePass.ViewModels
|
||||
private string _keyFilePath;
|
||||
private string _keyFileText;
|
||||
private string _openButtonLabel;
|
||||
|
||||
public OpenDatabaseControlVm() : this(
|
||||
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)
|
||||
|
||||
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_resource = resource;
|
||||
_messenger = messenger;
|
||||
_dialog = dialog;
|
||||
_notification = notification;
|
||||
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
|
||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
|
||||
@@ -135,30 +116,13 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
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());
|
||||
if (database.IsOpen)
|
||||
if (database.IsDirty)
|
||||
{
|
||||
await _dialog.ShowMessage(_resource.GetResourceValue("MessageDialogDBOpenTitle"),
|
||||
string.Format(_resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
|
||||
_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);
|
||||
}
|
||||
});
|
||||
MessengerInstance.Register<DatabaseClosedMessage>(this, async message => await OpenDatabase(message.Parameter as string));
|
||||
MessengerInstance.Send(new DatabaseAlreadyOpenedMessage {Parameter = databaseFilePath});
|
||||
}
|
||||
else await OpenDatabase(databaseFilePath);
|
||||
}
|
||||
@@ -180,7 +144,7 @@ namespace ModernKeePass.ViewModels
|
||||
});
|
||||
var rootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
||||
|
||||
_messenger.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
|
||||
MessengerInstance.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
|
@@ -1,20 +1,17 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SetCredentialsVm : ObservableObject
|
||||
public class SetCredentialsVm : ViewModelBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ICredentialsProxy _credentials;
|
||||
private readonly IMessenger _messenger;
|
||||
|
||||
public bool HasPassword
|
||||
{
|
||||
@@ -103,18 +100,11 @@ namespace ModernKeePass.ViewModels
|
||||
private string _keyFilePath;
|
||||
private string _keyFileText;
|
||||
private string _openButtonLabel;
|
||||
|
||||
public SetCredentialsVm(): this(
|
||||
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)
|
||||
|
||||
public SetCredentialsVm(IMediator mediator, ICredentialsProxy credentials, IResourceProxy resource)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_credentials = credentials;
|
||||
_messenger = messenger;
|
||||
GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid);
|
||||
|
||||
_keyFileText = resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
@@ -127,7 +117,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
private void GenerateCredentials()
|
||||
{
|
||||
_messenger.Send(new CredentialsSetMessage
|
||||
MessengerInstance.Send(new CredentialsSetMessage
|
||||
{
|
||||
Password = HasPassword ? Password : null,
|
||||
KeyFilePath = HasKeyFile ? KeyFilePath : null
|
||||
|
@@ -69,17 +69,17 @@ namespace ModernKeePass.ViewModels
|
||||
SimpleIoc.Default.Register<SaveVm>();
|
||||
}
|
||||
|
||||
public MainVm Main => ServiceLocator.Current.GetInstance<MainVm>();
|
||||
public SettingsVm Settings => ServiceLocator.Current.GetInstance<SettingsVm>();
|
||||
public SettingsDatabaseVm SettingsDatabase => ServiceLocator.Current.GetInstance<SettingsDatabaseVm>();
|
||||
public SettingsNewVm SettingsNew => ServiceLocator.Current.GetInstance<SettingsNewVm>();
|
||||
public SettingsSaveVm SettingsSave => ServiceLocator.Current.GetInstance<SettingsSaveVm>();
|
||||
public SettingsSecurityVm SettingsSecurity => ServiceLocator.Current.GetInstance<SettingsSecurityVm>();
|
||||
public MainVm Main => ServiceLocator.Current.GetInstance<MainVm>(Guid.NewGuid().ToString());
|
||||
public SettingsVm Settings => ServiceLocator.Current.GetInstance<SettingsVm>(Guid.NewGuid().ToString());
|
||||
public SettingsDatabaseVm SettingsDatabase => ServiceLocator.Current.GetInstance<SettingsDatabaseVm>(Guid.NewGuid().ToString());
|
||||
public SettingsNewVm SettingsNew => ServiceLocator.Current.GetInstance<SettingsNewVm>(Guid.NewGuid().ToString());
|
||||
public SettingsSaveVm SettingsSave => ServiceLocator.Current.GetInstance<SettingsSaveVm>(Guid.NewGuid().ToString());
|
||||
public SettingsSecurityVm SettingsSecurity => ServiceLocator.Current.GetInstance<SettingsSecurityVm>(Guid.NewGuid().ToString());
|
||||
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance<OpenDatabaseControlVm>(Guid.NewGuid().ToString());
|
||||
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance<SetCredentialsVm>(Guid.NewGuid().ToString());
|
||||
public NewVm New => ServiceLocator.Current.GetInstance<NewVm>();
|
||||
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 static void Cleanup()
|
||||
|
@@ -15,8 +15,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Actions\ToastAction.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Common\Constants.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)Controls\ListViewWithDisable.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\TextBoxWithButton.cs" />
|
||||
@@ -31,7 +29,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\PluralizationConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ProgressBarLegalValuesConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\TextToWidthConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Events\PasswordEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ColorExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DispatcherTaskExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\CredentialsMessage.cs" />
|
||||
@@ -57,5 +54,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\SaveVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\OpenDatabaseControlVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\SetCredentialsVm.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelLocator.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user