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:
AT
2019-10-20 22:15:24 +03:00
parent a3ba2276e2
commit 8ee8f2c085
19 changed files with 149 additions and 26 deletions

View File

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