[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:
Heiko
2021-09-06 12:46:14 +02:00
committed by GitHub
parent a4f84844bc
commit dcc4563c8c
9 changed files with 415 additions and 329 deletions

View File

@@ -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>();

View File

@@ -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;

View File

@@ -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;
}
}
}
}

View File

@@ -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;
}
}
}
}
}