From 181b1e45da25d7efb31b7b0276c22b7f718efda7 Mon Sep 17 00:00:00 2001
From: Heiko <61519853+htcfreek@users.noreply.github.com>
Date: Wed, 18 May 2022 16:27:02 +0200
Subject: [PATCH] [PTRun][TimeDate] Change global query setting to ignore
number input too (#18157)
* add new setting
* fix spelling
* update/fix setting
* fixes
* make setting default true and update tests
* fix spelling
* change settings/behavior
* docs and tests
* fix condition
---
doc/devdocs/modules/launcher/plugins/timedate.md | 12 ++++++------
.../QueryTests.cs | 8 ++++++--
.../Components/SearchController.cs | 5 +++--
.../Components/TimeDateSettings.cs | 2 +-
.../Properties/Resources.Designer.cs | 2 +-
.../Properties/Resources.resx | 2 +-
6 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/doc/devdocs/modules/launcher/plugins/timedate.md b/doc/devdocs/modules/launcher/plugins/timedate.md
index 4103beeaca..6ad856657a 100644
--- a/doc/devdocs/modules/launcher/plugins/timedate.md
+++ b/doc/devdocs/modules/launcher/plugins/timedate.md
@@ -69,12 +69,12 @@ The following formats are currently available:
- All available settings for the plugin are defined in the [`TimeDateSettings`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeDateSettings.cs) class of the plugin. The settings can be accessed everywhere in the plugin code via the static class instance `TimeDateSettings.Instance`.
- We have the following settings that the user can configure to change the behavior of the plugin:
- | Key | Default value | Name/Description |
- |--------------|-----------|------------|
- | `OnlyDateTimeNowGlobal` | `true` | Show only 'Time', 'Date', and 'Now' result on global queries |
- | `TimeWithSeconds` | `false` | Show time with seconds (Applies to 'Time' and 'Now' result) |
- | `DateWithWeekday` | `false` | Show date with weekday and name of month (Applies to 'Date' and 'Now' result) |
- | `HideNumberMessageOnGlobalQuery` | `false` | Hide 'Invalid number input' error message on global queries |
+ | Key | Default value | Name | Description |
+ |--------------|-----------|------------|------------|
+ | `OnlyDateTimeNowGlobal` | `true` | Show only 'Time', 'Date', and 'Now' result for system time on global queries | Regardless of this setting, for global queries the first word of the query has to be a complete match. |
+ | `TimeWithSeconds` | `false` | Show time with seconds | This setting applies to the 'Time' and 'Now' result. |
+ | `DateWithWeekday` | `false` | Show date with weekday and name of month | This setting applies to the 'Date' and 'Now' result. |
+ | `HideNumberMessageOnGlobalQuery` | `false` | Hide 'Invalid number input' error message on global queries | |
## Classes
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs
index 98606a638b..78563febf2 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs
@@ -38,8 +38,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
[DataRow("current", 3)]
[DataRow("year", 0)]
[DataRow("", 0)]
- [DataRow("time::10:10:10", 2)]
- [DataRow("date::10/10/10", 2)]
+ [DataRow("time::10:10:10", 0)]
+ [DataRow("date::10/10/10", 0)]
public void CountWithoutPluginKeyword(string typedString, int expectedResultCount)
{
// Setup
@@ -82,6 +82,10 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
[DataRow("and time", 1)] // match if term is conjunction and other words
[DataRow("date and time", 1)] // Match if first word is a full word match
[DataRow("ate and time", 0)] // Don't match if first word is not a full word match
+ [DataRow("10/10/10", 0)] // Don't match number only input (Setting 'Only Date, Time, Now on global results' is default on)
+ [DataRow("10:10:10", 0)] // Don't match number only input (Setting 'Only Date, Time, Now on global results' is default on)
+ [DataRow("10 10 10", 0)] // Don't match number only input (Setting 'Only Date, Time, Now on global results' is default on)
+ [DataRow("ft10", 1)] // Don't match number input with prefix (Setting 'Only Date, Time, Now on global results' is default on) => Test behave strange here.
public void ValidateBehaviorOnGlobalQueries(string typedString, int expectedResultCount)
{
// Setup
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs
index fef883818f..aa9d378502 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs
@@ -56,9 +56,10 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components
}
// Switch search type
- if (isEmptySearchInput)
+ if (isEmptySearchInput || (!isKeywordSearch && TimeDateSettings.Instance.OnlyDateTimeNowGlobal))
{
// Return all results for system time/date on empty keyword search
+ // or only time, date and now results for system time on global queries if the corresponding setting is enabled
availableFormats.AddRange(AvailableResultsList.GetList(isKeywordSearch));
}
else if (Regex.IsMatch(searchTerm, @".+" + Regex.Escape(InputDelimiter) + @".+"))
@@ -79,7 +80,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components
}
else
{
- // Search for specified format with system time/date
+ // Search for specified format with system time/date (All other cases)
availableFormats.AddRange(AvailableResultsList.GetList(isKeywordSearch));
}
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeDateSettings.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeDateSettings.cs
index f3df4fb85b..a4e3ff8377 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeDateSettings.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeDateSettings.cs
@@ -29,7 +29,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components
private static TimeDateSettings instance;
///
- /// Gets a value indicating whether to show only the time and date in global results or not
+ /// Gets a value indicating whether to show only the time and date for system time in global results or not
///
internal bool OnlyDateTimeNowGlobal { get; private set; }
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs
index 76d1dc4b74..2c535a5700 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs
@@ -430,7 +430,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Properties {
}
///
- /// Looks up a localized string similar to Show only 'Time', 'Date' and 'Now' result on global queries.
+ /// Looks up a localized string similar to Show only 'Time', 'Date' and 'Now' result for system time on global queries.
///
internal static string Microsoft_plugin_timedate_SettingOnlyDateTimeNowGlobal {
get {
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx
index 2565c71d3c..bf22dcdd6f 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx
@@ -256,7 +256,7 @@
Hide 'Invalid number input' error message on global queries
- Show only 'Time', 'Date' and 'Now' result on global queries
+ Show only 'Time', 'Date' and 'Now' result for system time on global queries
Regardless of this setting, for global queries the first word of the query has to be a complete match.