mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Adding entries and groups works again
Entry history almost fully functional Some refactoring
This commit is contained in:
@@ -46,7 +46,15 @@ namespace ModernKeePass.ViewModels
|
||||
/// <summary>
|
||||
/// Determines if the Entry is current or from history
|
||||
/// </summary>
|
||||
public bool IsSelected { get; set; } = true;
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return _isSelected; }
|
||||
set
|
||||
{
|
||||
_isSelected = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public double PasswordLength
|
||||
{
|
||||
@@ -178,7 +186,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
}
|
||||
public IEnumerable<EntryVm> History => _entry.History;
|
||||
public IEnumerable<EntryVm> History => _history;
|
||||
|
||||
public bool IsEditMode
|
||||
{
|
||||
@@ -211,19 +219,21 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
|
||||
public bool CanRestore => _entry.ParentGroupId == _database.RecycleBinId;
|
||||
|
||||
|
||||
public ICommand SaveCommand { get; }
|
||||
public ICommand GeneratePasswordCommand { get; }
|
||||
public ICommand UndoDeleteCommand { get; }
|
||||
|
||||
private readonly EntryVm _entry;
|
||||
private readonly GroupVm _parent;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
private readonly GroupVm _parent;
|
||||
private readonly IEnumerable<EntryVm> _history;
|
||||
private EntryVm _entry;
|
||||
private bool _isEditMode;
|
||||
private bool _isRevealPassword;
|
||||
private double _passwordLength = 25;
|
||||
private bool _isVisible = true;
|
||||
private bool _isSelected;
|
||||
|
||||
public EntryDetailVm() { }
|
||||
|
||||
@@ -235,8 +245,10 @@ namespace ModernKeePass.ViewModels
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
_entry = _mediator.Send(new GetEntryQuery {Id = entryId}).GetAwaiter().GetResult();
|
||||
_parent = _mediator.Send(new GetGroupQuery {Id = _entry.ParentGroupId}).GetAwaiter().GetResult();
|
||||
_history = _entry.History;
|
||||
_isEditMode = isNewEntry;
|
||||
if (isNewEntry) GeneratePassword().GetAwaiter().GetResult();
|
||||
IsSelected = true;
|
||||
|
||||
SaveCommand = new RelayCommand(() => _mediator.Send(new SaveDatabaseCommand()));
|
||||
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
|
||||
@@ -271,15 +283,27 @@ namespace ModernKeePass.ViewModels
|
||||
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
|
||||
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _parent, Entry = _entry });
|
||||
}
|
||||
|
||||
public EntryVm GetEntry()
|
||||
{
|
||||
return _entry;
|
||||
}
|
||||
|
||||
|
||||
public async Task SetFieldValue(string fieldName, object value)
|
||||
{
|
||||
await _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = fieldName, FieldValue = value });
|
||||
}
|
||||
|
||||
internal void SetEntry(EntryVm entry, int index)
|
||||
{
|
||||
_entry = entry;
|
||||
IsSelected = index == 0;
|
||||
/*OnPropertyChanged(nameof(Title));
|
||||
OnPropertyChanged(nameof(UserName));
|
||||
OnPropertyChanged(nameof(Password));
|
||||
OnPropertyChanged(nameof(Url));
|
||||
OnPropertyChanged(nameof(Notes));
|
||||
OnPropertyChanged(nameof(Icon));
|
||||
OnPropertyChanged(nameof(ForegroundColor));
|
||||
OnPropertyChanged(nameof(BackgroundColor));
|
||||
OnPropertyChanged(nameof(HasExpirationDate));
|
||||
OnPropertyChanged(nameof(ExpiryDate));
|
||||
OnPropertyChanged(nameof(ExpiryTime));*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -159,7 +159,7 @@ namespace ModernKeePass.ViewModels
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (_reorderedEntry == null)
|
||||
{
|
||||
var entry = ((EntryDetailVm) e.NewItems[0]).GetEntry();
|
||||
var entry = (EntryVm) e.NewItems[0];
|
||||
await _mediator.Send(new AddEntryCommand {Entry = entry, ParentGroup = _group});
|
||||
}
|
||||
else
|
||||
|
@@ -2,9 +2,9 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetCipher;
|
||||
using ModernKeePass.Application.Parameters.Commands.SetCompression;
|
||||
@@ -16,16 +16,14 @@ using ModernKeePass.Application.Parameters.Queries.GetCiphers;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetCompressions;
|
||||
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
// TODO: implement Kdf settings
|
||||
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
|
||||
public class SettingsDatabaseVm: NotifyPropertyChangedBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
private GroupDetailVm _selectedItem;
|
||||
|
||||
public bool HasRecycleBin
|
||||
{
|
||||
@@ -42,11 +40,11 @@ namespace ModernKeePass.ViewModels
|
||||
get { return string.IsNullOrEmpty(_database.RecycleBinId); }
|
||||
set
|
||||
{
|
||||
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBin = null }).Wait();
|
||||
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = null }).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<GroupVm> Groups { get; set; }
|
||||
public ObservableCollection<IEntityVm> Groups { get; set; }
|
||||
|
||||
public IEnumerable<CipherVm> Ciphers => _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
|
||||
public IEnumerable<string> Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
|
||||
@@ -70,6 +68,14 @@ namespace ModernKeePass.ViewModels
|
||||
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).Wait(); }
|
||||
}
|
||||
|
||||
public IEntityVm SelectedRecycleBin
|
||||
{
|
||||
get { return Groups.FirstOrDefault(g => g.Id == _database.RecycleBinId); }
|
||||
set { _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id}).Wait(); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*public int CipherIndex
|
||||
{
|
||||
get
|
||||
@@ -93,7 +99,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
get { return KdfPool.Get(_database.KeyDerivation.KdfUuid).Name; }
|
||||
set { _database.KeyDerivation = KdfPool.Engines.FirstOrDefault(e => e.Name == value)?.GetDefaultParameters(); }
|
||||
}*/
|
||||
}
|
||||
|
||||
public ISelectableModel SelectedItem
|
||||
{
|
||||
@@ -106,14 +112,14 @@ namespace ModernKeePass.ViewModels
|
||||
_selectedItem.IsSelected = false;
|
||||
}
|
||||
|
||||
SetProperty(ref _selectedItem, (GroupDetailVm)value);
|
||||
SetProperty(ref _selectedItem, (IEntityVm)value);
|
||||
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.IsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public SettingsDatabaseVm() : this(App.Mediator) { }
|
||||
|
||||
@@ -122,7 +128,7 @@ namespace ModernKeePass.ViewModels
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
|
||||
Groups = new ObservableCollection<GroupVm>(rootGroup.SubGroups);
|
||||
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -62,14 +62,17 @@ namespace ModernKeePass.Views
|
||||
private void HamburgerMenuUserControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var listView = sender as ListView;
|
||||
switch (listView?.SelectedIndex)
|
||||
if (listView == null) return;
|
||||
var index = listView.SelectedIndex;
|
||||
switch (index)
|
||||
{
|
||||
case -1:
|
||||
return;
|
||||
default:
|
||||
var entry = listView?.SelectedItem as Application.Entry.Models.EntryVm;
|
||||
StackPanel.DataContext = entry;
|
||||
TopGrid.DataContext = entry;
|
||||
Model.SetEntry(entry, index);
|
||||
/*StackPanel.DataContext = entry;
|
||||
TopGrid.DataContext = entry;*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -130,8 +130,7 @@ namespace ModernKeePass.Views
|
||||
|
||||
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
|
||||
{
|
||||
var entry = Model.SubEntries.FirstOrDefault(e => e.Id == args.Tag);
|
||||
Frame.Navigate(typeof(EntryDetailPage), entry);
|
||||
Frame.Navigate(typeof(EntryDetailPage), args.Tag);
|
||||
}
|
||||
|
||||
private void GroupDetailPage_OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
|
@@ -23,8 +23,8 @@
|
||||
<ToggleSwitch x:Uid="SettingsDatabaseRecycleBin" IsOn="{Binding HasRecycleBin, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" />
|
||||
<StackPanel Visibility="{Binding HasRecycleBin, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<RadioButton x:Uid="SettingsDatabaseRecycleBinCreate" GroupName="Recycle" IsChecked="{Binding IsNewRecycleBin, Mode=TwoWay}" />
|
||||
<RadioButton x:Name="RadioButton" x:Uid="SettingsDatabaseRecycleBinExisting" GroupName="Recycle" IsChecked="{Binding SelectedItem, Converter={StaticResource NullToBooleanConverter}}" />
|
||||
<ComboBox ItemsSource="{Binding Source={StaticResource RecycleBinGroups}}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" IsEnabled="{Binding IsChecked, ElementName=RadioButton}" />
|
||||
<RadioButton x:Name="RadioButton" x:Uid="SettingsDatabaseRecycleBinExisting" GroupName="Recycle" IsChecked="{Binding SelectedRecycleBin, Converter={StaticResource NullToBooleanConverter}}" />
|
||||
<ComboBox ItemsSource="{Binding Source={StaticResource RecycleBinGroups}}" SelectedItem="{Binding SelectedRecycleBin, Mode=TwoWay}" IsEnabled="{Binding IsChecked, ElementName=RadioButton}" />
|
||||
</StackPanel>
|
||||
<TextBlock x:Uid="SettingsDatabaseEncryption" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,20,0,10" />
|
||||
<ComboBox ItemsSource="{Binding Source={StaticResource Ciphers}}" DisplayMemberPath="Name" SelectedItem="{Binding SelectedCipher, Mode=TwoWay}" ItemContainerStyle="{StaticResource MainColorComboBoxItem}" Style="{StaticResource MainColorComboBox}" />
|
||||
|
@@ -5,7 +5,13 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<ComboBox x:Name="ComboBox" ItemsSource="{Binding Colors, ElementName=UserControl}" SelectionChanged="Selector_OnSelectionChanged" Loaded="ComboBox_Loaded" ItemContainerStyle="{StaticResource MainColorComboBoxItem}" Style="{StaticResource MainColorComboBox}">
|
||||
<ComboBox x:Name="ComboBox"
|
||||
ItemsSource="{Binding Colors, ElementName=UserControl}"
|
||||
SelectionChanged="Selector_OnSelectionChanged"
|
||||
Loaded="ComboBox_Loaded"
|
||||
ItemContainerStyle="{StaticResource MainColorComboBoxItem}"
|
||||
Style="{StaticResource MainColorComboBox}"
|
||||
IsEnabled="{Binding IsEnabled, ElementName=UserControl}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,10,0">
|
||||
|
Reference in New Issue
Block a user