From 59c903b635277d5d2bc2d29087ced6aba869d2b1 Mon Sep 17 00:00:00 2001 From: BONNEVILLE Geoffroy Date: Fri, 8 Jun 2018 12:08:06 +0200 Subject: [PATCH] Search box now recursively search sub groups --- ModernKeePass/ViewModels/GroupVm.cs | 21 ++++++++++++++++++--- ModernKeePass/Views/GroupDetailPage.xaml.cs | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ModernKeePass/ViewModels/GroupVm.cs b/ModernKeePass/ViewModels/GroupVm.cs index 3b656d3..14abc56 100644 --- a/ModernKeePass/ViewModels/GroupVm.cs +++ b/ModernKeePass/ViewModels/GroupVm.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; @@ -20,7 +21,22 @@ namespace ModernKeePass.ViewModels public ObservableCollection Entries { get { return _entries; } - set { SetProperty(ref _entries, value); } + private set { SetProperty(ref _entries, value); } + } + + public IEnumerable SubEntries + { + get + { + var subEntries = new List(); + subEntries.AddRange(Entries); + foreach (var group in Groups) + { + subEntries.AddRange(group.SubEntries); + } + + return subEntries; + } } public ObservableCollection Groups { get; set; } = new ObservableCollection(); @@ -28,8 +44,7 @@ namespace ModernKeePass.ViewModels public PwUuid IdUuid => _pwGroup?.Uuid; public string Id => IdUuid?.ToHexString(); public bool IsNotRoot => ParentGroup != null; - - + public bool ShowRestore => IsNotRoot && ParentGroup.IsSelected; public bool IsRecycleOnDelete => _database.RecycleBinEnabled && !IsSelected && !ParentGroup.IsSelected; diff --git a/ModernKeePass/Views/GroupDetailPage.xaml.cs b/ModernKeePass/Views/GroupDetailPage.xaml.cs index ae944cc..e30625f 100644 --- a/ModernKeePass/Views/GroupDetailPage.xaml.cs +++ b/ModernKeePass/Views/GroupDetailPage.xaml.cs @@ -156,7 +156,7 @@ namespace ModernKeePass.Views private void SearchBox_OnSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args) { var imageUri = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx://Assets/ModernKeePass-SmallLogo.scale-80.png")); - var results = Model.Entries.Where(e => e.Name.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5); + var results = Model.SubEntries.Where(e => e.Name.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5); foreach (var result in results) { args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Name, result.ParentGroup.Name, result.Id, imageUri, string.Empty);