[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:
parent
a4f84844bc
commit
dcc4563c8c
|
@ -17,7 +17,6 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||
public WindowsSetting()
|
||||
{
|
||||
Name = string.Empty;
|
||||
Area = string.Empty;
|
||||
Command = string.Empty;
|
||||
Type = string.Empty;
|
||||
}
|
||||
|
@ -28,9 +27,9 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||
public string Name { get; set; }
|
||||
|
||||
/// <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>
|
||||
public string Area { get; set; }
|
||||
public IList<string>? Areas { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
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>();
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||
{
|
||||
Action = (_) => DoOpenSettingsAction(entry),
|
||||
IcoPath = iconPath,
|
||||
SubTitle = $"{Resources.Area} \"{entry.Area}\" {Resources.SubtitlePreposition} {entry.Type}",
|
||||
SubTitle = entry.JoinedFullSettingsPath,
|
||||
Title = entry.Name,
|
||||
ContextData = entry,
|
||||
};
|
||||
|
@ -62,7 +62,11 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||
var toolTipText = new StringBuilder();
|
||||
|
||||
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())
|
||||
{
|
||||
|
@ -163,7 +167,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||
continue;
|
||||
}
|
||||
|
||||
if (windowsSetting.Area.StartsWith(query, StringComparison.CurrentCultureIgnoreCase))
|
||||
if (windowsSetting.Areas.Any(x => x.StartsWith(query, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
result.Score = lowScore--;
|
||||
continue;
|
||||
|
|
|
@ -28,40 +28,49 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||
|
||||
foreach (var settings in settingsList)
|
||||
{
|
||||
var area = Resources.ResourceManager.GetString($"Area{settings.Area}");
|
||||
// Translate 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))
|
||||
{
|
||||
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))
|
||||
{
|
||||
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;
|
||||
|
||||
if (!string.IsNullOrEmpty(settings.Note))
|
||||
// Translate Areas
|
||||
if (!(settings.Areas is null) && settings.Areas.Any())
|
||||
{
|
||||
var note = Resources.ResourceManager.GetString(settings.Note);
|
||||
if (string.IsNullOrEmpty(note))
|
||||
var translatedAreas = new List<string>();
|
||||
|
||||
foreach (var area in settings.Areas)
|
||||
{
|
||||
Log.Warn($"Resource string for [{settings.Note}] not found", typeof(Main));
|
||||
if (string.IsNullOrWhiteSpace(area))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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.Note = note ?? settings.Note ?? string.Empty;
|
||||
settings.Areas = translatedAreas;
|
||||
}
|
||||
|
||||
// Translate Alternative names
|
||||
if (!(settings.AltNames is null) && settings.AltNames.Any())
|
||||
{
|
||||
var translatedAltNames = new Collection<string>();
|
||||
|
@ -76,7 +85,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||
var translatedAltName = Resources.ResourceManager.GetString(altName);
|
||||
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);
|
||||
|
@ -84,6 +93,18 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
|
|||
|
||||
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);
|
||||
|
||||
TranslationHelper.TranslateAllSettings(_settingsList);
|
||||
WindowsSettingsPathHelper.GenerateSettingsPathValues(_settingsList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -114,16 +115,23 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
|
|||
return true;
|
||||
}
|
||||
|
||||
// Search for Area only by key char
|
||||
if (found.Area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase)
|
||||
&& query.Search.EndsWith(":"))
|
||||
if (!(found.Areas is null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
foreach (var area in found.Areas)
|
||||
{
|
||||
// Search for areas on normal queries.
|
||||
if (area.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (found.Area.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
// Search for Area only on queries with action char.
|
||||
if (area.Contains(query.Search.Replace(":", string.Empty), StringComparison.CurrentCultureIgnoreCase)
|
||||
&& query.Search.EndsWith(":"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
/// Looks up a localized string similar to Cortana.
|
||||
/// </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>
|
||||
/// Looks up a localized string similar to Sync center.
|
||||
/// </summary>
|
||||
|
|
|
@ -253,9 +253,6 @@
|
|||
<data name="AreaClockAndRegion" xml:space="preserve">
|
||||
<value>Clock and Region</value>
|
||||
</data>
|
||||
<data name="AreaControlPanel" xml:space="preserve">
|
||||
<value>Control Panel</value>
|
||||
</data>
|
||||
<data name="AreaCortana" xml:space="preserve">
|
||||
<value>Cortana</value>
|
||||
</data>
|
||||
|
@ -1449,10 +1446,6 @@
|
|||
<value>Storage Sense</value>
|
||||
<comment>Area System</comment>
|
||||
</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">
|
||||
<value>Sync center</value>
|
||||
<comment>Area Control Panel (legacy settings)</comment>
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue