From dcb9e34d59a6b57afae2c1da0966459a157c9750 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Sat, 16 Nov 2019 00:34:27 +0200 Subject: [PATCH] alphabet settings --- Wox.Infrastructure/Alphabet.cs | 27 ++++++++++++++++++--- Wox.Infrastructure/UserSettings/Settings.cs | 5 ++++ Wox/App.xaml.cs | 3 ++- Wox/Languages/en.xaml | 1 + Wox/SettingWindow.xaml | 3 +++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Wox.Infrastructure/Alphabet.cs b/Wox.Infrastructure/Alphabet.cs index 157d1c9f1f..91979bf526 100644 --- a/Wox.Infrastructure/Alphabet.cs +++ b/Wox.Infrastructure/Alphabet.cs @@ -6,6 +6,7 @@ using hyjiacan.util.p4n; using hyjiacan.util.p4n.format; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage; +using Wox.Infrastructure.UserSettings; namespace Wox.Infrastructure { @@ -14,9 +15,11 @@ namespace Wox.Infrastructure private static readonly HanyuPinyinOutputFormat Format = new HanyuPinyinOutputFormat(); private static ConcurrentDictionary PinyinCache; private static BinaryStorage> _pinyinStorage; + private static Settings _settings; - public static void Initialize() + public static void Initialize(Settings settings) { + _settings = settings; Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () => @@ -34,12 +37,20 @@ namespace Wox.Infrastructure _pinyinStorage.Save(PinyinCache); } + private static string[] EmptyStringArray = new string[0]; + private static string[][] Empty2DStringArray = new string[0][]; + /// /// replace chinese character with pinyin, non chinese character won't be modified /// should be word or sentence, instead of single character. e.g. 微软 /// public static string[] Pinyin(string word) { + if (!_settings.ShouldUsePinyin) + { + return EmptyStringArray; + } + var pinyin = word.Select(c => { var pinyins = PinyinHelper.toHanyuPinyinStringArray(c); @@ -57,7 +68,7 @@ namespace Wox.Infrastructure /// public static string[][] PinyinComination(string characters) { - if (!string.IsNullOrEmpty(characters)) + if (_settings.ShouldUsePinyin && !string.IsNullOrEmpty(characters)) { if (!PinyinCache.ContainsKey(characters)) { @@ -89,7 +100,7 @@ namespace Wox.Infrastructure } else { - return new string[][] { }; + return Empty2DStringArray; } } @@ -101,6 +112,11 @@ namespace Wox.Infrastructure public static bool ContainsChinese(string word) { + if (!_settings.ShouldUsePinyin) + { + return false; + } + var chinese = word.Select(PinyinHelper.toHanyuPinyinStringArray) .Any(p => p != null); return chinese; @@ -108,6 +124,11 @@ namespace Wox.Infrastructure private static string[] Combination(string[] array1, string[] array2) { + if (!_settings.ShouldUsePinyin) + { + return EmptyStringArray; + } + var combination = ( from a1 in array1 from a2 in array2 diff --git a/Wox.Infrastructure/UserSettings/Settings.cs b/Wox.Infrastructure/UserSettings/Settings.cs index 75f4393575..7371ea5d05 100644 --- a/Wox.Infrastructure/UserSettings/Settings.cs +++ b/Wox.Infrastructure/UserSettings/Settings.cs @@ -21,6 +21,11 @@ namespace Wox.Infrastructure.UserSettings public string ResultFontWeight { get; set; } public string ResultFontStretch { get; set; } + /// + /// when false Alphabet static service will always return empty results + /// + public bool ShouldUsePinyin { get; set; } = true; + private string _querySearchPrecision { get; set; } = StringMatcher.SearchPrecisionScore.Regular.ToString(); public string QuerySearchPrecision { diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index b66549b38a..0ec1614bf9 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -49,11 +49,12 @@ namespace Wox RegisterDispatcherUnhandledException(); ImageLoader.Initialize(); - Alphabet.Initialize(); _settingsVM = new SettingWindowViewModel(); _settings = _settingsVM.Settings; + Alphabet.Initialize(_settings); + StringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; PluginManager.LoadPlugins(_settings.PluginSettings); diff --git a/Wox/Languages/en.xaml b/Wox/Languages/en.xaml index ae8041121c..dca044dc11 100644 --- a/Wox/Languages/en.xaml +++ b/Wox/Languages/en.xaml @@ -34,6 +34,7 @@ Hide Wox on startup Hide tray icon Query Search Precision + Should Use Pinyin Plugin diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 86d6a345a9..9a5146c7ee 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -55,6 +55,9 @@ Checked="OnAutoStartupChecked" Unchecked="OnAutoStartupUncheck"> + + +