mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[WindowsSettings Plugin] Improve subtitle and area naming (#12915)
* Update WindowsSettings clas * Update TranslationHelper * Adding ToDos to code * Adding ToDo notes * Introduce AreaPathHelper * Small improvement * Improve helper class * Update ResultHelper * Fix spelling * adding todo marker * Improve calling of <WindowsSettingsPathHelper>: Update class <WindowsSetting> * Improve calling of <WindowsSettingsPathHelper>: Update helper class * Improve calling of <WindowsSettingsPathHelper>: Implement method call * TranslationHelper: Small fixes * Fix scoring for areas property * Fix search filters for area property * small fixes * Update WindowsSettings.json * adding todos * Code cleanup, improvements and fixes * Small changes * Update resource strings * Fix msitakes * Update settings * resolve review feedback
This commit is contained in:
@@ -17,7 +17,6 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||||||
public WindowsSetting()
|
public WindowsSetting()
|
||||||
{
|
{
|
||||||
Name = string.Empty;
|
Name = string.Empty;
|
||||||
Area = string.Empty;
|
|
||||||
Command = string.Empty;
|
Command = string.Empty;
|
||||||
Type = string.Empty;
|
Type = string.Empty;
|
||||||
}
|
}
|
||||||
@@ -28,9 +27,9 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the area of this setting.
|
/// Gets or sets the areas of this setting. The order is fixed to the order in json.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Area { get; set; }
|
public IList<string>? Areas { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the command of this setting.
|
/// Gets or sets the command of this setting.
|
||||||
@@ -62,5 +61,19 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||||||
/// Gets or sets the Windows build since this settings is not longer present.
|
/// Gets or sets the Windows build since this settings is not longer present.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint? DeprecatedInBuild { get; set; }
|
public uint? DeprecatedInBuild { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the the value with the generated area path as string.
|
||||||
|
/// This Property IS NOT PART OF THE DATA IN "WindowsSettings.json".
|
||||||
|
/// This property will be filled on runtime by "WindowsSettingsPathHelper".
|
||||||
|
/// </summary>
|
||||||
|
public string? JoinedAreaPath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the the value with the generated full settings path (App and areas) as string.
|
||||||
|
/// This Property IS NOT PART OF THE DATA IN "WindowsSettings.json".
|
||||||
|
/// This property will be filled on runtime by "WindowsSettingsPathHelper".
|
||||||
|
/// </summary>
|
||||||
|
public string? JoinedFullSettingsPath { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Log.Exception("Error loading settings JSON file", exception, typeof(Main));
|
Log.Exception("Error loading settings JSON file", exception, typeof(JsonSettingsListHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
return settingsList ?? Enumerable.Empty<WindowsSetting>();
|
return settingsList ?? Enumerable.Empty<WindowsSetting>();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
{
|
{
|
||||||
Action = (_) => DoOpenSettingsAction(entry),
|
Action = (_) => DoOpenSettingsAction(entry),
|
||||||
IcoPath = iconPath,
|
IcoPath = iconPath,
|
||||||
SubTitle = $"{Resources.Area} \"{entry.Area}\" {Resources.SubtitlePreposition} {entry.Type}",
|
SubTitle = entry.JoinedFullSettingsPath,
|
||||||
Title = entry.Name,
|
Title = entry.Name,
|
||||||
ContextData = entry,
|
ContextData = entry,
|
||||||
};
|
};
|
||||||
@@ -62,7 +62,11 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
var toolTipText = new StringBuilder();
|
var toolTipText = new StringBuilder();
|
||||||
|
|
||||||
toolTipText.AppendLine($"{Resources.Application}: {entry.Type}");
|
toolTipText.AppendLine($"{Resources.Application}: {entry.Type}");
|
||||||
toolTipText.AppendLine($"{Resources.Area}: {entry.Area}");
|
|
||||||
|
if (entry.Areas != null && entry.Areas.Any())
|
||||||
|
{
|
||||||
|
toolTipText.AppendLine($"{Resources.Area}: {entry.JoinedAreaPath}");
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.AltNames != null && entry.AltNames.Any())
|
if (entry.AltNames != null && entry.AltNames.Any())
|
||||||
{
|
{
|
||||||
@@ -163,7 +167,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (windowsSetting.Area.StartsWith(query, StringComparison.CurrentCultureIgnoreCase))
|
if (windowsSetting.Areas.Any(x => x.StartsWith(query, StringComparison.CurrentCultureIgnoreCase)))
|
||||||
{
|
{
|
||||||
result.Score = lowScore--;
|
result.Score = lowScore--;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -28,40 +28,49 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
|
|
||||||
foreach (var settings in settingsList)
|
foreach (var settings in settingsList)
|
||||||
{
|
{
|
||||||
var area = Resources.ResourceManager.GetString($"Area{settings.Area}");
|
// Translate Name
|
||||||
var name = Resources.ResourceManager.GetString(settings.Name);
|
var name = Resources.ResourceManager.GetString(settings.Name);
|
||||||
var type = Resources.ResourceManager.GetString(settings.Type);
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(area))
|
|
||||||
{
|
|
||||||
Log.Warn($"Resource string for [Area{settings.Area}] not found", typeof(Main));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(name))
|
if (string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
Log.Warn($"Resource string for [{settings.Name}] not found", typeof(Main));
|
Log.Warn($"Resource string for [{settings.Name}] not found", typeof(TranslationHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings.Name = name ?? settings.Name ?? string.Empty;
|
||||||
|
|
||||||
|
// Translate Type (App)
|
||||||
|
var type = Resources.ResourceManager.GetString(settings.Type);
|
||||||
if (string.IsNullOrEmpty(type))
|
if (string.IsNullOrEmpty(type))
|
||||||
{
|
{
|
||||||
Log.Warn($"Resource string for [{settings.Name}] not found", typeof(Main));
|
Log.Warn($"Resource string for [{settings.Type}] not found", typeof(TranslationHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.Area = area ?? settings.Area ?? string.Empty;
|
|
||||||
settings.Name = name ?? settings.Name ?? string.Empty;
|
|
||||||
settings.Type = type ?? settings.Type ?? string.Empty;
|
settings.Type = type ?? settings.Type ?? string.Empty;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(settings.Note))
|
// Translate Areas
|
||||||
|
if (!(settings.Areas is null) && settings.Areas.Any())
|
||||||
{
|
{
|
||||||
var note = Resources.ResourceManager.GetString(settings.Note);
|
var translatedAreas = new List<string>();
|
||||||
if (string.IsNullOrEmpty(note))
|
|
||||||
|
foreach (var area in settings.Areas)
|
||||||
{
|
{
|
||||||
Log.Warn($"Resource string for [{settings.Note}] not found", typeof(Main));
|
if (string.IsNullOrWhiteSpace(area))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.Note = note ?? settings.Note ?? string.Empty;
|
var translatedArea = Resources.ResourceManager.GetString(area);
|
||||||
|
if (string.IsNullOrEmpty(translatedArea))
|
||||||
|
{
|
||||||
|
Log.Warn($"Resource string for [{area}] not found", typeof(TranslationHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translatedAreas.Add(translatedArea ?? area);
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.Areas = translatedAreas;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translate Alternative names
|
||||||
if (!(settings.AltNames is null) && settings.AltNames.Any())
|
if (!(settings.AltNames is null) && settings.AltNames.Any())
|
||||||
{
|
{
|
||||||
var translatedAltNames = new Collection<string>();
|
var translatedAltNames = new Collection<string>();
|
||||||
@@ -76,7 +85,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
var translatedAltName = Resources.ResourceManager.GetString(altName);
|
var translatedAltName = Resources.ResourceManager.GetString(altName);
|
||||||
if (string.IsNullOrEmpty(translatedAltName))
|
if (string.IsNullOrEmpty(translatedAltName))
|
||||||
{
|
{
|
||||||
Log.Warn($"Resource string for [{altName}] not found", typeof(Main));
|
Log.Warn($"Resource string for [{altName}] not found", typeof(TranslationHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
translatedAltNames.Add(translatedAltName ?? altName);
|
translatedAltNames.Add(translatedAltName ?? altName);
|
||||||
@@ -84,6 +93,18 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||||||
|
|
||||||
settings.AltNames = translatedAltNames;
|
settings.AltNames = translatedAltNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translate Note
|
||||||
|
if (!string.IsNullOrEmpty(settings.Note))
|
||||||
|
{
|
||||||
|
var note = Resources.ResourceManager.GetString(settings.Note);
|
||||||
|
if (string.IsNullOrEmpty(note))
|
||||||
|
{
|
||||||
|
Log.Warn($"Resource string for [{settings.Note}] not found", typeof(TranslationHelper));
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.Note = note ?? settings.Note ?? string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Wox.Plugin.Logger;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Helper class to help with the path of a <see cref="WindowsSetting"/>. The settings path shows where to find a setting within Windows' user interface.
|
||||||
|
/// </summary>
|
||||||
|
internal static class WindowsSettingsPathHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The symbol which is used as delimiter between the parts of the path.
|
||||||
|
/// </summary>
|
||||||
|
private const string _pathDelimiterSequence = "\u0020\u0020\u02C3\u0020\u0020"; // = "<space><space><arrow><space><space>"
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates the values for <see cref="WindowsSetting.JoinedAreaPath"/> and <see cref="WindowsSetting.JoinedFullSettingsPath"/> on all settings of the given list with <see cref="WindowsSetting"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="settingsList">The list that contains <see cref="WindowsSetting"/> to translate.</param>
|
||||||
|
internal static void GenerateSettingsPathValues(in IEnumerable<WindowsSetting>? settingsList)
|
||||||
|
{
|
||||||
|
if (settingsList is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var settings in settingsList)
|
||||||
|
{
|
||||||
|
// Check if type value is filled. If not, then write log warning.
|
||||||
|
if (string.IsNullOrEmpty(settings.Type))
|
||||||
|
{
|
||||||
|
Log.Warn($"The type property is not set for setting [{settings.Name}] in json. Skipping generating of settings path.", typeof(WindowsSettingsPathHelper));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if "JoinedAreaPath" and "JoinedFullSettingsPath" are filled. Then log debug message.
|
||||||
|
if (!string.IsNullOrEmpty(settings.JoinedAreaPath))
|
||||||
|
{
|
||||||
|
Log.Debug($"The property [JoinedAreaPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten.", typeof(WindowsSettingsPathHelper));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(settings.JoinedFullSettingsPath))
|
||||||
|
{
|
||||||
|
Log.Debug($"The property [JoinedFullSettingsPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten.", typeof(WindowsSettingsPathHelper));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generating path values.
|
||||||
|
if (!(settings.Areas is null) && settings.Areas.Any())
|
||||||
|
{
|
||||||
|
var areaValue = string.Join(WindowsSettingsPathHelper._pathDelimiterSequence, settings.Areas);
|
||||||
|
settings.JoinedAreaPath = areaValue;
|
||||||
|
settings.JoinedFullSettingsPath = $"{settings.Type}{WindowsSettingsPathHelper._pathDelimiterSequence}{areaValue}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings.JoinedAreaPath = string.Empty;
|
||||||
|
settings.JoinedFullSettingsPath = settings.Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||||||
_settingsList = UnsupportedSettingsHelper.FilterByBuild(_settingsList);
|
_settingsList = UnsupportedSettingsHelper.FilterByBuild(_settingsList);
|
||||||
|
|
||||||
TranslationHelper.TranslateAllSettings(_settingsList);
|
TranslationHelper.TranslateAllSettings(_settingsList);
|
||||||
|
WindowsSettingsPathHelper.GenerateSettingsPathValues(_settingsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -114,17 +115,24 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for Area only by key char
|
if (!(found.Areas is null))
|
||||||
if (found.Area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase)
|
{
|
||||||
&& query.Search.EndsWith(":"))
|
foreach (var area in found.Areas)
|
||||||
|
{
|
||||||
|
// Search for areas on normal queries.
|
||||||
|
if (area.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found.Area.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
// Search for Area only on queries with action char.
|
||||||
|
if (area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase)
|
||||||
|
&& query.Search.EndsWith(":"))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!(found.AltNames is null))
|
if (!(found.AltNames is null))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -384,15 +384,6 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Control Panel.
|
|
||||||
/// </summary>
|
|
||||||
internal static string AreaControlPanel {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("AreaControlPanel", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Cortana.
|
/// Looks up a localized string similar to Cortana.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -3273,15 +3264,6 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to in.
|
|
||||||
/// </summary>
|
|
||||||
internal static string SubtitlePreposition {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("SubtitlePreposition", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Sync center.
|
/// Looks up a localized string similar to Sync center.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -253,9 +253,6 @@
|
|||||||
<data name="AreaClockAndRegion" xml:space="preserve">
|
<data name="AreaClockAndRegion" xml:space="preserve">
|
||||||
<value>Clock and Region</value>
|
<value>Clock and Region</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="AreaControlPanel" xml:space="preserve">
|
|
||||||
<value>Control Panel</value>
|
|
||||||
</data>
|
|
||||||
<data name="AreaCortana" xml:space="preserve">
|
<data name="AreaCortana" xml:space="preserve">
|
||||||
<value>Cortana</value>
|
<value>Cortana</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -1449,10 +1446,6 @@
|
|||||||
<value>Storage Sense</value>
|
<value>Storage Sense</value>
|
||||||
<comment>Area System</comment>
|
<comment>Area System</comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="SubtitlePreposition" xml:space="preserve">
|
|
||||||
<value>in</value>
|
|
||||||
<comment>Example: Area "System" in System settings</comment>
|
|
||||||
</data>
|
|
||||||
<data name="SyncCenter" xml:space="preserve">
|
<data name="SyncCenter" xml:space="preserve">
|
||||||
<value>Sync center</value>
|
<value>Sync center</value>
|
||||||
<comment>Area Control Panel (legacy settings)</comment>
|
<comment>Area Control Panel (legacy settings)</comment>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user