From cdb5cb56f1eed0abd78b4165a08cd9b57fa71815 Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Wed, 14 Apr 2021 23:12:14 +0200 Subject: [PATCH] [Feature] item starts with searchstring, sort it on top (#99), version 1.0.17.10 --- Config/Config.cs | 2 +- Properties/AssemblyInfo.cs | 4 ++-- UserInterface/Menu.cs | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Config/Config.cs b/Config/Config.cs index 9388582..6f35cfc 100644 --- a/Config/Config.cs +++ b/Config/Config.cs @@ -134,7 +134,7 @@ namespace SystemTrayMenu 1); // 0 = Dark mode, 1 = Light mode - if (registryValueAppsUseLightTheme != null && + if (registryValueAppsUseLightTheme != null && registryValueAppsUseLightTheme.ToString() == "0") { isDarkModeActive = true; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index bae796e..799f079 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.17.9")] -[assembly: AssemblyFileVersion("1.0.17.9")] +[assembly: AssemblyVersion("1.0.17.10")] +[assembly: AssemblyFileVersion("1.0.17.10")] diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index a825bdb..e6a6f8d 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -580,13 +580,36 @@ namespace SystemTrayMenu.UserInterface string filterField = dgv.Columns[1].Name; SearchTextChanging?.Invoke(); - data.DefaultView.RowFilter = string.Format( - CultureInfo.InvariantCulture, - "[{0}] LIKE '%{1}%'", - filterField, - textBoxSearch.Text); + string searchString = textBoxSearch.Text.Trim(); + string like = string.Empty; + string[] splittedParts = searchString.Split(" "); + if (splittedParts.Length > 1) + { + foreach (string splittedPart in splittedParts) + { + string and = string.Empty; + if (!string.IsNullOrEmpty(like)) + { + and = $" AND [{filterField}]"; + } - if (string.IsNullOrEmpty(textBoxSearch.Text)) + like += $"{and} LIKE '%{splittedPart}%'"; + } + } + else + { + like = $"LIKE '%{searchString}%'"; + } + + try + { + data.DefaultView.RowFilter = $"[{filterField}] {like}"; + } + catch (EvaluateException) + { + } + + if (string.IsNullOrEmpty(searchString)) { data.DefaultView.Sort = string.Empty; } @@ -597,7 +620,7 @@ namespace SystemTrayMenu.UserInterface foreach (DataRow row in data.Rows) { if (row[1].ToString().StartsWith( - textBoxSearch.Text, + searchString, StringComparison.InvariantCultureIgnoreCase)) { row[columnSortIndex] = 0;