Databinding for general tab

This commit is contained in:
bao-qian
2016-05-21 23:16:32 +01:00
parent 7d2ac2f55d
commit 3593a918b7
3 changed files with 46 additions and 124 deletions

View File

@@ -1,73 +1,75 @@
<Window <Window
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wox="clr-namespace:Wox" xmlns:wox="clr-namespace:Wox"
x:Class="Wox.SettingWindow" xmlns:vm="clr-namespace:Wox.ViewModel"
xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin" xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin"
xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure" xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure"
x:Class="Wox.SettingWindow"
mc:Ignorable="d"
Icon="Images\app.png" Icon="Images\app.png"
Title="{DynamicResource wox_settings}" Title="{DynamicResource wox_settings}"
ResizeMode="NoResize" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown"> Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown"
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}">
<Window.Resources> <Window.Resources>
<ListBoxItem HorizontalContentAlignment="Stretch"
IsEnabled="False"
IsHitTestVisible="False" x:Key="FeatureBoxSeperator">
<Separator Width="{Binding ElementName=PluginsListBox, Path=ActualWidth}" />
</ListBoxItem>
<image:ImagePathConverter x:Key="ImageConverter" /> <image:ImagePathConverter x:Key="ImageConverter" />
</Window.Resources> </Window.Resources>
<TabControl Height="auto" x:Name="SettingTab" SelectionChanged="settingTab_SelectionChanged"> <TabControl Height="auto" x:Name="SettingTab" SelectionChanged="OnTabChanged">
<TabItem Header="{DynamicResource general}"> <TabItem Header="{DynamicResource general}">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<CheckBox x:Name="AutoStartup" Unchecked="CbStartWithWindows_OnUnchecked" <CheckBox IsChecked="{Binding Settings.StartWoxOnSystemStartup}" Margin="10">
Checked="CbStartWithWindows_OnChecked" Margin="10">
<TextBlock Text="{DynamicResource startWoxOnSystemStartup}" /> <TextBlock Text="{DynamicResource startWoxOnSystemStartup}" />
</CheckBox> </CheckBox>
<CheckBox x:Name="HideOnStartup" Margin="10"> <CheckBox Margin="10" IsChecked="{Binding Settings.HideOnStartup}">
<TextBlock Text="{DynamicResource hideOnStartup}" /> <TextBlock Text="{DynamicResource hideOnStartup}" />
</CheckBox> </CheckBox>
<CheckBox x:Name="HideWhenDeactive" Margin="10"> <CheckBox Margin="10" IsChecked="{Binding Settings.HideWhenDeactive}">
<TextBlock Text="{DynamicResource hideWoxWhenLoseFocus}" /> <TextBlock Text="{DynamicResource hideWoxWhenLoseFocus}" />
</CheckBox> </CheckBox>
<CheckBox x:Name="RememberLastLocation" Margin="10"> <CheckBox Margin="10" IsChecked="{Binding Settings.RememberLastLaunchLocation}">
<TextBlock Text="{DynamicResource rememberLastLocation}" /> <TextBlock Text="{DynamicResource rememberLastLocation}" />
</CheckBox> </CheckBox>
<CheckBox x:Name="IgnoreHotkeysOnFullscreen" Margin="10"> <CheckBox Margin="10" IsChecked="{Binding Settings.IgnoreHotkeysOnFullscreen}">
<TextBlock Text="{DynamicResource ignoreHotkeysOnFullscreen}" /> <TextBlock Text="{DynamicResource ignoreHotkeysOnFullscreen}" />
</CheckBox> </CheckBox>
<CheckBox x:Name="AutoUpdates" Margin="10"> <CheckBox Margin="10" IsChecked="{Binding Settings.AutoUpdates}"
Checked="OnAutoStartupChecked" Unchecked="OnAutoStartupUncheck">
<TextBlock Text="{DynamicResource autoUpdates}" /> <TextBlock Text="{DynamicResource autoUpdates}" />
</CheckBox> </CheckBox>
<StackPanel Margin="10" Orientation="Horizontal"> <StackPanel Margin="10" Orientation="Horizontal">
<TextBlock Text="{DynamicResource language}" /> <TextBlock Text="{DynamicResource language}" />
<ComboBox Margin="10 0 0 0" Width="120" x:Name="Languages" /> <ComboBox Margin="10 0 0 0" Width="120" SelectionChanged="OnLanguageChanged"
ItemsSource="{Binding Languages}" SelectedValue="{Binding Settings.Language}"
DisplayMemberPath="Display" SelectedValuePath = "LanguageCode" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="10"> <StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Text="{DynamicResource maxShowResults}" /> <TextBlock Text="{DynamicResource maxShowResults}" />
<ComboBox Margin="10 0 0 0" Width="45" Name="MaxResults" /> <ComboBox Margin="10 0 0 0" Width="45" ItemsSource="{Binding MaxResultsRange}" SelectedItem="{Binding Settings.MaxResultsToShow}"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="{DynamicResource pythonDirectory}" Margin="10" /> <TextBlock Margin="10" Text="{DynamicResource pythonDirectory}" />
<TextBox Width="300" Margin="10" x:Name="PythonDirectory" /> <TextBox Width="300" Margin="10" x:Name="PythonDirectory" Text="{Binding Settings.PluginSettings.PythonDirectory}"/>
<Button Click="SelectPythonDirectoryOnClick" Content="{DynamicResource selectPythonDirectory}" <Button Margin="10" Click="OnSelectPythonDirectoryClick" Content="{DynamicResource selectPythonDirectory}" />
VerticalAlignment="Center" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Header="{DynamicResource plugin}" x:Name="PluginTab"> <TabItem Header="{DynamicResource plugin}" x:Name="PluginTab">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="200" /> <ColumnDefinition Width="39.5" />
<ColumnDefinition Width="160.5"/>
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<DockPanel Grid.Column="0"> <DockPanel Grid.Column="0" Grid.ColumnSpan="2">
<TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left" Cursor="Hand" <TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left" Cursor="Hand"
MouseUp="tbMorePlugins_MouseUp" Foreground="Blue" MouseUp="tbMorePlugins_MouseUp" Foreground="Blue"
Text="{DynamicResource browserMorePlugins}" /> Text="{DynamicResource browserMorePlugins}" />
<ListBox x:Name="PluginsListBox" Margin="10, 0, 10, 10" <ListBox x:Name="PluginsListBox" Margin="10, 0, 10, 10"
SelectionChanged="lbPlugins_OnSelectionChanged" SelectionChanged="OnPluginsSelectionChanged"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.IsSharedSizeScope="True"> ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.IsSharedSizeScope="True">
<ListBox.Resources> <ListBox.Resources>
@@ -95,7 +97,7 @@
</ListBox.Resources> </ListBox.Resources>
</ListBox> </ListBox>
</DockPanel> </DockPanel>
<Grid Margin="0" Grid.Column="1"> <Grid Margin="0" Grid.Column="2">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />

View File

@@ -52,86 +52,8 @@ namespace Wox
_settings.ProxyEnabled = ToggleProxy.IsChecked ?? false; _settings.ProxyEnabled = ToggleProxy.IsChecked ?? false;
} }
private async void Setting_Loaded(object sender, RoutedEventArgs ev) private void Setting_Loaded(object sender, RoutedEventArgs ev)
{ {
#region General
HideOnStartup.Checked += (o, e) =>
{
_settings.HideOnStartup = true;
};
HideOnStartup.Unchecked += (o, e) =>
{
_settings.HideOnStartup = false;
};
HideWhenDeactive.Checked += (o, e) =>
{
_settings.HideWhenDeactive = true;
};
HideWhenDeactive.Unchecked += (o, e) =>
{
_settings.HideWhenDeactive = false;
};
RememberLastLocation.Checked += (o, e) =>
{
_settings.RememberLastLaunchLocation = true;
};
RememberLastLocation.Unchecked += (o, e) =>
{
_settings.RememberLastLaunchLocation = false;
};
IgnoreHotkeysOnFullscreen.Checked += (o, e) =>
{
_settings.IgnoreHotkeysOnFullscreen = true;
};
IgnoreHotkeysOnFullscreen.Unchecked += (o, e) =>
{
_settings.IgnoreHotkeysOnFullscreen = false;
};
AutoUpdates.Checked += (o, e) =>
{
_settings.AutoUpdates = true;
};
AutoUpdates.Unchecked += (o, e) =>
{
_settings.AutoUpdates = false;
};
AutoStartup.IsChecked = _settings.StartWoxOnSystemStartup;
MaxResults.SelectionChanged += (o, e) =>
{
_settings.MaxResultsToShow = (int)MaxResults.SelectedItem;
//MainWindow.pnlResult.lbResults.GetBindingExpression(MaxHeightProperty).UpdateTarget();
};
HideOnStartup.IsChecked = _settings.HideOnStartup;
HideWhenDeactive.IsChecked = _settings.HideWhenDeactive;
RememberLastLocation.IsChecked = _settings.RememberLastLaunchLocation;
IgnoreHotkeysOnFullscreen.IsChecked = _settings.IgnoreHotkeysOnFullscreen;
AutoUpdates.IsChecked = _settings.AutoUpdates;
LoadLanguages();
MaxResults.ItemsSource = Enumerable.Range(2, 16);
var maxResults = _settings.MaxResultsToShow;
MaxResults.SelectedItem = maxResults == 0 ? 6 : maxResults;
PythonDirectory.Text = _settings.PluginSettings.PythonDirectory;
#endregion
#region Proxy #region Proxy
ToggleProxy.IsChecked = _settings.ProxyEnabled; ToggleProxy.IsChecked = _settings.ProxyEnabled;
@@ -182,7 +104,7 @@ namespace Wox
} }
} }
private void settingTab_SelectionChanged(object sender, SelectionChangedEventArgs e) private void OnTabChanged(object sender, SelectionChangedEventArgs e)
{ {
// Update controls inside the selected tab // Update controls inside the selected tab
if (e.OriginalSource != SettingTab) return; if (e.OriginalSource != SettingTab) return;
@@ -203,30 +125,20 @@ namespace Wox
#region General #region General
private void LoadLanguages() void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
{ {
Languages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages(); var language = (Language)e.AddedItems[0];
Languages.DisplayMemberPath = "Display"; InternationalizationManager.Instance.ChangeLanguage(language);
Languages.SelectedValuePath = "LanguageCode";
Languages.SelectedValue = _settings.Language;
Languages.SelectionChanged += cbLanguages_SelectionChanged;
} }
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e) private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
{
InternationalizationManager.Instance.ChangeLanguage(Languages.SelectedItem as Language);
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{ {
SetStartup(); SetStartup();
_settings.StartWoxOnSystemStartup = true;
} }
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e) private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
{ {
RemoveStartup(); RemoveStartup();
_settings.StartWoxOnSystemStartup = false;
} }
public static void SetStartup() public static void SetStartup()
@@ -249,7 +161,7 @@ namespace Wox
{ {
using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true)) using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true))
{ {
var path = key?.GetValue("Wox") as string; var path = key?.GetValue(Infrastructure.Constant.Wox) as string;
if (path != null) if (path != null)
{ {
return path == Infrastructure.Constant.ExecutablePath; return path == Infrastructure.Constant.ExecutablePath;
@@ -261,7 +173,7 @@ namespace Wox
} }
} }
private void SelectPythonDirectoryOnClick(object sender, RoutedEventArgs e) private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
{ {
var dlg = new System.Windows.Forms.FolderBrowserDialog var dlg = new System.Windows.Forms.FolderBrowserDialog
{ {
@@ -277,7 +189,6 @@ namespace Wox
var pythonPath = Path.Combine(pythonDirectory, PluginsLoader.PythonExecutable); var pythonPath = Path.Combine(pythonDirectory, PluginsLoader.PythonExecutable);
if (File.Exists(pythonPath)) if (File.Exists(pythonPath))
{ {
PythonDirectory.Text = pythonDirectory;
_settings.PluginSettings.PythonDirectory = pythonDirectory; _settings.PluginSettings.PythonDirectory = pythonDirectory;
MessageBox.Show("Remember to restart Wox use new Python path"); MessageBox.Show("Remember to restart Wox use new Python path");
} }
@@ -581,7 +492,7 @@ namespace Wox
#region Plugin #region Plugin
private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventArgs _) private void OnPluginsSelectionChanged(object sender, SelectionChangedEventArgs _)
{ {
var pair = PluginsListBox.SelectedItem as PluginPair; var pair = PluginsListBox.SelectedItem as PluginPair;

View File

@@ -1,8 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.UserSettings; using Wox.Core.UserSettings;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
@@ -11,6 +16,8 @@ namespace Wox.ViewModel
{ {
public class SettingWindowViewModel public class SettingWindowViewModel
{ {
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
private readonly JsonStrorage<Settings> _storage; private readonly JsonStrorage<Settings> _storage;
public Settings Settings { get; set; } public Settings Settings { get; set; }
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages(); public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
@@ -25,5 +32,7 @@ namespace Wox.ViewModel
{ {
_storage.Save(); _storage.Save();
} }
} }
} }