From a89b2ca45023bd16264ed903d6b4ad61d6f91ef3 Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Mon, 14 Oct 2019 14:22:20 +0300 Subject: [PATCH 1/8] remove the need for windows SDK --- Plugins/Wox.Plugin.Program/Main.cs | 28 ++++++++++++++++++---- Plugins/Wox.Plugin.Program/Programs/UWP.cs | 6 +++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index a6a891265a..9fb69bf7fb 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -17,12 +17,15 @@ namespace Wox.Plugin.Program { private static readonly object IndexLock = new object(); private static Win32[] _win32s; +#if SDK private static UWP.Application[] _uwps; + private static BinaryStorage _uwpStorage; +#endif private static PluginInitContext _context; private static BinaryStorage _win32Storage; - private static BinaryStorage _uwpStorage; + private static Settings _settings; private readonly PluginJsonStorage _settingsStorage; @@ -35,11 +38,15 @@ namespace Wox.Plugin.Program { _win32Storage = new BinaryStorage("Win32"); _win32s = _win32Storage.TryLoad(new Win32[] { }); +#if SDK _uwpStorage = new BinaryStorage("UWP"); _uwps = _uwpStorage.TryLoad(new UWP.Application[] { }); +#endif }); Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>"); +#if SDK Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); +#endif Task.Run(() => { Stopwatch.Normal("|Wox.Plugin.Program.Main|Program index cost", IndexPrograms); @@ -50,7 +57,9 @@ namespace Wox.Plugin.Program { _settingsStorage.Save(); _win32Storage.Save(_win32s); +#if SDK _uwpStorage.Save(_uwps); +#endif } public List Query(Query query) @@ -58,8 +67,14 @@ namespace Wox.Plugin.Program lock (IndexLock) { var results1 = _win32s.AsParallel().Select(p => p.Result(query.Search, _context.API)); +#if SDK var results2 = _uwps.AsParallel().Select(p => p.Result(query.Search, _context.API)); - var result = results1.Concat(results2).Where(r => r.Score > 0).ToList(); +#endif + var result = results1 +#if SDK + .Concat(results2) +#endif + .Where(r => r.Score > 0).ToList(); return result; } } @@ -72,10 +87,13 @@ namespace Wox.Plugin.Program public static void IndexPrograms() { Win32[] w = { }; +#if SDK UWP.Application[] u = { }; var t1 = Task.Run(() => { - w = Win32.All(_settings); +#endif + w = Win32.All(_settings); +#if SDK }); var t2 = Task.Run(() => { @@ -91,11 +109,13 @@ namespace Wox.Plugin.Program } }); Task.WaitAll(t1, t2); - +#endif lock (IndexLock) { _win32s = w; +#if SDK _uwps = u; +#endif } } diff --git a/Plugins/Wox.Plugin.Program/Programs/UWP.cs b/Plugins/Wox.Plugin.Program/Programs/UWP.cs index d5f72683f0..82b15738f5 100644 --- a/Plugins/Wox.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Wox.Plugin.Program/Programs/UWP.cs @@ -1,4 +1,5 @@ -using System; +#if SDK +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -583,4 +584,5 @@ namespace Wox.Plugin.Program.Programs private static extern Hresult SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved); } -} \ No newline at end of file +} +#endif \ No newline at end of file From e1f2bc0a19c7a7aad5e07692abc25a2c0ffda7f6 Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Thu, 17 Oct 2019 12:19:52 +0300 Subject: [PATCH 2/8] for unit tetsing --- Wox.Core/Plugin/PluginManager.cs | 2 +- Wox.Plugin/Query.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index e42cf02e80..d6806e5cb2 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -135,7 +135,7 @@ namespace Wox.Core.Plugin var rawQuery = string.Join(Query.TermSeperater, terms); var actionKeyword = string.Empty; var search = rawQuery; - List actionParameters = terms.ToList(); + var actionParameters = terms.ToList(); if (terms.Length == 0) return null; if (NonGlobalPlugins.ContainsKey(terms[0]) && !Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled) diff --git a/Wox.Plugin/Query.cs b/Wox.Plugin/Query.cs index 400ae741f1..4289f0497d 100644 --- a/Wox.Plugin/Query.cs +++ b/Wox.Plugin/Query.cs @@ -6,6 +6,19 @@ namespace Wox.Plugin { public class Query { + internal Query() { } + + /// + /// to allow unit tests for plug ins + /// + public Query(string rawQuery, string search, string[] terms, string actionKeyword = null) + { + Search = search; + RawQuery = rawQuery; + Terms = terms; + ActionKeyword = actionKeyword; + } + /// /// Raw query, this includes action keyword if it has /// We didn't recommend use this property directly. You should always use Search property. From e6f17834a0ee2c2a9143daa4ce11ded914bd175a Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Thu, 17 Oct 2019 12:21:57 +0300 Subject: [PATCH 3/8] added sdk const by default --- Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 322a873508..350ae4dd9e 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -21,7 +21,7 @@ full false ..\..\Output\Debug\Plugins\Wox.Plugin.Program\ - DEBUG;TRACE + TRACE;DEBUG;SDK prompt 4 false From 31916384c1e269b6d018e5f25d9ff08c5f8ead48 Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Thu, 17 Oct 2019 13:11:23 +0300 Subject: [PATCH 4/8] update query defualt to string empty instead of null and update result plugin id to be internal --- Wox.Plugin/Query.cs | 2 +- Wox.Plugin/Result.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Wox.Plugin/Query.cs b/Wox.Plugin/Query.cs index 4289f0497d..07b640ab85 100644 --- a/Wox.Plugin/Query.cs +++ b/Wox.Plugin/Query.cs @@ -11,7 +11,7 @@ namespace Wox.Plugin /// /// to allow unit tests for plug ins /// - public Query(string rawQuery, string search, string[] terms, string actionKeyword = null) + public Query(string rawQuery, string search, string[] terms, string actionKeyword = "") { Search = search; RawQuery = rawQuery; diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 88b8679f24..2f74591703 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -110,6 +110,6 @@ namespace Wox.Plugin /// /// Plugin ID that generate this result /// - public string PluginID { get; set; } + public string PluginID { get; internal set; } } } \ No newline at end of file From 0e241a0fc5b0698dea6f71bbb148440ff7ec8c38 Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Thu, 17 Oct 2019 13:37:09 +0300 Subject: [PATCH 5/8] added empty match option --- .../Commands/Bookmarks.cs | 6 +++--- Wox.Infrastructure/FuzzyMatcher.cs | 2 +- Wox.Infrastructure/StringMatcher.cs | 21 +++++++++++-------- Wox.Test/FuzzyMatcherTest.cs | 10 ++++----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs b/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs index 778e0ee65b..049b8f1668 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs +++ b/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs @@ -8,9 +8,9 @@ namespace Wox.Plugin.BrowserBookmark.Commands { internal static bool MatchProgram(Bookmark bookmark, string queryString) { - if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true; - if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true; - if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true; + if (StringMatcher.FuzzySearch(queryString, bookmark.Name).IsSearchPrecisionScoreMet()) return true; + if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName).IsSearchPrecisionScoreMet()) return true; + if (StringMatcher.FuzzySearch(queryString, bookmark.Url).IsSearchPrecisionScoreMet()) return true; return false; } diff --git a/Wox.Infrastructure/FuzzyMatcher.cs b/Wox.Infrastructure/FuzzyMatcher.cs index cb1e735f5c..461f20ed56 100644 --- a/Wox.Infrastructure/FuzzyMatcher.cs +++ b/Wox.Infrastructure/FuzzyMatcher.cs @@ -16,7 +16,7 @@ namespace Wox.Infrastructure public static FuzzyMatcher Create(string query) { - return new FuzzyMatcher(query, new MatchOption()); + return new FuzzyMatcher(query, StringMatcher.EmptyMatchOption); } public static FuzzyMatcher Create(string query, MatchOption opt) diff --git a/Wox.Infrastructure/StringMatcher.cs b/Wox.Infrastructure/StringMatcher.cs index 0f2657a49a..ec1df0f03a 100644 --- a/Wox.Infrastructure/StringMatcher.cs +++ b/Wox.Infrastructure/StringMatcher.cs @@ -8,6 +8,8 @@ namespace Wox.Infrastructure { public static class StringMatcher { + public static MatchOption EmptyMatchOption = new MatchOption(); + public static string UserSettingSearchPrecision { get; set; } [Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")] @@ -15,7 +17,7 @@ namespace Wox.Infrastructure { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { - return FuzzySearch(target, source, new MatchOption()).Score; + return FuzzySearch(target, source, EmptyMatchOption).Score; } else { @@ -26,12 +28,12 @@ namespace Wox.Infrastructure [Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")] public static bool IsMatch(string source, string target) { - return FuzzySearch(target, source, new MatchOption()).Score > 0; + return FuzzySearch(target, source, EmptyMatchOption).Score > 0; } public static MatchResult FuzzySearch(string query, string stringToCompare) { - return FuzzySearch(query, stringToCompare, new MatchOption()); + return FuzzySearch(query, stringToCompare, EmptyMatchOption); } /// @@ -41,7 +43,7 @@ namespace Wox.Infrastructure { if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult { Success = false }; - query.Trim(); + query = query.Trim(); var len = stringToCompare.Length; var compareString = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare; @@ -98,9 +100,9 @@ namespace Wox.Infrastructure var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1)); //a match with less characters assigning more weights if (stringToCompare.Length - query.Length < 5) - score = score + 20; + score += 20; else if (stringToCompare.Length - query.Length < 10) - score = score + 10; + score += 10; return score; } @@ -139,10 +141,10 @@ namespace Wox.Infrastructure { var combination = Alphabet.PinyinComination(source); var pinyinScore = combination - .Select(pinyin => FuzzySearch(target, string.Join("", pinyin), new MatchOption()).Score) + .Select(pinyin => FuzzySearch(target, string.Join("", pinyin)).Score) .Max(); var acronymScore = combination.Select(Alphabet.Acronym) - .Select(pinyin => FuzzySearch(target, pinyin, new MatchOption()).Score) + .Select(pinyin => FuzzySearch(target, pinyin).Score) .Max(); var score = Math.Max(pinyinScore, acronymScore); return score; @@ -163,8 +165,9 @@ namespace Wox.Infrastructure { public bool Success { get; set; } public int Score { get; set; } + /// - /// hightlight string + /// highlight string /// public string Value { get; set; } } diff --git a/Wox.Test/FuzzyMatcherTest.cs b/Wox.Test/FuzzyMatcherTest.cs index 9aeca05348..ce1746a3a3 100644 --- a/Wox.Test/FuzzyMatcherTest.cs +++ b/Wox.Test/FuzzyMatcherTest.cs @@ -55,7 +55,7 @@ namespace Wox.Test results.Add(new Result { Title = str, - Score = StringMatcher.FuzzySearch("inst", str, new MatchOption()).Score + Score = StringMatcher.FuzzySearch("inst", str).Score }); } @@ -72,7 +72,7 @@ namespace Wox.Test { var compareString = "Can have rum only in my glass"; - var scoreResult = StringMatcher.FuzzySearch(searchString, compareString, new MatchOption()).Score; + var scoreResult = StringMatcher.FuzzySearch(searchString, compareString).Score; Assert.True(scoreResult == 0); } @@ -92,7 +92,7 @@ namespace Wox.Test results.Add(new Result { Title = str, - Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score + Score = StringMatcher.FuzzySearch(searchTerm, str).Score }); } @@ -135,7 +135,7 @@ namespace Wox.Test results.Add(new Result { Title = str, - Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score + Score = StringMatcher.FuzzySearch(searchTerm, str).Score }); } @@ -173,7 +173,7 @@ namespace Wox.Test { var expectedPrecisionString = (StringMatcher.SearchPrecisionScore)expectedPrecisionScore; StringMatcher.UserSettingSearchPrecision = expectedPrecisionString.ToString(); - var matchResult = StringMatcher.FuzzySearch(queryString, compareString, new MatchOption()); + var matchResult = StringMatcher.FuzzySearch(queryString, compareString); Debug.WriteLine(""); Debug.WriteLine("###############################################"); From aefc90dc192513af115853393eb8b17cd674d1dd Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Sun, 20 Oct 2019 15:43:50 +0300 Subject: [PATCH 6/8] revert the change so you need declare an IGNORE_UWP in order to not use the windwos SDK --- Plugins/Wox.Plugin.Program/Main.cs | 18 +++++++++--------- Plugins/Wox.Plugin.Program/Programs/UWP.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index 9fb69bf7fb..f842bfdbc0 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -17,7 +17,7 @@ namespace Wox.Plugin.Program { private static readonly object IndexLock = new object(); private static Win32[] _win32s; -#if SDK +#if !IGNORE_UWP private static UWP.Application[] _uwps; private static BinaryStorage _uwpStorage; #endif @@ -38,13 +38,13 @@ namespace Wox.Plugin.Program { _win32Storage = new BinaryStorage("Win32"); _win32s = _win32Storage.TryLoad(new Win32[] { }); -#if SDK +#if !IGNORE_UWP _uwpStorage = new BinaryStorage("UWP"); _uwps = _uwpStorage.TryLoad(new UWP.Application[] { }); #endif }); Log.Info($"|Wox.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>"); -#if SDK +#if !IGNORE_UWP Log.Info($"|Wox.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); #endif Task.Run(() => @@ -57,7 +57,7 @@ namespace Wox.Plugin.Program { _settingsStorage.Save(); _win32Storage.Save(_win32s); -#if SDK +#if !IGNORE_UWP _uwpStorage.Save(_uwps); #endif } @@ -67,11 +67,11 @@ namespace Wox.Plugin.Program lock (IndexLock) { var results1 = _win32s.AsParallel().Select(p => p.Result(query.Search, _context.API)); -#if SDK +#if !IGNORE_UWP var results2 = _uwps.AsParallel().Select(p => p.Result(query.Search, _context.API)); #endif var result = results1 -#if SDK +#if !IGNORE_UWP .Concat(results2) #endif .Where(r => r.Score > 0).ToList(); @@ -87,13 +87,13 @@ namespace Wox.Plugin.Program public static void IndexPrograms() { Win32[] w = { }; -#if SDK +#if !IGNORE_UWP UWP.Application[] u = { }; var t1 = Task.Run(() => { #endif w = Win32.All(_settings); -#if SDK +#if !IGNORE_UWP }); var t2 = Task.Run(() => { @@ -113,7 +113,7 @@ namespace Wox.Plugin.Program lock (IndexLock) { _win32s = w; -#if SDK +#if !IGNORE_UWP _uwps = u; #endif } diff --git a/Plugins/Wox.Plugin.Program/Programs/UWP.cs b/Plugins/Wox.Plugin.Program/Programs/UWP.cs index 82b15738f5..e2104fcb0b 100644 --- a/Plugins/Wox.Plugin.Program/Programs/UWP.cs +++ b/Plugins/Wox.Plugin.Program/Programs/UWP.cs @@ -1,4 +1,4 @@ -#if SDK +#if !IGNORE_UWP using System; using System.Collections.Generic; using System.Diagnostics; From a3ba2276e23e7208c120d6d63707e1a5f818c36e Mon Sep 17 00:00:00 2001 From: Amir Tepper Date: Sun, 20 Oct 2019 15:45:06 +0300 Subject: [PATCH 7/8] renamed for Defualt match option --- Wox.Infrastructure/FuzzyMatcher.cs | 2 +- Wox.Infrastructure/StringMatcher.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Wox.Infrastructure/FuzzyMatcher.cs b/Wox.Infrastructure/FuzzyMatcher.cs index 461f20ed56..ddd26be832 100644 --- a/Wox.Infrastructure/FuzzyMatcher.cs +++ b/Wox.Infrastructure/FuzzyMatcher.cs @@ -16,7 +16,7 @@ namespace Wox.Infrastructure public static FuzzyMatcher Create(string query) { - return new FuzzyMatcher(query, StringMatcher.EmptyMatchOption); + return new FuzzyMatcher(query, StringMatcher.DefaultMatchOption); } public static FuzzyMatcher Create(string query, MatchOption opt) diff --git a/Wox.Infrastructure/StringMatcher.cs b/Wox.Infrastructure/StringMatcher.cs index ec1df0f03a..9c49b4119b 100644 --- a/Wox.Infrastructure/StringMatcher.cs +++ b/Wox.Infrastructure/StringMatcher.cs @@ -8,7 +8,7 @@ namespace Wox.Infrastructure { public static class StringMatcher { - public static MatchOption EmptyMatchOption = new MatchOption(); + public static MatchOption DefaultMatchOption = new MatchOption(); public static string UserSettingSearchPrecision { get; set; } @@ -17,7 +17,7 @@ namespace Wox.Infrastructure { if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target)) { - return FuzzySearch(target, source, EmptyMatchOption).Score; + return FuzzySearch(target, source, DefaultMatchOption).Score; } else { @@ -28,12 +28,12 @@ namespace Wox.Infrastructure [Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")] public static bool IsMatch(string source, string target) { - return FuzzySearch(target, source, EmptyMatchOption).Score > 0; + return FuzzySearch(target, source, DefaultMatchOption).Score > 0; } public static MatchResult FuzzySearch(string query, string stringToCompare) { - return FuzzySearch(query, stringToCompare, EmptyMatchOption); + return FuzzySearch(query, stringToCompare, DefaultMatchOption); } /// From 8ee8f2c08518a4b2107b397f0119fb1f1edf1d58 Mon Sep 17 00:00:00 2001 From: AT Date: Sun, 20 Oct 2019 22:15:24 +0300 Subject: [PATCH 8/8] 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) --- .../ControlPanelSettingsView.xaml | 12 +++++++ .../ControlPanelSettingsView.xaml.cs | 29 +++++++++++++++++ .../ControlPanelSettingsViewModel.cs | 22 +++++++++++++ Plugins/Wox.Plugin.ControlPanel/Main.cs | 31 ++++++++++++++++--- Plugins/Wox.Plugin.ControlPanel/Settings.cs | 7 +++++ .../Wox.Plugin.ControlPanel.csproj | 14 +++++++++ Plugins/Wox.Plugin.Program/Languages/de.xaml | 1 + Plugins/Wox.Plugin.Program/Languages/en.xaml | 2 ++ Plugins/Wox.Plugin.Program/Languages/pl.xaml | 1 + Plugins/Wox.Plugin.Program/Languages/tr.xaml | 1 + .../Wox.Plugin.Program/Languages/zh-cn.xaml | 1 + .../Wox.Plugin.Program/Languages/zh-tw.xaml | 1 + Plugins/Wox.Plugin.Program/Main.cs | 10 +++--- .../Wox.Plugin.Program/ProgramSetting.xaml | 3 +- .../Wox.Plugin.Program/ProgramSetting.xaml.cs | 16 +++++++--- .../Wox.Plugin.Program/Programs/IProgram.cs | 2 +- Plugins/Wox.Plugin.Program/Programs/UWP.cs | 10 +++--- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 10 +++--- Plugins/Wox.Plugin.Program/Settings.cs | 2 ++ 19 files changed, 149 insertions(+), 26 deletions(-) create mode 100644 Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml create mode 100644 Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml.cs create mode 100644 Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsViewModel.cs create mode 100644 Plugins/Wox.Plugin.ControlPanel/Settings.cs diff --git a/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml b/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml new file mode 100644 index 0000000000..b846f68de2 --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml.cs b/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml.cs new file mode 100644 index 0000000000..9f09895ed8 --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsView.xaml.cs @@ -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 +{ + /// + /// Interaction logic for ControlPanelSettingsControl.xaml + /// + public partial class ControlPanelSettingsView : UserControl + { + public ControlPanelSettingsView(ControlPanelSettingsViewModel vm) + { + InitializeComponent(); + DataContext = vm; + } + } +} diff --git a/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsViewModel.cs b/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsViewModel.cs new file mode 100644 index 0000000000..cdeebdee8b --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/ControlPanelSettingsViewModel.cs @@ -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(); + } + } + } +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.ControlPanel/Main.cs b/Plugins/Wox.Plugin.ControlPanel/Main.cs index 0e0a8898d6..f082d3f6a3 100644 --- a/Plugins/Wox.Plugin.ControlPanel/Main.cs +++ b/Plugins/Wox.Plugin.ControlPanel/Main.cs @@ -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 _settingsStorage; + private PluginInitContext context; private List controlPanelItems = new List(); private string iconFolder; private string fileType; + public Main() + { + _settingsStorage = new PluginJsonStorage(); + _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 {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(); + } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.ControlPanel/Settings.cs b/Plugins/Wox.Plugin.ControlPanel/Settings.cs new file mode 100644 index 0000000000..7c90afdd92 --- /dev/null +++ b/Plugins/Wox.Plugin.ControlPanel/Settings.cs @@ -0,0 +1,7 @@ +namespace Wox.Plugin.ControlPanel +{ + public class Settings + { + public bool ShouldUsePinYin { get; set; } = true; + } +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj b/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj index 614ea5f652..e764ccce0c 100644 --- a/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj +++ b/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj @@ -37,19 +37,27 @@ ..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll True + + + Properties\SolutionAssemblyInfo.cs + + ControlPanelSettingsView.xaml + + + @@ -114,6 +122,12 @@ PreserveNewest + + + Designer + MSBuild:Compile + +