Close #42 Program Source settings GUI

This commit is contained in:
Yeechan Lu 2014-03-19 20:16:20 +08:00
parent f4e74065ec
commit 1fa4be9ebb
15 changed files with 347 additions and 12 deletions

View File

@ -10,8 +10,13 @@ namespace Wox.Infrastructure.UserSettings
{ {
public string Location { get; set; } public string Location { get; set; }
public string Type { get; set; } public string Type { get; set; }
public int BounsPoints { get; set; } public int BonusPoints { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
public Dictionary<string, string> Meta { get; set; } public Dictionary<string, string> Meta { get; set; }
public override string ToString()
{
return (this.Type ?? "") + ":" + this.Location ?? "";
}
} }
} }

View File

@ -52,19 +52,19 @@ namespace Wox.Infrastructure.UserSettings
var list = new List<ProgramSource>(); var list = new List<ProgramSource>();
list.Add(new ProgramSource() list.Add(new ProgramSource()
{ {
BounsPoints = 0, BonusPoints = 0,
Enabled = true, Enabled = true,
Type = "CommonStartMenuProgramSource" Type = "CommonStartMenuProgramSource"
}); });
list.Add(new ProgramSource() list.Add(new ProgramSource()
{ {
BounsPoints = 0, BonusPoints = 0,
Enabled = true, Enabled = true,
Type = "UserStartMenuProgramSource" Type = "UserStartMenuProgramSource"
}); });
list.Add(new ProgramSource() list.Add(new ProgramSource()
{ {
BounsPoints = -10, BonusPoints = -10,
Enabled = true, Enabled = true,
Type = "AppPathsProgramSource" Type = "AppPathsProgramSource"
}); });

View File

@ -16,7 +16,7 @@ namespace Wox.Plugin.System
public AppPathsProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source) public AppPathsProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
: this() : this()
{ {
this.BonusPoints = source.BounsPoints; this.BonusPoints = source.BonusPoints;
} }
public override List<Program> LoadPrograms() public override List<Program> LoadPrograms()
@ -46,5 +46,10 @@ namespace Wox.Plugin.System
} }
} }
} }
public override string ToString()
{
return typeof(AppPathsProgramSource).Name;
}
} }
} }

View File

@ -30,8 +30,12 @@ namespace Wox.Plugin.System
public CommonStartMenuProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source) public CommonStartMenuProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
: this() : this()
{ {
this.BonusPoints = source.BounsPoints; this.BonusPoints = source.BonusPoints;
} }
public override string ToString()
{
return typeof(CommonStartMenuProgramSource).Name;
}
} }
} }

View File

@ -25,7 +25,7 @@ namespace Wox.Plugin.System
public FileSystemProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source) public FileSystemProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
: this(source.Location) : this(source.Location)
{ {
this.BonusPoints = source.BounsPoints; this.BonusPoints = source.BonusPoints;
} }
public override List<Program> LoadPrograms() public override List<Program> LoadPrograms()
@ -52,5 +52,10 @@ namespace Wox.Plugin.System
GetAppFromDirectory(subDirectory, list); GetAppFromDirectory(subDirectory, list);
} }
} }
public override string ToString()
{
return typeof(FileSystemProgramSource).Name + ":" + this.BaseDirectory;
}
} }
} }

View File

@ -18,7 +18,7 @@ namespace Wox.Plugin.System
public PortableAppsProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source) public PortableAppsProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
: this(source.Location) : this(source.Location)
{ {
this.BonusPoints = source.BounsPoints; this.BonusPoints = source.BonusPoints;
} }
public override List<Program> LoadPrograms() public override List<Program> LoadPrograms()
@ -121,5 +121,11 @@ namespace Wox.Plugin.System
return list; return list;
} }
public override string ToString()
{
return typeof(PortableAppsProgramSource).Name + ":" + this.BaseDirectory;
}
} }
} }

View File

@ -44,7 +44,7 @@ namespace Wox.Plugin.System
{ {
List<Program> installedList = new List<Program>(); List<Program> installedList = new List<Program>();
List<IProgramSource> sources = new List<IProgramSource>(); List<IProgramSource> sources = new List<IProgramSource>();
Dictionary<string, Type> sourceTypes = new Dictionary<string, Type>() { public static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)}, {"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)}, {"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}, {"AppPathsProgramSource", typeof(AppPathsProgramSource)},
@ -116,7 +116,7 @@ namespace Wox.Plugin.System
if (source.Enabled) if (source.Enabled)
{ {
Type sourceClass; Type sourceClass;
if (sourceTypes.TryGetValue(source.Type, out sourceClass)) if (SourceTypes.TryGetValue(source.Type, out sourceClass))
{ {
sources.Add(sourceClass.GetConstructor( sources.Add(sourceClass.GetConstructor(
new Type[] { typeof(Wox.Infrastructure.UserSettings.ProgramSource) } new Type[] { typeof(Wox.Infrastructure.UserSettings.ProgramSource) }

View File

@ -16,7 +16,12 @@ namespace Wox.Plugin.System
public UserStartMenuProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source) public UserStartMenuProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
: this() : this()
{ {
this.BonusPoints = source.BounsPoints; this.BonusPoints = source.BonusPoints;
}
public override string ToString()
{
return typeof(UserStartMenuProgramSource).Name;
} }
} }
} }

View File

@ -0,0 +1,40 @@
<Window x:Class="Wox.ProgramSourceSetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="Images\app.png"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Title="ProgramSourceSetting" Height="350" Width="674.766">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Type:</TextBlock>
<ComboBox x:Name="cbType" Margin="10" Grid.Row="0" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" ItemsSource="{Binding}" SelectionChanged="cbType_SelectionChanged"></ComboBox>
<TextBlock Margin="10" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Location:</TextBlock>
<TextBox x:Name="tbLocation" Margin="10" Grid.Row="1" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">BonusPoints:</TextBlock>
<TextBox x:Name="tbBonusPoints" Margin="10" Grid.Row="2" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<TextBlock Margin="10" FontSize="14" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Enable:</TextBlock>
<CheckBox x:Name="cbEnable" IsChecked="True" Margin="10" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center"></CheckBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="5" Grid.Column="1">
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="25">Cancel</Button>
<Button x:Name="btnAdd" Margin="10 0 10 0" Width="80" Height="25" Click="btnAdd_OnClick">
<TextBlock x:Name="lblAdd">Add</TextBlock>
</Button>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,129 @@
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.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using MessageBox = System.Windows.MessageBox;
namespace Wox
{
public partial class ProgramSourceSetting : Window
{
private SettingWidow settingWidow;
private bool update;
private ProgramSource updateProgramSource;
public ProgramSourceSetting(SettingWidow settingWidow)
{
this.settingWidow = settingWidow;
InitializeComponent();
this.cbType.ItemsSource = Wox.Plugin.System.Programs.SourceTypes.Select(o => o.Key).ToList();
}
public void UpdateItem(ProgramSource programSource)
{
updateProgramSource = CommonStorage.Instance.UserSetting.ProgramSources.FirstOrDefault(o => o == programSource);
if (updateProgramSource == null)
{
MessageBox.Show("Invalid program source");
Close();
return;
}
update = true;
lblAdd.Text = "Update";
cbEnable.IsChecked = programSource.Enabled;
cbType.SelectedItem = programSource.Type;
cbType.IsEnabled = false;
tbLocation.Text = programSource.Location;
tbBonusPoints.Text = programSource.BonusPoints.ToString();
}
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
{
string location = tbLocation.Text;
if (this.tbLocation.IsEnabled == true && string.IsNullOrEmpty(location))
{
MessageBox.Show("Please input Type field");
return;
}
string type = cbType.SelectedItem as string;
if (string.IsNullOrEmpty(type))
{
MessageBox.Show("Please input Type field");
return;
}
int bonusPoint = 0;
int.TryParse(this.tbBonusPoints.Text, out bonusPoint);
if (!update)
{
ProgramSource p = new ProgramSource()
{
Location = this.tbLocation.IsEnabled ? location : null,
Enabled = cbEnable.IsChecked ?? false,
Type = type,
BonusPoints = bonusPoint
};
if (CommonStorage.Instance.UserSetting.ProgramSources.Exists(o => o.ToString() == p.ToString() && o != p))
{
MessageBox.Show("Program source already exists!");
return;
}
CommonStorage.Instance.UserSetting.ProgramSources.Add(p);
MessageBox.Show(string.Format("Add {0} program source successfully!", p.ToString()));
}
else
{
if (CommonStorage.Instance.UserSetting.ProgramSources.Exists(o => o.ToString() == updateProgramSource.ToString() && o != updateProgramSource))
{
MessageBox.Show("Program source already exists!");
return;
}
updateProgramSource.Location = this.tbLocation.IsEnabled ? location : null;
updateProgramSource.Type = type;
updateProgramSource.Enabled = cbEnable.IsChecked ?? false;
updateProgramSource.BonusPoints = bonusPoint;
MessageBox.Show(string.Format("Update {0} program source successfully!", updateProgramSource.ToString()));
}
CommonStorage.Instance.Save();
settingWidow.ReloadProgramSourceView();
Close();
}
private void cbType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string item = cbType.SelectedItem as String;
Type type;
if (item != null && Wox.Plugin.System.Programs.SourceTypes.TryGetValue(item, out type))
{
var attrs = type.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), false);
if (attrs.Length > 0 && (attrs[0] as System.ComponentModel.BrowsableAttribute).Browsable == false)
{
this.tbLocation.IsEnabled = false;
return;
}
}
this.tbLocation.IsEnabled = true;
}
}
}

View File

@ -69,6 +69,57 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
</TabItem> </TabItem>
<TabItem Header="Programs">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<ListView x:Name="programSourceView" Grid.Row="0">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Location" Width="400">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Location, Converter={wox:StringEmptyConverter}, ConverterParameter='(null)'}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Type}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Bonus Points" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=BonusPoints}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Enabled" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Enabled}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10">Delete</Button>
<Button x:Name="btnEditProgramSource" Click="btnEditProgramSource_OnClick" Width="100" Margin="10">Edit</Button>
<Button x:Name="btnAddProgramSource" Click="btnAddProgramSource_OnClick" Width="100" Margin="10">Add</Button>
</StackPanel>
<TextBlock Grid.Row="1" Margin="10" HorizontalAlignment="Left" Text="* Restarting required" VerticalAlignment="Center" />
</Grid>
</TabItem>
<TabItem Header="Web Search"> <TabItem Header="Web Search">
<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>

View File

@ -60,13 +60,14 @@ namespace Wox
foreach (string theme in LoadAvailableThemes()) foreach (string theme in LoadAvailableThemes())
{ {
string themeName = theme.Substring(theme.LastIndexOf('\\') + 1).Replace(".xaml", ""); string themeName = System.IO.Path.GetFileNameWithoutExtension(theme);
themeComboBox.Items.Add(themeName); themeComboBox.Items.Add(themeName);
} }
themeComboBox.SelectedItem = CommonStorage.Instance.UserSetting.Theme; themeComboBox.SelectedItem = CommonStorage.Instance.UserSetting.Theme;
cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR; cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR;
webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches; webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches;
programSourceView.ItemsSource = CommonStorage.Instance.UserSetting.ProgramSources;
lvCustomHotkey.ItemsSource = CommonStorage.Instance.UserSetting.CustomPluginHotkeys; lvCustomHotkey.ItemsSource = CommonStorage.Instance.UserSetting.CustomPluginHotkeys;
cbEnablePythonPlugins.IsChecked = CommonStorage.Instance.UserSetting.EnablePythonPlugins; cbEnablePythonPlugins.IsChecked = CommonStorage.Instance.UserSetting.EnablePythonPlugins;
cbStartWithWindows.IsChecked = File.Exists(woxLinkPath); cbStartWithWindows.IsChecked = File.Exists(woxLinkPath);
@ -77,6 +78,11 @@ namespace Wox
webSearchView.Items.Refresh(); webSearchView.Items.Refresh();
} }
public void ReloadProgramSourceView()
{
programSourceView.Items.Refresh();
}
private List<string> LoadAvailableThemes() private List<string> LoadAvailableThemes()
{ {
string themePath = Directory.GetCurrentDirectory() + "\\Themes\\"; string themePath = Directory.GetCurrentDirectory() + "\\Themes\\";
@ -128,6 +134,43 @@ namespace Wox
} }
} }
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{
ProgramSourceSetting programSource = new ProgramSourceSetting(this);
programSource.ShowDialog();
}
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
{
ProgramSource seletedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (seletedProgramSource != null &&
MessageBox.Show("Are your sure to delete " + seletedProgramSource.ToString(), "Delete ProgramSource",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
CommonStorage.Instance.UserSetting.ProgramSources.Remove(seletedProgramSource);
programSourceView.Items.Refresh();
}
else
{
MessageBox.Show("Please select a program source");
}
}
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
{
ProgramSource seletedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (seletedProgramSource != null)
{
ProgramSourceSetting programSource = new ProgramSourceSetting(this);
programSource.UpdateItem(seletedProgramSource);
programSource.ShowDialog();
}
else
{
MessageBox.Show("Please select a program source");
}
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e) private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{ {
CreateStartupFolderShortcut(); CreateStartupFolderShortcut();

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wox
{
public class StringEmptyConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return string.IsNullOrEmpty((string)value) ? parameter : value;
}
public object ConvertBack(
object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}

View File

@ -109,6 +109,11 @@ namespace Wox
} }
else else
{ {
if (CommonStorage.Instance.UserSetting.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch))
{
MessageBox.Show("ActionWord has existed, please input a new one.");
return;
}
updateWebSearch.ActionWord = action; updateWebSearch.ActionWord = action;
updateWebSearch.IconPath = tbIconPath.Text; updateWebSearch.IconPath = tbIconPath.Text;
updateWebSearch.Enabled = cbEnable.IsChecked ?? false; updateWebSearch.Enabled = cbEnable.IsChecked ?? false;

View File

@ -107,6 +107,9 @@
<Compile Include="Commands\CommandFactory.cs" /> <Compile Include="Commands\CommandFactory.cs" />
<Compile Include="Commands\PluginCommand.cs" /> <Compile Include="Commands\PluginCommand.cs" />
<Compile Include="Commands\SystemCommand.cs" /> <Compile Include="Commands\SystemCommand.cs" />
<Compile Include="ProgramSourceSetting.xaml.cs">
<DependentUpon>ProgramSourceSetting.xaml</DependentUpon>
</Compile>
<Compile Include="CustomPluginHotkeySetting.xaml.cs"> <Compile Include="CustomPluginHotkeySetting.xaml.cs">
<DependentUpon>CustomPluginHotkeySetting.xaml</DependentUpon> <DependentUpon>CustomPluginHotkeySetting.xaml</DependentUpon>
</Compile> </Compile>
@ -135,10 +138,15 @@
<Compile Include="SettingWindow.xaml.cs"> <Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon> <DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="StringEmptyConverter.cs" />
<Compile Include="StringNullOrEmptyToVisibilityConverter.cs" /> <Compile Include="StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="WebSearchSetting.xaml.cs"> <Compile Include="WebSearchSetting.xaml.cs">
<DependentUpon>WebSearchSetting.xaml</DependentUpon> <DependentUpon>WebSearchSetting.xaml</DependentUpon>
</Compile> </Compile>
<Page Include="ProgramSourceSetting.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="CustomPluginHotkeySetting.xaml"> <Page Include="CustomPluginHotkeySetting.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>