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
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:wox="clr-namespace:Wox"
x:Class="Wox.SettingWindow"
xmlns:vm="clr-namespace:Wox.ViewModel"
xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin"
xmlns:image="clr-namespace:Wox.Infrastructure.Image;assembly=Wox.Infrastructure"
x:Class="Wox.SettingWindow"
mc:Ignorable="d"
Icon="Images\app.png"
Title="{DynamicResource wox_settings}"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown">
Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown"
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}">
<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" />
</Window.Resources>
<TabControl Height="auto" x:Name="SettingTab" SelectionChanged="settingTab_SelectionChanged">
<TabControl Height="auto" x:Name="SettingTab" SelectionChanged="OnTabChanged">
<TabItem Header="{DynamicResource general}">
<StackPanel Orientation="Vertical">
<CheckBox x:Name="AutoStartup" Unchecked="CbStartWithWindows_OnUnchecked"
Checked="CbStartWithWindows_OnChecked" Margin="10">
<CheckBox IsChecked="{Binding Settings.StartWoxOnSystemStartup}" Margin="10">
<TextBlock Text="{DynamicResource startWoxOnSystemStartup}" />
</CheckBox>
<CheckBox x:Name="HideOnStartup" Margin="10">
<CheckBox Margin="10" IsChecked="{Binding Settings.HideOnStartup}">
<TextBlock Text="{DynamicResource hideOnStartup}" />
</CheckBox>
<CheckBox x:Name="HideWhenDeactive" Margin="10">
<CheckBox Margin="10" IsChecked="{Binding Settings.HideWhenDeactive}">
<TextBlock Text="{DynamicResource hideWoxWhenLoseFocus}" />
</CheckBox>
<CheckBox x:Name="RememberLastLocation" Margin="10">
<CheckBox Margin="10" IsChecked="{Binding Settings.RememberLastLaunchLocation}">
<TextBlock Text="{DynamicResource rememberLastLocation}" />
</CheckBox>
<CheckBox x:Name="IgnoreHotkeysOnFullscreen" Margin="10">
<CheckBox Margin="10" IsChecked="{Binding Settings.IgnoreHotkeysOnFullscreen}">
<TextBlock Text="{DynamicResource ignoreHotkeysOnFullscreen}" />
</CheckBox>
<CheckBox x:Name="AutoUpdates" Margin="10">
<CheckBox Margin="10" IsChecked="{Binding Settings.AutoUpdates}"
Checked="OnAutoStartupChecked" Unchecked="OnAutoStartupUncheck">
<TextBlock Text="{DynamicResource autoUpdates}" />
</CheckBox>
<StackPanel Margin="10" Orientation="Horizontal">
<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 Orientation="Horizontal" Margin="10">
<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 Orientation="Horizontal">
<TextBlock Text="{DynamicResource pythonDirectory}" Margin="10" />
<TextBox Width="300" Margin="10" x:Name="PythonDirectory" />
<Button Click="SelectPythonDirectoryOnClick" Content="{DynamicResource selectPythonDirectory}"
VerticalAlignment="Center" />
<TextBlock Margin="10" Text="{DynamicResource pythonDirectory}" />
<TextBox Width="300" Margin="10" x:Name="PythonDirectory" Text="{Binding Settings.PluginSettings.PythonDirectory}"/>
<Button Margin="10" Click="OnSelectPythonDirectoryClick" Content="{DynamicResource selectPythonDirectory}" />
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="{DynamicResource plugin}" x:Name="PluginTab">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="39.5" />
<ColumnDefinition Width="160.5"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<DockPanel Grid.Column="0" Grid.ColumnSpan="2">
<TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left" Cursor="Hand"
MouseUp="tbMorePlugins_MouseUp" Foreground="Blue"
Text="{DynamicResource browserMorePlugins}" />
<ListBox x:Name="PluginsListBox" Margin="10, 0, 10, 10"
SelectionChanged="lbPlugins_OnSelectionChanged"
SelectionChanged="OnPluginsSelectionChanged"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.IsSharedSizeScope="True">
<ListBox.Resources>
@@ -95,7 +97,7 @@
</ListBox.Resources>
</ListBox>
</DockPanel>
<Grid Margin="0" Grid.Column="1">
<Grid Margin="0" Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />

View File

@@ -52,86 +52,8 @@ namespace Wox
_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
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
if (e.OriginalSource != SettingTab) return;
@@ -203,30 +125,20 @@ namespace Wox
#region General
private void LoadLanguages()
void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
{
Languages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
Languages.DisplayMemberPath = "Display";
Languages.SelectedValuePath = "LanguageCode";
Languages.SelectedValue = _settings.Language;
Languages.SelectionChanged += cbLanguages_SelectionChanged;
var language = (Language)e.AddedItems[0];
InternationalizationManager.Instance.ChangeLanguage(language);
}
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
InternationalizationManager.Instance.ChangeLanguage(Languages.SelectedItem as Language);
}
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
{
SetStartup();
_settings.StartWoxOnSystemStartup = true;
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
{
RemoveStartup();
_settings.StartWoxOnSystemStartup = false;
}
public static void SetStartup()
@@ -249,7 +161,7 @@ namespace Wox
{
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)
{
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
{
@@ -277,7 +189,6 @@ namespace Wox
var pythonPath = Path.Combine(pythonDirectory, PluginsLoader.PythonExecutable);
if (File.Exists(pythonPath))
{
PythonDirectory.Text = pythonDirectory;
_settings.PluginSettings.PythonDirectory = pythonDirectory;
MessageBox.Show("Remember to restart Wox use new Python path");
}
@@ -581,7 +492,7 @@ namespace Wox
#region Plugin
private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventArgs _)
private void OnPluginsSelectionChanged(object sender, SelectionChangedEventArgs _)
{
var pair = PluginsListBox.SelectedItem as PluginPair;

View File

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