Merge pull request #278 from dstiert/program-source-details

Improve configurability of Programs plguin
This commit is contained in:
qianlifeng 2015-05-03 14:25:46 +08:00
commit dcd20f42b9
12 changed files with 419 additions and 234 deletions

View file

@ -0,0 +1,27 @@
<Window x:Class="Wox.Plugin.Program.AddProgramSource"
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"
mc:Ignorable="d"
Width="400"
Height="180"
WindowStartupLocation="CenterScreen"
d:DesignHeight="400" d:DesignWidth="300">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource wox_plugin_program_directory}"/>
<TextBox Name="Directory" VerticalAlignment="Center" Width="238" Margin="0,7" />
<Button Name="BrowseButton" Content="{DynamicResource wox_plugin_program_browse}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="75" Click="BrowseButton_Click" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource wox_plugin_program_file_suffixes}" />
<TextBox x:Name="Suffixes" VerticalAlignment="Center" Width="297" Margin="0,7" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource wox_plugin_program_max_search_depth}" />
<TextBox Name="MaxDepth" Text="-1" VerticalAlignment="Center" Width="146" Margin="0,7" />
</StackPanel>
<Button VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10" Height="20" Width="70" Click="ButtonAdd_OnClick" Content="{DynamicResource wox_plugin_program_update}" />
</StackPanel>
</Window>

View file

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Program
{
/// <summary>
/// Interaction logic for AddProgramSource.xaml
/// </summary>
public partial class AddProgramSource
{
private ProgramSource _editing;
public AddProgramSource()
{
InitializeComponent();
}
public AddProgramSource(ProgramSource edit) : this()
{
this._editing = edit;
this.Directory.Text = this._editing.Location;
this.MaxDepth.Text = this._editing.MaxDepth.ToString();
this.Suffixes.Text = this._editing.Suffixes;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new System.Windows.Forms.FolderBrowserDialog();
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
this.Directory.Text = dialog.SelectedPath;
}
}
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
{
int max;
if(!int.TryParse(this.MaxDepth.Text, out max))
{
max = -1;
}
if(this._editing == null)
{
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
{
Location = this.Directory.Text,
MaxDepth = max,
Suffixes = this.Suffixes.Text,
Type = "FileSystemProgramSource",
Enabled = true
});
}
else
{
this._editing.Location = this.Directory.Text;
this._editing.MaxDepth = max;
this._editing.Suffixes = this.Suffixes.Text;
}
ProgramStorage.Instance.Save();
this.DialogResult = true;
this.Close();
}
}
}

View file

@ -10,6 +10,15 @@
<system:String x:Key="wox_plugin_program_suffixes">Index file suffixes</system:String> <system:String x:Key="wox_plugin_program_suffixes">Index file suffixes</system:String>
<system:String x:Key="wox_plugin_program_reindex">Reindex</system:String> <system:String x:Key="wox_plugin_program_reindex">Reindex</system:String>
<system:String x:Key="wox_plugin_program_indexing">Indexing</system:String> <system:String x:Key="wox_plugin_program_indexing">Indexing</system:String>
<system:String x:Key="wox_plugin_program_index_start">Index Start Menu</system:String>
<system:String x:Key="wox_plugin_program_index_registry">Index Registry</system:String>
<system:String x:Key="wox_plugin_program_suffixes_header">Suffixes</system:String>
<system:String x:Key="wox_plugin_program_max_depth_header">Max Depth</system:String>
<system:String x:Key="wox_plugin_program_directory">Directory:</system:String>
<system:String x:Key="wox_plugin_program_browse">Browse</system:String>
<system:String x:Key="wox_plugin_program_file_suffixes">File Suffixes:</system:String>
<system:String x:Key="wox_plugin_program_max_search_depth">Maximum Search Depth (-1 is unlimited):</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">Please select a program source</system:String> <system:String x:Key="wox_plugin_program_pls_select_program_source">Please select a program source</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">Are your sure to delete {0}?</system:String> <system:String x:Key="wox_plugin_program_delete_program_source">Are your sure to delete {0}?</system:String>

View file

@ -1,30 +1,38 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"> xmlns:system="clr-namespace:System;assembly=mscorlib">
<!--Program setting--> <!--Program setting-->
<system:String x:Key="wox_plugin_program_delete">删除</system:String> <system:String x:Key="wox_plugin_program_delete">删除</system:String>
<system:String x:Key="wox_plugin_program_edit">编辑</system:String> <system:String x:Key="wox_plugin_program_edit">编辑</system:String>
<system:String x:Key="wox_plugin_program_add">增加</system:String> <system:String x:Key="wox_plugin_program_add">增加</system:String>
<system:String x:Key="wox_plugin_program_location">位置</system:String> <system:String x:Key="wox_plugin_program_location">位置</system:String>
<system:String x:Key="wox_plugin_program_suffixes">索引文件后缀</system:String> <system:String x:Key="wox_plugin_program_suffixes">索引文件后缀</system:String>
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String> <system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String> <system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
<system:String x:Key="wox_plugin_program_index_start">指数开始菜单</system:String>
<system:String x:Key="wox_plugin_program_index_registry">指数注册</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">请先选择一项</system:String> <system:String x:Key="wox_plugin_program_suffixes_header">后缀</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">你确定要删除{0}吗?</system:String> <system:String x:Key="wox_plugin_program_max_depth_header">最大深度</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String> <system:String x:Key="wox_plugin_program_directory">目录</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox仅索引下列后缀的文件</system:String> <system:String x:Key="wox_plugin_program_browse">浏览</system:String>
<system:String x:Key="wox_plugin_program_split_by_tip">(每个后缀以英文状态下的分号分隔)</system:String> <system:String x:Key="wox_plugin_program_file_suffixes">文件后缀</system:String>
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件后缀</system:String> <system:String x:Key="wox_plugin_program_max_search_depth">最大搜索深度(-1是无限的</system:String>
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件后缀不能为空</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">请先选择一项</system:String>
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理员身份运行</system:String> <system:String x:Key="wox_plugin_program_delete_program_source">你确定要删除{0}吗?</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">打开所属文件夹</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String> <system:String x:Key="wox_plugin_program_only_index_tip">Wox仅索引下列后缀的文件</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String> <system:String x:Key="wox_plugin_program_split_by_tip">(每个后缀以英文状态下的分号分隔)</system:String>
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件后缀</system:String>
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件后缀不能为空</system:String>
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理员身份运行</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">打开所属文件夹</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String>
</ResourceDictionary> </ResourceDictionary>

View file

@ -1,29 +1,37 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"> xmlns:system="clr-namespace:System;assembly=mscorlib">
<!--Program setting--> <!--Program setting-->
<system:String x:Key="wox_plugin_program_delete">刪除</system:String> <system:String x:Key="wox_plugin_program_delete">刪除</system:String>
<system:String x:Key="wox_plugin_program_edit">編輯</system:String> <system:String x:Key="wox_plugin_program_edit">編輯</system:String>
<system:String x:Key="wox_plugin_program_add">增加</system:String> <system:String x:Key="wox_plugin_program_add">增加</system:String>
<system:String x:Key="wox_plugin_program_location">位置</system:String> <system:String x:Key="wox_plugin_program_location">位置</system:String>
<system:String x:Key="wox_plugin_program_suffixes">索引文件後綴</system:String> <system:String x:Key="wox_plugin_program_suffixes">索引文件後綴</system:String>
<system:String x:Key="wox_plugin_program_reindex">重新索引</system:String> <system:String x:Key="wox_plugin_program_reindex">重新索引</system:String>
<system:String x:Key="wox_plugin_program_indexing">索引中</system:String> <system:String x:Key="wox_plugin_program_indexing">索引中</system:String>
<system:String x:Key="wox_plugin_program_index_start">指数开始菜单</system:String>
<system:String x:Key="wox_plugin_program_index_registry">指数注册</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">請先選擇一項</system:String> <system:String x:Key="wox_plugin_program_suffixes_header">后缀</system:String>
<system:String x:Key="wox_plugin_program_delete_program_source">你確定要刪除{0}嗎?</system:String> <system:String x:Key="wox_plugin_program_max_depth_header">最大深度</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String> <system:String x:Key="wox_plugin_program_directory">目录</system:String>
<system:String x:Key="wox_plugin_program_only_index_tip">Wox僅索引下列後綴的文件</system:String> <system:String x:Key="wox_plugin_program_browse">浏览</system:String>
<system:String x:Key="wox_plugin_program_split_by_tip">(每個後綴以英文狀態下的分號分隔)</system:String> <system:String x:Key="wox_plugin_program_file_suffixes">文件后缀</system:String>
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件後綴</system:String> <system:String x:Key="wox_plugin_program_max_search_depth">最大搜索深度(-1是无限的</system:String>
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件後綴不能為空</system:String>
<system:String x:Key="wox_plugin_program_pls_select_program_source">請先選擇一項</system:String>
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理員身份運行</system:String> <system:String x:Key="wox_plugin_program_delete_program_source">你確定要刪除{0}嗎?</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">打開所屬文件夾</system:String>
<system:String x:Key="wox_plugin_program_update">更新</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String> <system:String x:Key="wox_plugin_program_only_index_tip">Wox僅索引下列後綴的文件</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String> <system:String x:Key="wox_plugin_program_split_by_tip">(每個後綴以英文狀態下的分號分隔)</system:String>
<system:String x:Key="wox_plugin_program_update_file_suffixes">成功更新索引文件後綴</system:String>
<system:String x:Key="wox_plugin_program_suffixes_cannot_empty">文件後綴不能為空</system:String>
<system:String x:Key="wox_plugin_program_run_as_administrator">以管理員身份運行</system:String>
<system:String x:Key="wox_plugin_program_open_containing_folder">打開所屬文件夾</system:String>
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String>
</ResourceDictionary> </ResourceDictionary>

View file

@ -12,7 +12,11 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Stretch">
<StackPanel Orientation="Vertical" Width="310">
<CheckBox Name="StartMenuEnabled" Click="StartMenuEnabled_Click" Margin="5" Content="{DynamicResource wox_plugin_program_index_start}"></CheckBox>
<CheckBox Name="RegistryEnabled" Click="RegistryEnabled_Click" Margin="5" Content="{DynamicResource wox_plugin_program_index_registry}"></CheckBox>
</StackPanel>
<Button Height="30" HorizontalAlignment="Right" x:Name="btnProgramSuffixes" Width="130" Click="BtnProgramSuffixes_OnClick" Content="{DynamicResource wox_plugin_program_suffixes}"></Button> <Button Height="30" HorizontalAlignment="Right" x:Name="btnProgramSuffixes" Width="130" Click="BtnProgramSuffixes_OnClick" Content="{DynamicResource wox_plugin_program_suffixes}"></Button>
<Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnReindex" Width="100" Click="btnReindex_Click" Content="{DynamicResource wox_plugin_program_reindex}"></Button> <Button Height="30" HorizontalAlignment="Right" Margin="10 0 0 0" x:Name="btnReindex" Width="100" Click="btnReindex_Click" Content="{DynamicResource wox_plugin_program_reindex}"></Button>
</StackPanel> </StackPanel>
@ -21,13 +25,27 @@
Drop="programSourceView_Drop" > Drop="programSourceView_Drop" >
<ListView.View> <ListView.View>
<GridView> <GridView>
<GridViewColumn Header="{DynamicResource wox_plugin_program_location}" Width="400"> <GridViewColumn Header="{DynamicResource wox_plugin_program_location}" Width="250">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/> <TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
<GridViewColumn Header="{DynamicResource wox_plugin_program_suffixes_header}" Width="220">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Suffixes, ConverterParameter=(null), Converter={program:StringEmptyConverter}}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{DynamicResource wox_plugin_program_max_depth_header}" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding MaxDepth, ConverterParameter=(null)}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView> </GridView>
</ListView.View> </ListView.View>
</ListView> </ListView>

View file

@ -22,6 +22,8 @@ namespace Wox.Plugin.Program
private void Setting_Loaded(object sender, RoutedEventArgs e) private void Setting_Loaded(object sender, RoutedEventArgs e)
{ {
programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources; programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources;
StartMenuEnabled.IsChecked = ProgramStorage.Instance.EnableStartMenuSource;
RegistryEnabled.IsChecked = ProgramStorage.Instance.EnableRegistrySource;
} }
private void ReIndexing() private void ReIndexing()
@ -37,19 +39,10 @@ namespace Wox.Plugin.Program
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e) private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{ {
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); var add = new AddProgramSource();
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) if(add.ShowDialog() ?? false)
{ {
string path = folderBrowserDialog.SelectedPath; this.ReIndexing();
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
{
Location = path,
Type = "FileSystemProgramSource",
Enabled = true
});
ProgramStorage.Instance.Save();
ReIndexing();
} }
} }
@ -79,14 +72,10 @@ namespace Wox.Plugin.Program
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource; ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null) if (selectedProgramSource != null)
{ {
//todo: update var add = new AddProgramSource(selectedProgramSource);
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); if (add.ShowDialog() ?? false)
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
string path = folderBrowserDialog.SelectedPath; this.ReIndexing();
selectedProgramSource.Location = path;
ProgramStorage.Instance.Save();
ReIndexing();
} }
} }
else 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();
}
} }
} }

View file

@ -10,6 +10,8 @@ namespace Wox.Plugin.Program
public string Type { get; set; } public string Type { get; set; }
public int BonusPoints { get; set; } public int BonusPoints { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
public string Suffixes { get; set; }
public int MaxDepth { get; set; }
public Dictionary<string, string> Meta { get; set; } public Dictionary<string, string> Meta { get; set; }
public override string ToString() public override string ToString()

View file

@ -10,14 +10,21 @@ namespace Wox.Plugin.Program.ProgramSources
public class FileSystemProgramSource : AbstractProgramSource public class FileSystemProgramSource : AbstractProgramSource
{ {
private string baseDirectory; 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.baseDirectory = baseDirectory;
this.maxDepth = maxDepth;
this.suffixes = suffixes;
} }
public FileSystemProgramSource(string baseDirectory)
: this(baseDirectory, -1, "") {}
public FileSystemProgramSource(ProgramSource source) public FileSystemProgramSource(ProgramSource source)
: this(source.Location) : this(source.Location, source.MaxDepth, source.Suffixes)
{ {
this.BonusPoints = source.BonusPoints; this.BonusPoints = source.BonusPoints;
} }
@ -35,11 +42,21 @@ namespace Wox.Plugin.Program.ProgramSources
private void GetAppFromDirectory(string path, List<Program> list) private void GetAppFromDirectory(string path, List<Program> list)
{ {
GetAppFromDirectory(path, list, 0);
}
private void GetAppFromDirectory(string path, List<Program> list, int depth)
{
if(maxDepth != -1 && depth > maxDepth)
{
return;
}
try try
{ {
foreach (string file in Directory.GetFiles(path)) 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); Program p = CreateEntry(file);
list.Add(p); list.Add(p);
@ -48,7 +65,7 @@ namespace Wox.Plugin.Program.ProgramSources
foreach (var subDirectory in Directory.GetDirectories(path)) foreach (var subDirectory in Directory.GetDirectories(path))
{ {
GetAppFromDirectory(subDirectory, list); GetAppFromDirectory(subDirectory, list, depth + 1);
} }
} }
catch (Exception e) catch (Exception e)

View file

@ -6,6 +6,7 @@ using System.Reflection;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using System.ComponentModel;
namespace Wox.Plugin.Program namespace Wox.Plugin.Program
{ {
@ -17,6 +18,14 @@ namespace Wox.Plugin.Program
[JsonProperty] [JsonProperty]
public string ProgramSuffixes { get; set; } 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 protected override string ConfigFolder
{ {
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
@ -25,6 +34,8 @@ namespace Wox.Plugin.Program
protected override ProgramStorage LoadDefault() protected override ProgramStorage LoadDefault()
{ {
ProgramSources = new List<ProgramSource>(); ProgramSources = new List<ProgramSource>();
EnableStartMenuSource = true;
EnableRegistrySource = true;
return this; return this;
} }

View file

@ -28,6 +28,7 @@ namespace Wox.Plugin.Program
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
var fuzzyMather = FuzzyMatcher.Create(query.Search); var fuzzyMather = FuzzyMatcher.Create(query.Search);
List<Program> returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList(); List<Program> returnList = programs.Where(o => MatchProgram(o, fuzzyMather)).ToList();
returnList.ForEach(ScoreFilter); returnList.ForEach(ScoreFilter);
@ -97,11 +98,11 @@ namespace Wox.Plugin.Program
if (ProgramStorage.Instance.ProgramSources != null && if (ProgramStorage.Instance.ProgramSources != null &&
ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0) ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0)
{ {
programSources.AddRange(ProgramStorage.Instance.ProgramSources.Where(o => o.Enabled)); programSources.AddRange(ProgramStorage.Instance.ProgramSources);
} }
sources.Clear(); sources.Clear();
programSources.ForEach(source => foreach(var source in programSources.Where(o => o.Enabled))
{ {
Type sourceClass; Type sourceClass;
if (SourceTypes.TryGetValue(source.Type, out sourceClass)) if (SourceTypes.TryGetValue(source.Type, out sourceClass))
@ -114,7 +115,7 @@ namespace Wox.Plugin.Program
sources.Add(programSource); sources.Add(programSource);
} }
} }
}); }
var tempPrograms = new List<Program>(); var tempPrograms = new List<Program>();
foreach (var source in sources) foreach (var source in sources)
@ -145,19 +146,19 @@ namespace Wox.Plugin.Program
list.Add(new ProgramSource() list.Add(new ProgramSource()
{ {
BonusPoints = 0, BonusPoints = 0,
Enabled = true, Enabled = ProgramStorage.Instance.EnableStartMenuSource,
Type = "CommonStartMenuProgramSource" Type = "CommonStartMenuProgramSource"
}); });
list.Add(new ProgramSource() list.Add(new ProgramSource()
{ {
BonusPoints = 0, BonusPoints = 0,
Enabled = true, Enabled = ProgramStorage.Instance.EnableStartMenuSource,
Type = "UserStartMenuProgramSource" Type = "UserStartMenuProgramSource"
}); });
list.Add(new ProgramSource() list.Add(new ProgramSource()
{ {
BonusPoints = -10, BonusPoints = -10,
Enabled = true, Enabled = ProgramStorage.Instance.EnableRegistrySource,
Type = "AppPathsProgramSource" Type = "AppPathsProgramSource"
}); });
return list; return list;

View file

@ -1,153 +1,156 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FDB3555B-58EF-4AE6-B5F1-904719637AB4}</ProjectGuid> <ProjectGuid>{FDB3555B-58EF-4AE6-B5F1-904719637AB4}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wox.Plugin.Program</RootNamespace> <RootNamespace>Wox.Plugin.Program</RootNamespace>
<AssemblyName>Wox.Plugin.Program</AssemblyName> <AssemblyName>Wox.Plugin.Program</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages> <RestorePackages>true</RestorePackages>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Program\</OutputPath> <OutputPath>..\..\Output\Debug\Plugins\Wox.Plugin.Program\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Program\</OutputPath> <OutputPath>..\..\Output\Release\Plugins\Wox.Plugin.Program\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data" />
<Reference Include="System.Data" /> <Reference Include="System.Xml" />
<Reference Include="System.Xml" /> <Reference Include="WindowsBase" />
<Reference Include="WindowsBase" /> </ItemGroup>
</ItemGroup> <ItemGroup>
<ItemGroup> <Page Include="AddProgramSource.xaml" />
<Compile Include="FileChangeWatcher.cs" /> <Compile Include="AddProgramSource.xaml.cs">
<Compile Include="IProgramSource.cs" /> <DependentUpon>AddProgramSource.xaml</DependentUpon>
<Compile Include="Program.cs" /> </Compile>
<Compile Include="ProgramCacheStorage.cs" /> <Compile Include="FileChangeWatcher.cs" />
<Compile Include="Programs.cs" /> <Compile Include="IProgramSource.cs" />
<Compile Include="ProgramSetting.xaml.cs"> <Compile Include="Program.cs" />
<DependentUpon>ProgramSetting.xaml</DependentUpon> <Compile Include="ProgramCacheStorage.cs" />
</Compile> <Compile Include="Programs.cs" />
<Compile Include="ProgramSource.cs" /> <Compile Include="ProgramSetting.xaml.cs">
<Compile Include="ProgramSources\AppPathsProgramSource.cs" /> <DependentUpon>ProgramSetting.xaml</DependentUpon>
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" /> </Compile>
<Compile Include="ProgramSources\FileSystemProgramSource.cs" /> <Compile Include="ProgramSource.cs" />
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" /> <Compile Include="ProgramSources\AppPathsProgramSource.cs" />
<Compile Include="ProgramStorage.cs" /> <Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
<Compile Include="ProgramSuffixes.xaml.cs"> <Compile Include="ProgramSources\FileSystemProgramSource.cs" />
<DependentUpon>ProgramSuffixes.xaml</DependentUpon> <Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
</Compile> <Compile Include="ProgramStorage.cs" />
<Compile Include="StringEmptyConverter.cs" /> <Compile Include="ProgramSuffixes.xaml.cs">
<Compile Include="Properties\AssemblyInfo.cs" /> <DependentUpon>ProgramSuffixes.xaml</DependentUpon>
</ItemGroup> </Compile>
<ItemGroup> <Compile Include="StringEmptyConverter.cs" />
<None Include="packages.config" /> <Compile Include="Properties\AssemblyInfo.cs" />
<None Include="plugin.json"> </ItemGroup>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <ItemGroup>
</None> <None Include="packages.config" />
</ItemGroup> <None Include="plugin.json">
<ItemGroup> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="Images\program.png"> </None>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </ItemGroup>
</None> <ItemGroup>
<None Include="Images\cmd.png"> <None Include="Images\program.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Images\folder.png"> <None Include="Images\cmd.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<Content Include="Languages\en.xaml"> <None Include="Images\folder.png">
<Generator>MSBuild:Compile</Generator> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> </None>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Content Include="Languages\en.xaml">
</Content> <Generator>MSBuild:Compile</Generator>
</ItemGroup> <SubType>Designer</SubType>
<ItemGroup> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="Languages\zh-cn.xaml"> </Content>
<Generator>MSBuild:Compile</Generator> </ItemGroup>
<SubType>Designer</SubType> <ItemGroup>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <None Include="Languages\zh-cn.xaml">
</None> <Generator>MSBuild:Compile</Generator>
<None Include="Languages\zh-tw.xaml"> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> </None>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <None Include="Languages\zh-tw.xaml">
</None> <Generator>MSBuild:Compile</Generator>
<Page Include="ProgramSetting.xaml"> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType> </None>
</Page> <Page Include="ProgramSetting.xaml">
<Page Include="ProgramSuffixes.xaml"> <Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType>
<SubType>Designer</SubType> </Page>
</Page> <Page Include="ProgramSuffixes.xaml">
</ItemGroup> <Generator>MSBuild:Compile</Generator>
<ItemGroup> <SubType>Designer</SubType>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj"> </Page>
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project> </ItemGroup>
<Name>Wox.Infrastructure</Name> <ItemGroup>
</ProjectReference> <ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj"> <Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project> <Name>Wox.Infrastructure</Name>
<Name>Wox.Plugin</Name> </ProjectReference>
</ProjectReference> <ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
</ItemGroup> <Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
<ItemGroup> <Name>Wox.Plugin</Name>
<COMReference Include="IWshRuntimeLibrary"> </ProjectReference>
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid> </ItemGroup>
<VersionMajor>1</VersionMajor> <ItemGroup>
<VersionMinor>0</VersionMinor> <COMReference Include="IWshRuntimeLibrary">
<Lcid>0</Lcid> <Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<WrapperTool>tlbimp</WrapperTool> <VersionMajor>1</VersionMajor>
<Isolated>False</Isolated> <VersionMinor>0</VersionMinor>
<EmbedInteropTypes>True</EmbedInteropTypes> <Lcid>0</Lcid>
</COMReference> <WrapperTool>tlbimp</WrapperTool>
</ItemGroup> <Isolated>False</Isolated>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <EmbedInteropTypes>True</EmbedInteropTypes>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> </COMReference>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> </ItemGroup>
<PropertyGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</PropertyGroup> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> <PropertyGroup>
</Target> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>