mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP Split composite key user control
Some refactoring
This commit is contained in:
@@ -31,7 +31,7 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
SetProperty(ref _hasPassword, value);
|
||||
OnPropertyChanged("IsValid");
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,21 +41,11 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
SetProperty(ref _hasKeyFile, value);
|
||||
OnPropertyChanged("IsValid");
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasUserAccount
|
||||
{
|
||||
get { return _hasUserAccount; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _hasUserAccount, value);
|
||||
OnPropertyChanged("IsValid");
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null || HasUserAccount);
|
||||
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null);
|
||||
|
||||
public string Status
|
||||
{
|
||||
@@ -103,7 +93,6 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
private bool _hasPassword;
|
||||
private bool _hasKeyFile;
|
||||
private bool _hasUserAccount;
|
||||
private bool _isOpening;
|
||||
private string _password = string.Empty;
|
||||
private string _status;
|
||||
@@ -160,7 +149,6 @@ namespace ModernKeePass.ViewModels
|
||||
var errorMessage = new StringBuilder($"{_resource.GetResourceValue("CompositeKeyErrorOpen")}\n");
|
||||
if (HasPassword) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserPassword"));
|
||||
if (HasKeyFile) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserKeyFile"));
|
||||
if (HasUserAccount) errorMessage.AppendLine(_resource.GetResourceValue("CompositeKeyErrorUserAccount"));
|
||||
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -171,7 +159,7 @@ namespace ModernKeePass.ViewModels
|
||||
finally
|
||||
{
|
||||
_isOpening = false;
|
||||
OnPropertyChanged("IsValid");
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using MediatR;
|
||||
@@ -120,10 +119,10 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public string Url
|
||||
{
|
||||
get { return SelectedItem.Url?.ToString(); }
|
||||
get { return SelectedItem.Url; }
|
||||
set
|
||||
{
|
||||
SelectedItem.Url = new Uri(value);
|
||||
SelectedItem.Url = value;
|
||||
SetFieldValue(nameof(Url), value).Wait();
|
||||
}
|
||||
}
|
||||
@@ -216,10 +215,10 @@ namespace ModernKeePass.ViewModels
|
||||
set { SetProperty(ref _isRevealPassword, value); }
|
||||
}
|
||||
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand GeneratePasswordCommand { get; }
|
||||
public ICommand MoveCommand { get; }
|
||||
public ICommand RestoreCommand { get; }
|
||||
public RelayCommand SaveCommand { get; }
|
||||
public RelayCommand GeneratePasswordCommand { get; }
|
||||
public RelayCommand MoveCommand { get; }
|
||||
public RelayCommand RestoreCommand { get; }
|
||||
|
||||
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
|
||||
@@ -286,7 +285,7 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task SetFieldValue(string fieldName, object value)
|
||||
{
|
||||
await _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = fieldName, FieldValue = value });
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
@@ -300,7 +299,7 @@ namespace ModernKeePass.ViewModels
|
||||
await _mediator.Send(new RestoreHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex });
|
||||
History.Insert(0, SelectedItem);
|
||||
SelectedIndex = 0;
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
public async Task DeleteHistory()
|
||||
@@ -308,14 +307,14 @@ namespace ModernKeePass.ViewModels
|
||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex });
|
||||
History.RemoveAt(SelectedIndex);
|
||||
SelectedIndex = 0;
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async Task SaveChanges()
|
||||
{
|
||||
await AddHistory();
|
||||
await _mediator.Send(new SaveDatabaseCommand());
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
_isDirty = false;
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -53,7 +52,7 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
_mediator.Send(new UpdateGroupCommand {Group = _group, Title = value, Icon = _group.Icon}).Wait();
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
_mediator.Send(new UpdateGroupCommand { Group = _group, Title = _group.Title, Icon = (Icon)Enum.Parse(typeof(Icon), value.ToString()) }).Wait();
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +72,8 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
SetProperty(ref _isEditMode, value);
|
||||
((RelayCommand)SortEntriesCommand).RaiseCanExecuteChanged();
|
||||
((RelayCommand)SortGroupsCommand).RaiseCanExecuteChanged();
|
||||
SortEntriesCommand.RaiseCanExecuteChanged();
|
||||
SortGroupsCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,10 +88,10 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public IEnumerable<GroupVm> BreadCrumb { get; }
|
||||
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand SortEntriesCommand { get; }
|
||||
public ICommand SortGroupsCommand { get; }
|
||||
public ICommand MoveCommand { get; }
|
||||
public RelayCommand SaveCommand { get; }
|
||||
public RelayCommand SortEntriesCommand { get; }
|
||||
public RelayCommand SortGroupsCommand { get; }
|
||||
public RelayCommand MoveCommand { get; }
|
||||
|
||||
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
|
||||
@@ -156,7 +155,7 @@ namespace ModernKeePass.ViewModels
|
||||
private async Task SaveChanges()
|
||||
{
|
||||
await _mediator.Send(new SaveDatabaseCommand());
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async void Entries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
@@ -179,21 +178,21 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
break;
|
||||
}
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async Task SortEntriesAsync()
|
||||
{
|
||||
await _mediator.Send(new SortEntriesCommand {Group = _group});
|
||||
OnPropertyChanged(nameof(Entries));
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async Task SortGroupsAsync()
|
||||
{
|
||||
await _mediator.Send(new SortGroupsCommand {Group = _group});
|
||||
OnPropertyChanged(nameof(Groups));
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class ListMenuItemVm : NotifyPropertyChangedBase, IIsEnabled, ISelectableModel
|
||||
{
|
||||
private bool _isSelected;
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Group { get; set; } = "_";
|
||||
public Type PageType { get; set; }
|
||||
public Symbol SymbolIcon { get; set; }
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return _isSelected; }
|
||||
set { SetProperty(ref _isSelected, value); }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Title;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class MainMenuItemVm: ListMenuItemVm
|
||||
{
|
||||
public object Parameter { get; set; }
|
||||
public Frame Destination { get; set; }
|
||||
}
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class RecentItemVm: NotifyPropertyChangedBase, ISelectableModel
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private bool _isSelected;
|
||||
private string _name;
|
||||
private string _token;
|
||||
private string _path;
|
||||
|
||||
public string Token
|
||||
{
|
||||
get { return _token; }
|
||||
set { SetProperty(ref _token, value); }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { SetProperty(ref _name, value); }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return _path; }
|
||||
set { SetProperty(ref _path, value); }
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return _isSelected; }
|
||||
set { SetProperty(ref _isSelected, value); }
|
||||
}
|
||||
|
||||
public RecentItemVm(FileInfo file): this(App.Services.GetRequiredService<IRecentProxy>(), file) {}
|
||||
public RecentItemVm(IRecentProxy recent, FileInfo file)
|
||||
{
|
||||
_recent = recent;
|
||||
Token = file.Id;
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
}
|
||||
|
||||
// Called from XAML
|
||||
public void UpdateAccessTime()
|
||||
{
|
||||
_recent.Get(Token, true).Wait();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetCipher;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetCompression;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetKeyDerivation;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetRecycleBin;
|
||||
using ModernKeePass.Application.Parameters.Models;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetCiphers;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetCompressions;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
// TODO: implement Kdf settings
|
||||
public class SettingsDatabaseVm: NotifyPropertyChangedBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
|
||||
public bool HasRecycleBin
|
||||
{
|
||||
get { return _database.IsRecycleBinEnabled; }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new SetHasRecycleBinCommand {HasRecycleBin = value}).Wait();
|
||||
OnPropertyChanged(nameof(HasRecycleBin));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNewRecycleBin
|
||||
{
|
||||
get { return string.IsNullOrEmpty(_database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = null }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<IEntityVm> Groups { get; }
|
||||
public ObservableCollection<CipherVm> Ciphers { get; }
|
||||
public IEnumerable<string> Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
|
||||
public ObservableCollection<KeyDerivationVm> KeyDerivations { get; }
|
||||
|
||||
public CipherVm SelectedCipher
|
||||
{
|
||||
get { return Ciphers.FirstOrDefault(c => c.Id == _database.CipherId); }
|
||||
set { _mediator.Send(new SetCipherCommand {CipherId = value.Id}).Wait(); }
|
||||
}
|
||||
|
||||
public string SelectedCompression
|
||||
{
|
||||
get { return Compressions.FirstOrDefault(c => c == _database.Compression); }
|
||||
set { _mediator.Send(new SetCompressionCommand {Compression = value}).Wait(); }
|
||||
}
|
||||
|
||||
public KeyDerivationVm SelectedKeyDerivation
|
||||
{
|
||||
get { return KeyDerivations.FirstOrDefault(c => c.Id == _database.KeyDerivationId); }
|
||||
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).Wait(); }
|
||||
}
|
||||
|
||||
public IEntityVm SelectedRecycleBin
|
||||
{
|
||||
get { return Groups.FirstOrDefault(g => g.Id == _database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (!IsNewRecycleBin) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id}).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsDatabaseVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
public SettingsDatabaseVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
|
||||
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
|
||||
var ciphers = _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
|
||||
Ciphers = new ObservableCollection<CipherVm>(ciphers);
|
||||
var keyDerivations = _mediator.Send(new GetKeyDerivationsQuery()).GetAwaiter().GetResult();
|
||||
KeyDerivations = new ObservableCollection<KeyDerivationVm>(keyDerivations);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SettingsNewVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsNewVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
||||
{ }
|
||||
|
||||
public SettingsNewVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public bool IsCreateSample
|
||||
{
|
||||
get { return _settings.GetSetting<bool>("Sample"); }
|
||||
set { _settings.PutSetting("Sample", value); }
|
||||
}
|
||||
|
||||
public IEnumerable<string> FileFormats => new []{"2", "4"};
|
||||
|
||||
public string FileFormatVersion
|
||||
{
|
||||
get { return _settings.GetSetting<string>("DefaultFileFormat"); }
|
||||
set { _settings.PutSetting("DefaultFileFormat", value); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SettingsSaveVm
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsSaveVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
||||
{ }
|
||||
|
||||
public SettingsSaveVm(ISettingsProxy settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public bool IsSaveSuspend
|
||||
{
|
||||
get { return _settings.GetSetting(Constants.Settings.SaveSuspend, true); }
|
||||
set { _settings.PutSetting(Constants.Settings.SaveSuspend, value); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,6 +10,7 @@ using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.ViewModels.ListItems;
|
||||
using ModernKeePass.Views;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
|
@@ -6,6 +6,7 @@ using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.ViewModels.ListItems;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
|
@@ -7,6 +7,7 @@ using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.ViewModels.ListItems;
|
||||
using ModernKeePass.Views;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
|
Reference in New Issue
Block a user