mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Removed Breadcrumb service
Breadcrumb control handles breadcrumb status Layout improvements Added the ability to delete an entry from the group menu
This commit is contained in:
@@ -1,45 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Models;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Models;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class BreadcrumbControlVm
|
||||
{
|
||||
public IEnumerable<BreadcrumbItem> BreadcrumbItems { get; }
|
||||
public string ParentGroupName => BreadcrumbItems.Last()?.Name;
|
||||
public ObservableCollection<BreadcrumbItem> BreadcrumbItems { get; }
|
||||
public string ParentGroupName { get; private set; }
|
||||
public Icon ParentGroupIcon { get; private set; }
|
||||
|
||||
public RelayCommand GoBackCommand { get; }
|
||||
public RelayCommand GoUpCommand { get; private set; }
|
||||
public RelayCommand<int> GoToCommand { get; }
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
private readonly INavigationService _navigation;
|
||||
private readonly IBreadcrumbService _breadcrumb;
|
||||
|
||||
public BreadcrumbControlVm(INavigationService navigation, IBreadcrumbService breadcrumb)
|
||||
public BreadcrumbControlVm(IMediator mediator, INavigationService navigation)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_navigation = navigation;
|
||||
_breadcrumb = breadcrumb;
|
||||
|
||||
BreadcrumbItems = _breadcrumb.GetItems().Reverse();
|
||||
GoBackCommand = new RelayCommand(GoBack);
|
||||
|
||||
BreadcrumbItems = new ObservableCollection<BreadcrumbItem>();
|
||||
GoBackCommand = new RelayCommand(() => _navigation.GoBack());
|
||||
GoToCommand = new RelayCommand<int>(GoTo);
|
||||
}
|
||||
|
||||
public async Task Initialize(GroupVm group)
|
||||
{
|
||||
GoUpCommand = new RelayCommand(() => GoTo(BreadcrumbItems.Count - 1), () => group != null);
|
||||
|
||||
if (group == null) return;
|
||||
ParentGroupName = group.Title;
|
||||
ParentGroupIcon = group.Icon;
|
||||
|
||||
BreadcrumbItems.Insert(0, new BreadcrumbItem { Path = group.Id, Name = group.Title, Icon = group.Icon });
|
||||
var parentGroup = group;
|
||||
while (!string.IsNullOrEmpty(parentGroup.ParentGroupId))
|
||||
{
|
||||
parentGroup = await _mediator.Send(new GetGroupQuery {Id = parentGroup.ParentGroupId});
|
||||
BreadcrumbItems.Insert(0, new BreadcrumbItem {Path = parentGroup.Id, Name = parentGroup.Title, Icon = parentGroup.Icon});
|
||||
}
|
||||
}
|
||||
|
||||
private void GoTo(int index)
|
||||
{
|
||||
var breadcrumb = _breadcrumb.Pop(BreadcrumbItems.Count() - index);
|
||||
if (BreadcrumbItems.Count == 0) return;
|
||||
var breadcrumb = BreadcrumbItems[index];
|
||||
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = breadcrumb.Path });
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
_breadcrumb.Pop();
|
||||
_navigation.GoBack();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user