Move ProgramSetting into Feature

This commit is contained in:
Yeechan Lu
2014-03-29 14:42:43 +08:00
parent 4512854c2a
commit 479945455b
11 changed files with 219 additions and 106 deletions

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.Infrastructure
{
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

@@ -0,0 +1,26 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wox.Infrastructure
{
public class StringNullOrEmptyToVisibilityConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return string.IsNullOrEmpty(value as string) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}

View File

@@ -37,6 +37,7 @@
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@@ -60,6 +61,8 @@
<Compile Include="Storage\UserSettings\PluginHotkey.cs" /> <Compile Include="Storage\UserSettings\PluginHotkey.cs" />
<Compile Include="Storage\UserSettings\ProgramSource.cs" /> <Compile Include="Storage\UserSettings\ProgramSource.cs" />
<Compile Include="Storage\UserSettings\WebSearch.cs" /> <Compile Include="Storage\UserSettings\WebSearch.cs" />
<Compile Include="StringEmptyConverter.cs" />
<Compile Include="StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="WindowsShellRun.cs" /> <Compile Include="WindowsShellRun.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -0,0 +1,56 @@
<UserControl x:Class="Wox.Plugin.System.ProgramSetting"
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"
xmlns:infrastructure="clr-namespace:Wox.Infrastructure;assembly=Wox.Infrastructure"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<ListView x:Name="programSourceView" Grid.Row="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Location" Width="400">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={infrastructure:StringEmptyConverter}}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Type}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Bonus Points" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding BonusPoints}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Enabled" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Enabled}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10" Content="Delete"/>
<Button x:Name="btnEditProgramSource" Click="btnEditProgramSource_OnClick" Width="100" Margin="10" Content="Edit"/>
<Button x:Name="btnAddProgramSource" Click="btnAddProgramSource_OnClick" Width="100" Margin="10" Content="Add"/>
</StackPanel>
<TextBlock Grid.Row="1" Margin="10" HorizontalAlignment="Left" Text="* Restarting required" VerticalAlignment="Center" />
</Grid>
</UserControl>

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;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.System
{
/// <summary>
/// Interaction logic for ProgramSetting.xaml
/// </summary>
public partial class ProgramSetting : UserControl
{
public ProgramSetting()
{
InitializeComponent();
Loaded += Setting_Loaded;
}
private void Setting_Loaded(object sender, RoutedEventArgs e)
{
programSourceView.ItemsSource = UserSettingStorage.Instance.ProgramSources;
}
public void ReloadProgramSourceView()
{
programSourceView.Items.Refresh();
}
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)
{
UserSettingStorage.Instance.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");
}
}
}
}

View File

@@ -1,4 +1,4 @@
<Window x:Class="Wox.ProgramSourceSetting" <Window x:Class="Wox.Plugin.System.ProgramSourceSetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 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"
Icon="Images\app.png" Icon="Images\app.png"

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@@ -11,21 +12,20 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using Wox.Helper;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings; using Wox.Infrastructure.Storage.UserSettings;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
namespace Wox namespace Wox.Plugin.System
{ {
public partial class ProgramSourceSetting : Window public partial class ProgramSourceSetting : Window
{ {
private SettingWindow settingWindow; private ProgramSetting settingWindow;
private bool update; private bool update;
private ProgramSource updateProgramSource; private ProgramSource updateProgramSource;
public ProgramSourceSetting(SettingWindow settingWidow) public ProgramSourceSetting(ProgramSetting settingWidow)
{ {
this.settingWindow = settingWidow; this.settingWindow = settingWidow;
InitializeComponent(); InitializeComponent();
@@ -117,8 +117,8 @@ namespace Wox
Type type; Type type;
if (item != null && Wox.Plugin.System.Programs.SourceTypes.TryGetValue(item, out type)) if (item != null && Wox.Plugin.System.Programs.SourceTypes.TryGetValue(item, out type))
{ {
var attrs = type.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), false); var attrs = type.GetCustomAttributes(typeof(BrowsableAttribute), false);
if (attrs.Length > 0 && (attrs[0] as System.ComponentModel.BrowsableAttribute).Browsable == false) if (attrs.Length > 0 && (attrs[0] as BrowsableAttribute).Browsable == false)
{ {
this.tbLocation.IsEnabled = false; this.tbLocation.IsEnabled = false;
return; return;

View File

@@ -38,6 +38,9 @@
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
<Reference Include="YAMP"> <Reference Include="YAMP">
<HintPath>..\packages\YAMP.1.3.0\lib\net35\YAMP.dll</HintPath> <HintPath>..\packages\YAMP.1.3.0\lib\net35\YAMP.dll</HintPath>
</Reference> </Reference>
@@ -52,6 +55,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CMD\CMDStorage.cs" /> <Compile Include="CMD\CMDStorage.cs" />
<Compile Include="ProgramSetting.xaml.cs">
<DependentUpon>ProgramSetting.xaml</DependentUpon>
</Compile>
<Compile Include="ProgramSourceSetting.xaml.cs">
<DependentUpon>ProgramSourceSetting.xaml</DependentUpon>
</Compile>
<Compile Include="ProgramSources\AppPathsProgramSource.cs" /> <Compile Include="ProgramSources\AppPathsProgramSource.cs" />
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" /> <Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
<Compile Include="ProgramSources\PortableAppsProgramSource.cs" /> <Compile Include="ProgramSources\PortableAppsProgramSource.cs" />
@@ -85,6 +94,16 @@
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Page Include="ProgramSetting.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProgramSourceSetting.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent> <PostBuildEvent>

View File

@@ -76,56 +76,7 @@
<Button x:Name="btnAddCustomeHotkey" Click="BtnAddCustomeHotkey_OnClick" Width="100" Margin="10" Content="Add"/> <Button x:Name="btnAddCustomeHotkey" Click="BtnAddCustomeHotkey_OnClick" Width="100" Margin="10" Content="Add"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</TabItem> </TabItem>
<TabItem Header="Programs">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<ListView x:Name="programSourceView" Grid.Row="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Location" Width="400">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Location, ConverterParameter=(null), Converter={wox:StringEmptyConverter}}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Type}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Bonus Points" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding BonusPoints}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Enabled" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Enabled}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDeleteProgramSource" Click="btnDeleteProgramSource_OnClick" Width="100" Margin="10" Content="Delete"/>
<Button x:Name="btnEditProgramSource" Click="btnEditProgramSource_OnClick" Width="100" Margin="10" Content="Edit"/>
<Button x:Name="btnAddProgramSource" Click="btnAddProgramSource_OnClick" Width="100" Margin="10" Content="Add"/>
</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

@@ -153,7 +153,6 @@ namespace Wox
themeComboBox.SelectedItem = UserSettingStorage.Instance.Theme; themeComboBox.SelectedItem = UserSettingStorage.Instance.Theme;
cbReplaceWinR.IsChecked = UserSettingStorage.Instance.ReplaceWinR; cbReplaceWinR.IsChecked = UserSettingStorage.Instance.ReplaceWinR;
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches; webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches;
programSourceView.ItemsSource = UserSettingStorage.Instance.ProgramSources;
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys; lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
cbEnablePythonPlugins.IsChecked = UserSettingStorage.Instance.EnablePythonPlugins; cbEnablePythonPlugins.IsChecked = UserSettingStorage.Instance.EnablePythonPlugins;
cbStartWithWindows.IsChecked = File.Exists(woxLinkPath); cbStartWithWindows.IsChecked = File.Exists(woxLinkPath);
@@ -202,10 +201,6 @@ namespace Wox
webSearchView.Items.Refresh(); webSearchView.Items.Refresh();
} }
public void ReloadProgramSourceView()
{
programSourceView.Items.Refresh();
}
private List<string> LoadAvailableThemes() private List<string> LoadAvailableThemes()
{ {
@@ -252,43 +247,6 @@ 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)
{
UserSettingStorage.Instance.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

@@ -120,9 +120,6 @@
<Compile Include="Helper\WallpaperPathRetrieval.cs" /> <Compile Include="Helper\WallpaperPathRetrieval.cs" />
<Compile Include="Helper\WindowIntelopHelper.cs" /> <Compile Include="Helper\WindowIntelopHelper.cs" />
<Compile Include="OpacityModeConverter.cs" /> <Compile Include="OpacityModeConverter.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>
@@ -160,10 +157,6 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<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>