From cc9b7d62df7a08fdbba31471fa662da6df531d38 Mon Sep 17 00:00:00 2001 From: donlaci Date: Fri, 14 Jun 2024 10:36:09 +0200 Subject: [PATCH] extend search for projects by search over the containing apps' names --- .../ViewModels/MainViewModel.cs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs index 536e87fe60..49d832b5b8 100644 --- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs +++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs @@ -8,12 +8,10 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Timers; -using System.Windows.Media.Imaging; using ManagedCommon; using ProjectsEditor.Models; using ProjectsEditor.Utils; @@ -31,7 +29,7 @@ namespace ProjectsEditor.ViewModels { get { - IEnumerable projects = string.IsNullOrEmpty(_searchTerm) ? Projects : Projects.Where(x => x.Name.Contains(_searchTerm, StringComparison.InvariantCultureIgnoreCase)); + IEnumerable projects = GetFilteredProjects(); if (projects == null) { return Enumerable.Empty(); @@ -53,6 +51,30 @@ namespace ProjectsEditor.ViewModels } } + // return those projects where the project name or any of the selected apps' name contains the search term + private IEnumerable GetFilteredProjects() + { + if (string.IsNullOrEmpty(_searchTerm)) + { + return Projects; + } + + return Projects.Where(x => + { + if (x.Name.Contains(_searchTerm, StringComparison.InvariantCultureIgnoreCase)) + { + return true; + } + + if (x.Applications == null) + { + return false; + } + + return x.Applications.Any(app => app.IsSelected && app.AppName.Contains(_searchTerm, StringComparison.InvariantCultureIgnoreCase)); + }); + } + private string _searchTerm; public string SearchTerm