mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
adjust default result when query is empty
Make Tasklink Area Unknown Make Tasklink results score lower
This commit is contained in:
parent
b2090bc808
commit
123cad8450
4 changed files with 301 additions and 268 deletions
|
|
@ -18,6 +18,18 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
|
||||
public static void Init(IPublicAPI api) => _api = api;
|
||||
|
||||
private static List<Result> GetDefaultReuslts(in IEnumerable<WindowsSetting> list,
|
||||
string windowsSettingIconPath,
|
||||
string controlPanelIconPath)
|
||||
{
|
||||
return list.Select(entry =>
|
||||
{
|
||||
var result = NewSettingResult(100, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
|
||||
AddOptionalToolTip(entry, result);
|
||||
return result;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list with <see cref="Result"/>s, based on the given list.
|
||||
/// </summary>
|
||||
|
|
@ -31,13 +43,20 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
string windowsSettingIconPath,
|
||||
string controlPanelIconPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query.Search))
|
||||
{
|
||||
return GetDefaultReuslts(list, windowsSettingIconPath, controlPanelIconPath);
|
||||
}
|
||||
|
||||
var resultList = new List<Result>();
|
||||
|
||||
foreach (var entry in list)
|
||||
{
|
||||
// Adjust the score to lower the order of many irrelevant matches from area strings
|
||||
// that may only be for description.
|
||||
const int nonNameMatchScoreAdj = 10;
|
||||
|
||||
|
||||
Result? result;
|
||||
Debug.Assert(_api != null, nameof(_api) + " != null");
|
||||
|
||||
|
|
@ -45,7 +64,7 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
|
||||
if (nameMatch.IsSearchPrecisionScoreMet())
|
||||
{
|
||||
var settingResult = NewSettingResult(nameMatch.Score, entry.Type);
|
||||
var settingResult = NewSettingResult(nameMatch.Score, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
|
||||
settingResult.TitleHighlightData = nameMatch.MatchData;
|
||||
result = settingResult;
|
||||
}
|
||||
|
|
@ -54,7 +73,7 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
var areaMatch = _api.FuzzySearch(query.Search, entry.Area);
|
||||
if (areaMatch.IsSearchPrecisionScoreMet())
|
||||
{
|
||||
var settingResult = NewSettingResult(areaMatch.Score - nonNameMatchScoreAdj, entry.Type);
|
||||
var settingResult = NewSettingResult(areaMatch.Score - nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
|
||||
result = settingResult;
|
||||
}
|
||||
else
|
||||
|
|
@ -62,7 +81,7 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
result = entry.AltNames?
|
||||
.Select(altName => _api.FuzzySearch(query.Search, altName))
|
||||
.Where(match => match.IsSearchPrecisionScoreMet())
|
||||
.Select(altNameMatch => NewSettingResult(altNameMatch.Score - nonNameMatchScoreAdj, entry.Type))
|
||||
.Select(altNameMatch => NewSettingResult(altNameMatch.Score - nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +95,7 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
.SelectMany(x => x)
|
||||
.Contains(x, StringComparer.CurrentCultureIgnoreCase))
|
||||
)
|
||||
result = NewSettingResult(nonNameMatchScoreAdj, entry.Type);
|
||||
result = NewSettingResult(nonNameMatchScoreAdj, entry.Type, windowsSettingIconPath, controlPanelIconPath, entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,21 +105,23 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Helper
|
|||
AddOptionalToolTip(entry, result);
|
||||
|
||||
resultList.Add(result);
|
||||
|
||||
Result NewSettingResult(int score, string type) => new()
|
||||
{
|
||||
Action = _ => DoOpenSettingsAction(entry),
|
||||
IcoPath = type == "AppSettingsApp" ? windowsSettingIconPath : controlPanelIconPath,
|
||||
SubTitle = GetSubtitle(entry.Area, type),
|
||||
Title = entry.Name + entry.glyph,
|
||||
ContextData = entry,
|
||||
Score = score
|
||||
};
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private const int TaskLinkScorePanelty = 50;
|
||||
|
||||
private static Result NewSettingResult(int score, string type, string windowsSettingIconPath, string controlPanelIconPath, WindowsSetting entry) => new()
|
||||
{
|
||||
Action = _ => DoOpenSettingsAction(entry),
|
||||
IcoPath = type == "AppSettingsApp" ? windowsSettingIconPath : controlPanelIconPath,
|
||||
SubTitle = GetSubtitle(entry.Area, type),
|
||||
Title = entry.Name + entry.glyph,
|
||||
ContextData = entry,
|
||||
Score = score - (type == "TaskLink" ? TaskLinkScorePanelty : 0),
|
||||
};
|
||||
|
||||
private static string GetSubtitle(string section, string entryType)
|
||||
{
|
||||
var settingType = entryType == "AppSettingsApp" ? "System settings" : "Control Panel";
|
||||
|
|
|
|||
|
|
@ -736,6 +736,15 @@ namespace Flow.Launcher.Plugin.WindowsSettings.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unknown.
|
||||
/// </summary>
|
||||
public static string AreaUnknown {
|
||||
get {
|
||||
return ResourceManager.GetString("AreaUnknown", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Update and security.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -2508,4 +2508,7 @@
|
|||
<data name="TaskLink" xml:space="preserve">
|
||||
<value>TaskLink</value>
|
||||
</data>
|
||||
<data name="AreaUnknown" xml:space="preserve">
|
||||
<value>Unknown</value>
|
||||
</data>
|
||||
</root>
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue