Change Themes tab layout and add wallpaper behind preview.

This commit is contained in:
Yeechan Lu 2014-03-26 15:30:59 +08:00
parent f157e6a9f5
commit 45f32ba62c
4 changed files with 129 additions and 31 deletions

View File

@ -0,0 +1,48 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Media;
using Microsoft.Win32;
namespace Wox.Helper
{
public static class WallpaperPathRetrieval
{
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern Int32 SystemParametersInfo(UInt32 action,
Int32 uParam, StringBuilder vParam, UInt32 winIni);
private static readonly UInt32 SPI_GETDESKWALLPAPER = 0x73;
private static int MAX_PATH = 260;
public static string GetWallpaperPath()
{
var wallpaper = new StringBuilder(MAX_PATH);
SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaper, 0);
var str = wallpaper.ToString();
if (string.IsNullOrEmpty(str))
return null;
return str;
}
public static Color GetWallpaperColor()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true);
var result = key.GetValue(@"Background", null);
if (result != null && result is string)
{
try
{
var parts = result.ToString().Trim().Split(new char[] {' '}, 3).Select(byte.Parse).ToList();
return Color.FromRgb(parts[0], parts[1], parts[2]);
}
catch
{
}
}
return Colors.Transparent;
}
}
}

View File

@ -6,7 +6,7 @@
Title="Wox Setting"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Height="407.447" Width="843.989">
Height="600" Width="800">
<TabControl Height="auto" >
<TabItem Header="Basic">
@ -172,11 +172,8 @@
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Margin="10" Grid.Column="0">
<TextBlock Text="Theme:" />
<ComboBox x:Name="themeComboBox" SelectionChanged="ThemeComboBox_OnSelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"/>
</StackPanel>
<Grid Margin="10" Grid.Column="1">
<ListBox x:Name="themeComboBox" Grid.Column="0" Margin="10" SelectionChanged="ThemeComboBox_OnSelectionChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="180"/>
<Grid Margin="0" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition ></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
@ -186,21 +183,24 @@
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Grid.ColumnSpan="2" Grid.Row="0" Margin="10">
<StackPanel.Resources>
<ResourceDictionary Source="/PresentationFramework.Classic,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Classic.xaml"/>
</StackPanel.Resources>
<Border Width="500" Style="{DynamicResource WindowBorderStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" ></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Text="Hello Wox" IsReadOnly="True" Style="{DynamicResource QueryBoxStyle}" Grid.Row="0"/>
<wox:ResultPanel Grid.Row="1" x:Name="resultPanelPreview"/>
</Grid>
</Border>
<StackPanel x:Name="PreviewPanel" Grid.ColumnSpan="2" Grid.Row="0" Margin="0">
<StackPanel Orientation="Horizontal" Margin="10" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel.Resources>
<ResourceDictionary Source="/PresentationFramework.Classic,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Classic.xaml"/>
</StackPanel.Resources>
<Border Width="500" Style="{DynamicResource WindowBorderStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" ></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Text="Hello Wox" IsReadOnly="True" Style="{DynamicResource QueryBoxStyle}" Grid.Row="0"/>
<wox:ResultPanel Grid.Row="1" x:Name="resultPanelPreview"/>
</Grid>
</Border>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="10">
<TextBlock Text="Query Box Font:" />
<ComboBox x:Name="cbQueryBoxFont" ItemsSource="{x:Static Fonts.SystemFontFamilies}" SelectionChanged="CbQueryBoxFont_OnSelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="180"/>

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using IWshRuntimeLibrary;
using Microsoft.VisualBasic.ApplicationServices;
using Wox.Infrastructure;
@ -99,7 +100,7 @@ namespace Wox
new Result()
{
Title = "Search applications",
SubTitle = "Search applications, files (via everything plugin) and chrome bookmarks",
SubTitle = "Search applications, files (via everything plugin) and browser bookmarks",
IcoPath = "Images/work.png",
PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)
},
@ -122,6 +123,20 @@ namespace Wox
SubTitle = "get more themes from http://www.getwox.com/theme",
IcoPath = "Images/work.png",
PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)
},
new Result()
{
Title = "Plugins support",
SubTitle = "get more plugins from http://www.getwox.com/plugin",
IcoPath = "Images/work.png",
PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)
},
new Result()
{
Title = "Wox is an open-source software",
SubTitle = "Wox benefits from the open-source community a lot",
IcoPath = "Images/work.png",
PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath)
}
});
@ -142,6 +157,20 @@ namespace Wox
cbEnablePythonPlugins.IsChecked = UserSettingStorage.Instance.EnablePythonPlugins;
cbStartWithWindows.IsChecked = File.Exists(woxLinkPath);
var wallpaper = WallpaperPathRetrieval.GetWallpaperPath();
if (wallpaper != null && File.Exists(wallpaper))
{
var brush = new ImageBrush(new BitmapImage(new Uri(wallpaper)));
brush.Stretch = Stretch.UniformToFill;
this.PreviewPanel.Background = brush;
}
else
{
var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor();
this.PreviewPanel.Background = new SolidColorBrush(wallpaperColor);
}
//PreviewPanel
settingsLoaded = true;
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
}
@ -366,11 +395,21 @@ namespace Wox
{
if (!settingsLoaded) return;
FamilyTypeface typeface = (FamilyTypeface) cbQueryBoxFontFaces.SelectedItem;
UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
if (typeface == null)
{
if (cbQueryBoxFontFaces.Items.Count > 0)
cbQueryBoxFontFaces.SelectedIndex = 0;
return;
}
else
{
UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
}
}
private void CbResultItemFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
@ -388,11 +427,21 @@ namespace Wox
{
if (!settingsLoaded) return;
FamilyTypeface typeface = (FamilyTypeface)cbResultItemFontFaces.SelectedItem;
UserSettingStorage.Instance.ResultItemFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
if (typeface == null)
{
if (cbResultItemFontFaces.Items.Count > 0)
cbResultItemFontFaces.SelectedIndex = 0;
return;
}
else
{
UserSettingStorage.Instance.ResultItemFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
}
}
#endregion
}

View File

@ -113,6 +113,7 @@
<Compile Include="Helper\FontHelper.cs" />
<Compile Include="Helper\Forker.cs" />
<Compile Include="Helper\SyntaxSugars.cs" />
<Compile Include="Helper\WallpaperPathRetrieval.cs" />
<Compile Include="Helper\WindowIntelopHelper.cs" />
<Compile Include="ProgramSourceSetting.xaml.cs">
<DependentUpon>ProgramSourceSetting.xaml</DependentUpon>