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

@@ -0,0 +1,12 @@
<UserControl x:Class="Wox.Plugin.ControlPanel.ControlPanelSettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wox.Plugin.ControlPanel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<CheckBox Name="ShouldUsePinYin_checkBox" IsChecked="{Binding ShouldUsePinYin}" Content="Should Use PinYin"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Wox.Plugin.ControlPanel
{
/// <summary>
/// Interaction logic for ControlPanelSettingsControl.xaml
/// </summary>
public partial class ControlPanelSettingsView : UserControl
{
public ControlPanelSettingsView(ControlPanelSettingsViewModel vm)
{
InitializeComponent();
DataContext = vm;
}
}
}

View File

@@ -0,0 +1,22 @@
namespace Wox.Plugin.ControlPanel
{
public class ControlPanelSettingsViewModel : BaseModel
{
private readonly Settings _settings;
public ControlPanelSettingsViewModel(Settings settings)
{
_settings = settings;
}
public bool ShouldUsePinYin
{
get { return _settings.ShouldUsePinYin; }
set
{
_settings.ShouldUsePinYin = value;
this.OnPropertyChanged();
}
}
}
}

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

View File

@@ -0,0 +1,7 @@
namespace Wox.Plugin.ControlPanel
{
public class Settings
{
public bool ShouldUsePinYin { get; set; } = true;
}
}

View File

@@ -37,19 +37,27 @@
<HintPath>..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\SolutionAssemblyInfo.cs">
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ControlPanelSettingsView.xaml.cs">
<DependentUpon>ControlPanelSettingsView.xaml</DependentUpon>
</Compile>
<Compile Include="ControlPanelSettingsViewModel.cs" />
<Compile Include="Main.cs" />
<Compile Include="ControlPanelItem.cs" />
<Compile Include="ControlPanelList.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -114,6 +122,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Page Include="ControlPanelSettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.