mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Groups can now also be manually reordered
Design improvements
This commit is contained in:
@@ -275,7 +275,7 @@ namespace ModernKeePass.ViewModels
|
||||
public RelayCommand<Attachment> DeleteAttachmentCommand { get; set; }
|
||||
|
||||
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
private readonly INavigationService _navigation;
|
||||
private readonly IResourceProxy _resource;
|
||||
@@ -285,7 +285,7 @@ namespace ModernKeePass.ViewModels
|
||||
private GroupVm _parent;
|
||||
private EntryVm _selectedItem;
|
||||
private int _selectedIndex;
|
||||
private int _additionalFieldSelectedIndex;
|
||||
private int _additionalFieldSelectedIndex = -1;
|
||||
private bool _isEditMode;
|
||||
private bool _isRevealPassword;
|
||||
private double _passwordLength = 25;
|
||||
@@ -307,11 +307,11 @@ namespace ModernKeePass.ViewModels
|
||||
DeleteCommand = new RelayCommand(async () => await AskForDelete());
|
||||
GoBackCommand = new RelayCommand(() => _navigation.GoBack());
|
||||
GoToParentCommand = new RelayCommand(() => GoToGroup(_parent.Id));
|
||||
AddAdditionalField = new RelayCommand(AddField);
|
||||
DeleteAdditionalField = new RelayCommand<FieldVm>(async field => await DeleteField(field), field => field != null);
|
||||
AddAdditionalField = new RelayCommand(AddField, () => IsCurrentEntry);
|
||||
DeleteAdditionalField = new RelayCommand<FieldVm>(async field => await DeleteField(field), field => field != null && IsCurrentEntry);
|
||||
OpenAttachmentCommand = new RelayCommand<Attachment>(async attachment => await OpenAttachment(attachment));
|
||||
AddAttachmentCommand = new RelayCommand(async () => await AddAttachment(), () => IsCurrentEntry);
|
||||
DeleteAttachmentCommand = new RelayCommand<Attachment>(async attachment => await DeleteAttachment(attachment));
|
||||
DeleteAttachmentCommand = new RelayCommand<Attachment>(async attachment => await DeleteAttachment(attachment), _ => IsCurrentEntry);
|
||||
|
||||
MessengerInstance.Register<DatabaseSavedMessage>(this, _ => SaveCommand.RaiseCanExecuteChanged());
|
||||
MessengerInstance.Register<EntryFieldValueChangedMessage>(this, async message => await SetFieldValue(message.FieldName, message.FieldValue));
|
||||
|
@@ -20,6 +20,7 @@ using ModernKeePass.Application.Group.Commands.CreateEntry;
|
||||
using ModernKeePass.Application.Group.Commands.CreateGroup;
|
||||
using ModernKeePass.Application.Group.Commands.DeleteGroup;
|
||||
using ModernKeePass.Application.Group.Commands.MoveEntry;
|
||||
using ModernKeePass.Application.Group.Commands.MoveGroup;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveGroup;
|
||||
using ModernKeePass.Application.Group.Commands.SortEntries;
|
||||
using ModernKeePass.Application.Group.Commands.SortGroups;
|
||||
@@ -106,7 +107,8 @@ namespace ModernKeePass.ViewModels
|
||||
private GroupVm _parent;
|
||||
private bool _isEditMode;
|
||||
private EntryVm _reorderedEntry;
|
||||
|
||||
private GroupVm _reorderedGroup;
|
||||
|
||||
public GroupDetailVm(IMediator mediator, IResourceProxy resource, INavigationService navigation, IDialogService dialog, INotificationService notification)
|
||||
{
|
||||
_mediator = mediator;
|
||||
@@ -139,6 +141,7 @@ namespace ModernKeePass.ViewModels
|
||||
Entries = new ObservableCollection<EntryVm>(_group.Entries);
|
||||
Entries.CollectionChanged += Entries_CollectionChanged;
|
||||
Groups = new ObservableCollection<GroupVm>(_group.SubGroups);
|
||||
Groups.CollectionChanged += Groups_CollectionChanged;
|
||||
}
|
||||
|
||||
public void GoToEntry(string entryId, bool isNew = false)
|
||||
@@ -213,6 +216,29 @@ namespace ModernKeePass.ViewModels
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async void Groups_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
var oldIndex = e.OldStartingIndex;
|
||||
_reorderedGroup = _group.SubGroups[oldIndex];
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (_reorderedGroup == null)
|
||||
{
|
||||
var group = (GroupVm)e.NewItems[0];
|
||||
await _mediator.Send(new AddGroupCommand() { GroupId = group.Id, ParentGroupId = Id });
|
||||
}
|
||||
else
|
||||
{
|
||||
await _mediator.Send(new MoveGroupCommand { Group = _reorderedGroup, ParentGroup = _group, Index = e.NewStartingIndex });
|
||||
}
|
||||
break;
|
||||
}
|
||||
SaveCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
private async Task SortEntriesAsync()
|
||||
{
|
||||
await _mediator.Send(new SortEntriesCommand {Group = _group});
|
||||
|
Reference in New Issue
Block a user