mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
added the abitliy to opt out of pinyin in control panel and in program plug in - this give a major perf boost (and I'm guessing it is not relevant for most users)
This commit is contained in:
@@ -4,17 +4,28 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.ControlPanel
|
||||
{
|
||||
public class Main : IPlugin, IPluginI18n
|
||||
public class Main : IPlugin, IPluginI18n, ISettingProvider, ISavable
|
||||
{
|
||||
private readonly Settings _settings = new Settings {ShouldUsePinYin = false};
|
||||
private readonly PluginJsonStorage<Settings> _settingsStorage;
|
||||
|
||||
private PluginInitContext context;
|
||||
private List<ControlPanelItem> controlPanelItems = new List<ControlPanelItem>();
|
||||
private string iconFolder;
|
||||
private string fileType;
|
||||
|
||||
public Main()
|
||||
{
|
||||
_settingsStorage = new PluginJsonStorage<Settings>();
|
||||
_settings = _settingsStorage.Load();
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
@@ -43,7 +54,7 @@ namespace Wox.Plugin.ControlPanel
|
||||
|
||||
foreach (var item in controlPanelItems)
|
||||
{
|
||||
item.Score = Score(item, query.Search);
|
||||
item.Score = Score(item, query.Search, _settings.ShouldUsePinYin);
|
||||
if (item.Score > 0)
|
||||
{
|
||||
var result = new Result
|
||||
@@ -74,20 +85,20 @@ namespace Wox.Plugin.ControlPanel
|
||||
return panelItems;
|
||||
}
|
||||
|
||||
private int Score(ControlPanelItem item, string query)
|
||||
private int Score(ControlPanelItem item, string query, bool shouldUsePinYin)
|
||||
{
|
||||
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);
|
||||
var score2 = shouldUsePinYin ? StringMatcher.ScoreForPinyin(item.LocalizedString, query) : 0;
|
||||
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);
|
||||
var score2 = shouldUsePinYin ? StringMatcher.ScoreForPinyin(item.InfoTip, query) : 0;
|
||||
scores.Add(score1);
|
||||
scores.Add(score2);
|
||||
}
|
||||
@@ -103,5 +114,15 @@ namespace Wox.Plugin.ControlPanel
|
||||
{
|
||||
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_description");
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new ControlPanelSettingsView(new ControlPanelSettingsViewModel(_settings));
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_settingsStorage.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user