diff --git a/Plugins/Wox.Plugin.Program/AddProgramSource.xaml b/Plugins/Wox.Plugin.Program/AddProgramSource.xaml new file mode 100644 index 0000000000..4819a2f18d --- /dev/null +++ b/Plugins/Wox.Plugin.Program/AddProgramSource.xaml @@ -0,0 +1,27 @@ + + + + @@ -21,13 +25,27 @@ Drop="programSourceView_Drop" > - + + + + + + + + + + + + + + + diff --git a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs index 3037997dfa..3d4b50a89b 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs @@ -22,6 +22,8 @@ namespace Wox.Plugin.Program private void Setting_Loaded(object sender, RoutedEventArgs e) { programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources; + StartMenuEnabled.IsChecked = ProgramStorage.Instance.EnableStartMenuSource; + RegistryEnabled.IsChecked = ProgramStorage.Instance.EnableRegistrySource; } private void ReIndexing() @@ -37,19 +39,10 @@ namespace Wox.Plugin.Program private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e) { - var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); - if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + var add = new AddProgramSource(); + if(add.ShowDialog() ?? false) { - string path = folderBrowserDialog.SelectedPath; - - ProgramStorage.Instance.ProgramSources.Add(new ProgramSource() - { - Location = path, - Type = "FileSystemProgramSource", - Enabled = true - }); - ProgramStorage.Instance.Save(); - ReIndexing(); + this.ReIndexing(); } } @@ -79,14 +72,10 @@ namespace Wox.Plugin.Program ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource; if (selectedProgramSource != null) { - //todo: update - var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); - if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + var add = new AddProgramSource(selectedProgramSource); + if (add.ShowDialog() ?? false) { - string path = folderBrowserDialog.SelectedPath; - selectedProgramSource.Location = path; - ProgramStorage.Instance.Save(); - ReIndexing(); + this.ReIndexing(); } } else @@ -142,5 +131,19 @@ namespace Wox.Plugin.Program } } } + + private void StartMenuEnabled_Click(object sender, RoutedEventArgs e) + { + ProgramStorage.Instance.EnableStartMenuSource = StartMenuEnabled.IsChecked ?? false; + ProgramStorage.Instance.Save(); + ReIndexing(); + } + + private void RegistryEnabled_Click(object sender, RoutedEventArgs e) + { + ProgramStorage.Instance.EnableRegistrySource = RegistryEnabled.IsChecked ?? false; + ProgramStorage.Instance.Save(); + ReIndexing(); + } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSource.cs index 99548b89e0..97a779d969 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSource.cs @@ -10,6 +10,8 @@ namespace Wox.Plugin.Program public string Type { get; set; } public int BonusPoints { get; set; } public bool Enabled { get; set; } + public string Suffixes { get; set; } + public int MaxDepth { get; set; } public Dictionary Meta { get; set; } public override string ToString() diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs index f4997615e8..b1ef2dcd4c 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs @@ -10,14 +10,21 @@ namespace Wox.Plugin.Program.ProgramSources public class FileSystemProgramSource : AbstractProgramSource { private string baseDirectory; + private int maxDepth; + private string suffixes; - public FileSystemProgramSource(string baseDirectory) + public FileSystemProgramSource(string baseDirectory, int maxDepth, string suffixes) { this.baseDirectory = baseDirectory; + this.maxDepth = maxDepth; + this.suffixes = suffixes; } + public FileSystemProgramSource(string baseDirectory) + : this(baseDirectory, -1, "") {} + public FileSystemProgramSource(ProgramSource source) - : this(source.Location) + : this(source.Location, source.MaxDepth, source.Suffixes) { this.BonusPoints = source.BonusPoints; } @@ -35,11 +42,21 @@ namespace Wox.Plugin.Program.ProgramSources private void GetAppFromDirectory(string path, List list) { + GetAppFromDirectory(path, list, 0); + } + + private void GetAppFromDirectory(string path, List list, int depth) + { + if(maxDepth != -1 && depth > maxDepth) + { + return; + } try { foreach (string file in Directory.GetFiles(path)) { - if (ProgramStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o))) + if (ProgramStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)) || + suffixes.Split(';').Any(o => file.EndsWith("." + o))) { Program p = CreateEntry(file); list.Add(p); @@ -48,7 +65,7 @@ namespace Wox.Plugin.Program.ProgramSources foreach (var subDirectory in Directory.GetDirectories(path)) { - GetAppFromDirectory(subDirectory, list); + GetAppFromDirectory(subDirectory, list, depth + 1); } } catch (Exception e) diff --git a/Plugins/Wox.Plugin.Program/ProgramStorage.cs b/Plugins/Wox.Plugin.Program/ProgramStorage.cs index d6607c768c..a274237f87 100644 --- a/Plugins/Wox.Plugin.Program/ProgramStorage.cs +++ b/Plugins/Wox.Plugin.Program/ProgramStorage.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Text; using Newtonsoft.Json; using Wox.Infrastructure.Storage; +using System.ComponentModel; namespace Wox.Plugin.Program { @@ -17,6 +18,14 @@ namespace Wox.Plugin.Program [JsonProperty] public string ProgramSuffixes { get; set; } + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + [DefaultValue(true)] + public bool EnableStartMenuSource { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] + [DefaultValue(true)] + public bool EnableRegistrySource { get; set; } + protected override string ConfigFolder { get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } @@ -25,6 +34,8 @@ namespace Wox.Plugin.Program protected override ProgramStorage LoadDefault() { ProgramSources = new List(); + EnableStartMenuSource = true; + EnableRegistrySource = true; return this; } diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index fad46efa3f..d6a3a35183 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -28,6 +28,7 @@ namespace Wox.Plugin.Program public List Query(Query query) { + var fuzzyMather = FuzzyMatcher.Create(query.Search); List returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList(); returnList.ForEach(ScoreFilter); @@ -97,11 +98,11 @@ namespace Wox.Plugin.Program if (ProgramStorage.Instance.ProgramSources != null && ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0) { - programSources.AddRange(ProgramStorage.Instance.ProgramSources.Where(o => o.Enabled)); + programSources.AddRange(ProgramStorage.Instance.ProgramSources); } sources.Clear(); - programSources.ForEach(source => + foreach(var source in programSources.Where(o => o.Enabled)) { Type sourceClass; if (SourceTypes.TryGetValue(source.Type, out sourceClass)) @@ -114,7 +115,7 @@ namespace Wox.Plugin.Program sources.Add(programSource); } } - }); + } var tempPrograms = new List(); foreach (var source in sources) @@ -145,19 +146,19 @@ namespace Wox.Plugin.Program list.Add(new ProgramSource() { BonusPoints = 0, - Enabled = true, + Enabled = ProgramStorage.Instance.EnableStartMenuSource, Type = "CommonStartMenuProgramSource" }); list.Add(new ProgramSource() { BonusPoints = 0, - Enabled = true, + Enabled = ProgramStorage.Instance.EnableStartMenuSource, Type = "UserStartMenuProgramSource" }); list.Add(new ProgramSource() { BonusPoints = -10, - Enabled = true, + Enabled = ProgramStorage.Instance.EnableRegistrySource, Type = "AppPathsProgramSource" }); return list; diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 0f357736f1..70e612ac2a 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -1,153 +1,156 @@ - - - - - Debug - AnyCPU - {FDB3555B-58EF-4AE6-B5F1-904719637AB4} - Library - Properties - Wox.Plugin.Program - Wox.Plugin.Program - v3.5 - 512 - ..\..\ - true - - - - true - full - false - ..\..\Output\Debug\Plugins\Wox.Plugin.Program\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - ..\..\Output\Release\Plugins\Wox.Plugin.Program\ - TRACE - prompt - 4 - false - - - - False - ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - ProgramSetting.xaml - - - - - - - - - ProgramSuffixes.xaml - - - - - - - - PreserveNewest - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} - Wox.Infrastructure - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} - Wox.Plugin - - - - - {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} - 1 - 0 - 0 - tlbimp - False - True - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - + + + + + Debug + AnyCPU + {FDB3555B-58EF-4AE6-B5F1-904719637AB4} + Library + Properties + Wox.Plugin.Program + Wox.Plugin.Program + v3.5 + 512 + ..\..\ + true + + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.Program\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.Program\ + TRACE + prompt + 4 + false + + + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + AddProgramSource.xaml + + + + + + + + ProgramSetting.xaml + + + + + + + + + ProgramSuffixes.xaml + + + + + + + + PreserveNewest + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + True + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + --> \ No newline at end of file