mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 11:09:28 +08:00
Highlight how results matched
This commit is contained in:
parent
a004ef65af
commit
601d6f37af
@ -27,7 +27,6 @@ namespace Wox.Plugin.ControlPanel
|
|||||||
Directory.CreateDirectory(iconFolder);
|
Directory.CreateDirectory(iconFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (ControlPanelItem item in controlPanelItems)
|
foreach (ControlPanelItem item in controlPanelItems)
|
||||||
{
|
{
|
||||||
if (!File.Exists(iconFolder + item.GUID + fileType) && item.Icon != null)
|
if (!File.Exists(iconFolder + item.GUID + fileType) && item.Icon != null)
|
||||||
@ -43,7 +42,10 @@ namespace Wox.Plugin.ControlPanel
|
|||||||
|
|
||||||
foreach (var item in controlPanelItems)
|
foreach (var item in controlPanelItems)
|
||||||
{
|
{
|
||||||
item.Score = Score(item, query.Search);
|
var titleMatch = StringMatcher.FuzzySearch(query.Search, item.LocalizedString);
|
||||||
|
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, item.InfoTip);
|
||||||
|
|
||||||
|
item.Score = Math.Max(titleMatch.Score, subTitleMatch.Score);
|
||||||
if (item.Score > 0)
|
if (item.Score > 0)
|
||||||
{
|
{
|
||||||
var result = new Result
|
var result = new Result
|
||||||
@ -66,6 +68,16 @@ namespace Wox.Plugin.ControlPanel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (item.Score == titleMatch.Score)
|
||||||
|
{
|
||||||
|
result.TitleHighlightData = titleMatch.MatchData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.SubTitleHighlightData = subTitleMatch.MatchData;
|
||||||
|
}
|
||||||
|
|
||||||
results.Add(result);
|
results.Add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,26 +86,6 @@ namespace Wox.Plugin.ControlPanel
|
|||||||
return panelItems;
|
return panelItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int Score(ControlPanelItem item, string query)
|
|
||||||
{
|
|
||||||
var scores = new List<int> {0};
|
|
||||||
if (!string.IsNullOrEmpty(item.LocalizedString))
|
|
||||||
{
|
|
||||||
var score1 = StringMatcher.FuzzySearch(query, item.LocalizedString).ScoreAfterSearchPrecisionFilter();
|
|
||||||
var score2 = StringMatcher.ScoreForPinyin(item.LocalizedString, query);
|
|
||||||
scores.Add(score1);
|
|
||||||
scores.Add(score2);
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(item.InfoTip))
|
|
||||||
{
|
|
||||||
var score1 = StringMatcher.FuzzySearch(query, item.InfoTip).ScoreAfterSearchPrecisionFilter();
|
|
||||||
var score2 = StringMatcher.ScoreForPinyin(item.InfoTip, query);
|
|
||||||
scores.Add(score1);
|
|
||||||
scores.Add(score2);
|
|
||||||
}
|
|
||||||
return scores.Max();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_name");
|
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_name");
|
||||||
|
@ -55,6 +55,7 @@ namespace Wox.Plugin.Everything
|
|||||||
r.Title = Path.GetFileName(path);
|
r.Title = Path.GetFileName(path);
|
||||||
r.SubTitle = path;
|
r.SubTitle = path;
|
||||||
r.IcoPath = path;
|
r.IcoPath = path;
|
||||||
|
r.TitleHighlightData = StringMatcher.FuzzySearch(keyword, Path.GetFileName(path)).MatchData;
|
||||||
r.Action = c =>
|
r.Action = c =>
|
||||||
{
|
{
|
||||||
bool hide;
|
bool hide;
|
||||||
@ -78,6 +79,7 @@ namespace Wox.Plugin.Everything
|
|||||||
return hide;
|
return hide;
|
||||||
};
|
};
|
||||||
r.ContextData = s;
|
r.ContextData = s;
|
||||||
|
r.SubTitleHighlightData = StringMatcher.FuzzySearch(keyword, path).MatchData;
|
||||||
results.Add(r);
|
results.Add(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
|
|
||||||
namespace Wox.Plugin.Folder
|
namespace Wox.Plugin.Folder
|
||||||
@ -53,6 +54,7 @@ namespace Wox.Plugin.Folder
|
|||||||
Title = item.Nickname,
|
Title = item.Nickname,
|
||||||
IcoPath = item.Path,
|
IcoPath = item.Path,
|
||||||
SubTitle = "Ctrl + Enter to open the directory",
|
SubTitle = "Ctrl + Enter to open the directory",
|
||||||
|
TitleHighlightData = StringMatcher.FuzzySearch(item.Nickname, search).MatchData,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
if (c.SpecialKeyState.CtrlPressed)
|
if (c.SpecialKeyState.CtrlPressed)
|
||||||
@ -148,6 +150,8 @@ namespace Wox.Plugin.Folder
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
string searchNickname = new FolderLink { Path = query.Search }.Nickname;
|
||||||
|
|
||||||
//Add children directories
|
//Add children directories
|
||||||
DirectoryInfo[] dirs = new DirectoryInfo(search).GetDirectories();
|
DirectoryInfo[] dirs = new DirectoryInfo(search).GetDirectories();
|
||||||
foreach (DirectoryInfo dir in dirs)
|
foreach (DirectoryInfo dir in dirs)
|
||||||
@ -162,6 +166,7 @@ namespace Wox.Plugin.Folder
|
|||||||
Title = dir.Name,
|
Title = dir.Name,
|
||||||
IcoPath = dir.FullName,
|
IcoPath = dir.FullName,
|
||||||
SubTitle = "Ctrl + Enter to open the directory",
|
SubTitle = "Ctrl + Enter to open the directory",
|
||||||
|
TitleHighlightData = StringMatcher.FuzzySearch(dir.Name, searchNickname).MatchData,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
if (c.SpecialKeyState.CtrlPressed)
|
if (c.SpecialKeyState.CtrlPressed)
|
||||||
@ -197,6 +202,7 @@ namespace Wox.Plugin.Folder
|
|||||||
{
|
{
|
||||||
Title = Path.GetFileName(filePath),
|
Title = Path.GetFileName(filePath),
|
||||||
IcoPath = filePath,
|
IcoPath = filePath,
|
||||||
|
TitleHighlightData = StringMatcher.FuzzySearch(file.Name, searchNickname).MatchData,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -8,6 +8,7 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Http;
|
using Wox.Infrastructure.Http;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
|
|
||||||
@ -142,6 +143,8 @@ namespace Wox.Plugin.PluginManagement
|
|||||||
Title = r.name,
|
Title = r.name,
|
||||||
SubTitle = r.description,
|
SubTitle = r.description,
|
||||||
IcoPath = "Images\\plugin.png",
|
IcoPath = "Images\\plugin.png",
|
||||||
|
TitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, r.name).MatchData,
|
||||||
|
SubTitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, r.description).MatchData,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
MessageBoxResult result = MessageBox.Show("Are you sure you wish to install the \'" + r.name + "\' plugin",
|
MessageBoxResult result = MessageBox.Show("Are you sure you wish to install the \'" + r.name + "\' plugin",
|
||||||
@ -191,6 +194,8 @@ namespace Wox.Plugin.PluginManagement
|
|||||||
Title = plugin.Name,
|
Title = plugin.Name,
|
||||||
SubTitle = plugin.Description,
|
SubTitle = plugin.Description,
|
||||||
IcoPath = plugin.IcoPath,
|
IcoPath = plugin.IcoPath,
|
||||||
|
TitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, plugin.Name).MatchData,
|
||||||
|
SubTitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, plugin.Description).MatchData,
|
||||||
Action = e =>
|
Action = e =>
|
||||||
{
|
{
|
||||||
UnInstallPlugin(plugin);
|
UnInstallPlugin(plugin);
|
||||||
|
@ -35,7 +35,6 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
|
|
||||||
public UWP(Package package)
|
public UWP(Package package)
|
||||||
{
|
{
|
||||||
|
|
||||||
Location = package.InstalledLocation.Path;
|
Location = package.InstalledLocation.Path;
|
||||||
Name = package.Id.Name;
|
Name = package.Id.Name;
|
||||||
FullName = package.Id.FullName;
|
FullName = package.Id.FullName;
|
||||||
@ -266,11 +265,9 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
|
|
||||||
private int Score(string query)
|
private int Score(string query)
|
||||||
{
|
{
|
||||||
var score1 = StringMatcher.FuzzySearch(query, DisplayName).ScoreAfterSearchPrecisionFilter();
|
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
|
||||||
var score2 = StringMatcher.ScoreForPinyin(DisplayName, query);
|
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||||
var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
|
var score = new[] { displayNameMatch.Score, descriptionMatch.Score }.Max();
|
||||||
var score4 = StringMatcher.ScoreForPinyin(Description, query);
|
|
||||||
var score = new[] { score1, score2, score3, score4 }.Max();
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,14 +290,17 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
Description.Substring(0, DisplayName.Length) == DisplayName)
|
Description.Substring(0, DisplayName.Length) == DisplayName)
|
||||||
{
|
{
|
||||||
result.Title = Description;
|
result.Title = Description;
|
||||||
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(Description))
|
else if (!string.IsNullOrEmpty(Description))
|
||||||
{
|
{
|
||||||
result.Title = $"{DisplayName}: {Description}";
|
result.Title = $"{DisplayName}: {Description}";
|
||||||
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Title = DisplayName;
|
result.Title = DisplayName;
|
||||||
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,10 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
|
|
||||||
private int Score(string query)
|
private int Score(string query)
|
||||||
{
|
{
|
||||||
var score1 = StringMatcher.FuzzySearch(query, Name).ScoreAfterSearchPrecisionFilter();
|
var nameMatch = StringMatcher.FuzzySearch(query, Name);
|
||||||
var score2 = StringMatcher.ScoreForPinyin(Name, query);
|
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
|
||||||
var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
|
var executableNameMatch = StringMatcher.FuzzySearch(query, ExecutableName);
|
||||||
var score4 = StringMatcher.ScoreForPinyin(Description, query);
|
var score = new[] { nameMatch.Score, descriptionMatch.Score, executableNameMatch.Score }.Max();
|
||||||
var score5 = StringMatcher.FuzzySearch(query, ExecutableName).ScoreAfterSearchPrecisionFilter();
|
|
||||||
var score = new[] { score1, score2, score3, score4, score5 }.Max();
|
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +65,17 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
Description.Substring(0, Name.Length) == Name)
|
Description.Substring(0, Name.Length) == Name)
|
||||||
{
|
{
|
||||||
result.Title = Description;
|
result.Title = Description;
|
||||||
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(Description))
|
else if (!string.IsNullOrEmpty(Description))
|
||||||
{
|
{
|
||||||
result.Title = $"{Name}: {Description}";
|
result.Title = $"{Name}: {Description}";
|
||||||
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.Title = Name;
|
result.Title = Name;
|
||||||
|
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -56,12 +56,21 @@ namespace Wox.Plugin.Sys
|
|||||||
var results = new List<Result>();
|
var results = new List<Result>();
|
||||||
foreach (var c in commands)
|
foreach (var c in commands)
|
||||||
{
|
{
|
||||||
var titleScore = StringMatcher.FuzzySearch(query.Search, c.Title).ScoreAfterSearchPrecisionFilter();
|
var titleMatch = StringMatcher.FuzzySearch(query.Search, c.Title);
|
||||||
var subTitleScore = StringMatcher.FuzzySearch(query.Search, c.SubTitle).ScoreAfterSearchPrecisionFilter();
|
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, c.SubTitle);
|
||||||
var score = Math.Max(titleScore, subTitleScore);
|
|
||||||
|
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
|
||||||
if (score > 0)
|
if (score > 0)
|
||||||
{
|
{
|
||||||
c.Score = score;
|
c.Score = score;
|
||||||
|
if (score == titleMatch.Score)
|
||||||
|
{
|
||||||
|
c.TitleHighlightData = titleMatch.MatchData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c.SubTitleHighlightData = subTitleMatch.MatchData;
|
||||||
|
}
|
||||||
results.Add(c);
|
results.Add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user