diff --git a/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs b/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs index 42498eb..ab012b4 100644 --- a/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs +++ b/ModernKeePass.Application/Common/Interfaces/IEntityVm.cs @@ -8,7 +8,6 @@ namespace ModernKeePass.Application.Common.Interfaces string Id { get; set; } string Title { get; set; } Icon Icon { get; set; } - List Breadcrumb { get; } string ParentGroupId { get; set; } string ParentGroupName { get; set; } } diff --git a/ModernKeePass.Application/Entry/Models/EntryVm.cs b/ModernKeePass.Application/Entry/Models/EntryVm.cs index 760ad90..36d7d5b 100644 --- a/ModernKeePass.Application/Entry/Models/EntryVm.cs +++ b/ModernKeePass.Application/Entry/Models/EntryVm.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using AutoMapper; using ModernKeePass.Application.Common.Interfaces; using ModernKeePass.Application.Common.Mappings; @@ -13,7 +14,6 @@ namespace ModernKeePass.Application.Entry.Models { public string ParentGroupId { get; set; } public string ParentGroupName { get; set; } - public List Breadcrumb { get; } = new List(); public string Id { get; set; } public string Title { get; set; } public string Username { get; set; } @@ -46,7 +46,7 @@ namespace ModernKeePass.Application.Entry.Models .ForMember(d => d.Url, opts => opts.MapFrom(s => s.Url)) .ForMember(d => d.Notes, opts => opts.MapFrom(s => s.Notes)) .ForMember(d => d.AdditionalFields, opts => opts.MapFrom(s => s.AdditionalFields)) - .ForMember(d => d.History, opts => opts.MapFrom(s => s.History)) + .ForMember(d => d.History, opts => opts.MapFrom(s => s.History.OrderByDescending(h => h.LastModificationDate))) .ForMember(d => d.HasExpirationDate, opts => opts.MapFrom(s => s.HasExpirationDate)) .ForMember(d => d.ExpirationDate, opts => opts.MapFrom(s => s.ExpirationDate)) .ForMember(d => d.ModificationDate, opts => opts.MapFrom(s => s.LastModificationDate)) diff --git a/ModernKeePass.Application/Group/Models/GroupVm.cs b/ModernKeePass.Application/Group/Models/GroupVm.cs index 81d8f81..c7428a8 100644 --- a/ModernKeePass.Application/Group/Models/GroupVm.cs +++ b/ModernKeePass.Application/Group/Models/GroupVm.cs @@ -16,7 +16,6 @@ namespace ModernKeePass.Application.Group.Models public string Id { get; set; } public string Title { get; set; } public Icon Icon { get; set; } - public List Breadcrumb { get; } = new List(); public List SubGroups { get; set; } public List Entries { get; set; } public bool IsSelected { get; set; } diff --git a/ModernKeePass.Application/Parameters/Commands/SetRecycleBin/SetRecycleBinCommand.cs b/ModernKeePass.Application/Parameters/Commands/SetRecycleBin/SetRecycleBinCommand.cs index bb7e0f3..552047f 100644 --- a/ModernKeePass.Application/Parameters/Commands/SetRecycleBin/SetRecycleBinCommand.cs +++ b/ModernKeePass.Application/Parameters/Commands/SetRecycleBin/SetRecycleBinCommand.cs @@ -1,13 +1,12 @@ using MediatR; using ModernKeePass.Application.Common.Interfaces; -using ModernKeePass.Application.Group.Models; using ModernKeePass.Domain.Exceptions; namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin { public class SetRecycleBinCommand : IRequest { - public GroupVm RecycleBin { get; set; } + public string RecycleBinId { get; set; } public class SetRecycleBinCommandHandler : IRequestHandler { @@ -20,7 +19,7 @@ namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin public void Handle(SetRecycleBinCommand message) { - if (_database.IsOpen) _database.SetRecycleBin(message.RecycleBin.Id); + if (_database.IsOpen) _database.SetRecycleBin(message.RecycleBinId); else throw new DatabaseClosedException(); } } diff --git a/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs index e3f06fc..c649523 100644 --- a/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs +++ b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseClient.cs @@ -191,7 +191,7 @@ namespace ModernKeePass.Infrastructure.KeePass { var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true); var pwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(groupId), true); - parentPwGroup.Groups.Add(pwGroup); + parentPwGroup.AddGroup(pwGroup, true); }); } public async Task RemoveEntry(string parentGroupId, string entryId) @@ -288,7 +288,7 @@ namespace ModernKeePass.Infrastructure.KeePass { var pwEntry = new PwEntry(true, true); var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true); - parentPwGroup.Entries.Add(pwEntry); + parentPwGroup.AddEntry(pwEntry, true); return _mapper.Map(pwEntry); } @@ -297,7 +297,7 @@ namespace ModernKeePass.Infrastructure.KeePass { var pwGroup = new PwGroup(true, true, name, isRecycleBin? PwIcon.TrashBin : PwIcon.Folder); var parentPwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(parentGroupId), true); - parentPwGroup.Groups.Add(pwGroup); + parentPwGroup.AddGroup(pwGroup, true); if (isRecycleBin) _pwDatabase.RecycleBinUuid = pwGroup.Uuid; return _mapper.Map(pwGroup); diff --git a/ModernKeePass/ViewModels/EntryDetailVm.cs b/ModernKeePass/ViewModels/EntryDetailVm.cs index 6a0e28a..664dab9 100644 --- a/ModernKeePass/ViewModels/EntryDetailVm.cs +++ b/ModernKeePass/ViewModels/EntryDetailVm.cs @@ -46,7 +46,15 @@ namespace ModernKeePass.ViewModels /// /// Determines if the Entry is current or from history /// - 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 History => _entry.History; + public IEnumerable 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 _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));*/ + } } } diff --git a/ModernKeePass/ViewModels/GroupDetailVm.cs b/ModernKeePass/ViewModels/GroupDetailVm.cs index 33a98eb..ec148c7 100644 --- a/ModernKeePass/ViewModels/GroupDetailVm.cs +++ b/ModernKeePass/ViewModels/GroupDetailVm.cs @@ -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 diff --git a/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs b/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs index 767dcf2..b29c174 100644 --- a/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs +++ b/ModernKeePass/ViewModels/Items/SettingsDatabaseVm.cs @@ -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 Groups { get; set; } + public ObservableCollection Groups { get; set; } public IEnumerable Ciphers => _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult(); public IEnumerable 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(rootGroup.SubGroups); + Groups = new ObservableCollection(rootGroup.SubGroups); } } } diff --git a/ModernKeePass/Views/EntryDetailPage.xaml.cs b/ModernKeePass/Views/EntryDetailPage.xaml.cs index 596cf76..e81b5f9 100644 --- a/ModernKeePass/Views/EntryDetailPage.xaml.cs +++ b/ModernKeePass/Views/EntryDetailPage.xaml.cs @@ -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; } } diff --git a/ModernKeePass/Views/GroupDetailPage.xaml.cs b/ModernKeePass/Views/GroupDetailPage.xaml.cs index 9f4ec59..936fec6 100644 --- a/ModernKeePass/Views/GroupDetailPage.xaml.cs +++ b/ModernKeePass/Views/GroupDetailPage.xaml.cs @@ -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) diff --git a/ModernKeePass/Views/SettingsPageFrames/SettingsDatabasePage.xaml b/ModernKeePass/Views/SettingsPageFrames/SettingsDatabasePage.xaml index 962fae0..3084b2b 100644 --- a/ModernKeePass/Views/SettingsPageFrames/SettingsDatabasePage.xaml +++ b/ModernKeePass/Views/SettingsPageFrames/SettingsDatabasePage.xaml @@ -23,8 +23,8 @@ - - + + diff --git a/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml b/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml index aef0945..ba2d02c 100644 --- a/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml +++ b/ModernKeePass/Views/UserControls/ColorPickerUserControl.xaml @@ -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"> - +