From 4e537ac4d881b51332eda27f136648c0c3c530b4 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Wed, 19 Mar 2014 22:17:01 +0800 Subject: [PATCH] #56 Add Font setting --- Wox.Infrastructure/CommonStorage.cs | 24 +++++ .../UserSettings/UserSetting.cs | 2 + Wox/MainWindow.xaml.cs | 24 +++++ Wox/SettingWindow.xaml | 47 +++++++++- Wox/SettingWindow.xaml.cs | 89 +++++++++++++++++-- Wox/Themes/Default.xaml | 3 + 6 files changed, 178 insertions(+), 11 deletions(-) diff --git a/Wox.Infrastructure/CommonStorage.cs b/Wox.Infrastructure/CommonStorage.cs index e8230ee32c..a7b5c8d2ea 100644 --- a/Wox.Infrastructure/CommonStorage.cs +++ b/Wox.Infrastructure/CommonStorage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Windows.Forms; using Newtonsoft.Json; @@ -45,6 +46,7 @@ namespace Wox.Infrastructure try { storage = JsonConvert.DeserializeObject(json); + ValidateConfigs(); } catch (Exception) { @@ -57,6 +59,28 @@ namespace Wox.Infrastructure } } + private static void ValidateConfigs() + { + try + { + new FontFamily(storage.UserSetting.QueryBoxFont); + } + catch (Exception e) + { + storage.UserSetting.QueryBoxFont = FontFamily.GenericSansSerif.Name; + + } + + try + { + new FontFamily(storage.UserSetting.ResultItemFont); + } + catch (Exception) + { + storage.UserSetting.ResultItemFont = FontFamily.GenericSansSerif.Name; + } + } + private static void LoadDefaultUserSetting() { //default setting diff --git a/Wox.Infrastructure/UserSettings/UserSetting.cs b/Wox.Infrastructure/UserSettings/UserSetting.cs index c3ac94da77..cf6795e8cc 100644 --- a/Wox.Infrastructure/UserSettings/UserSetting.cs +++ b/Wox.Infrastructure/UserSettings/UserSetting.cs @@ -7,6 +7,8 @@ namespace Wox.Infrastructure.UserSettings { public string Hotkey { get; set; } public string Theme { get; set; } + public string QueryBoxFont { get; set; } + public string ResultItemFont { get; set; } public bool ReplaceWinR { get; set; } public List WebSearches { get; set; } public List ProgramSources { get; set; } diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index e42591a8ee..a0453da390 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -8,6 +8,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; +using System.Windows.Media; using System.Windows.Media.Animation; using WindowsInput; using WindowsInput.Native; @@ -21,10 +22,12 @@ using Wox.Plugin; using Wox.PluginLoader; using Application = System.Windows.Application; using ContextMenu = System.Windows.Forms.ContextMenu; +using Control = System.Windows.Controls.Control; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MenuItem = System.Windows.Forms.MenuItem; using MessageBox = System.Windows.MessageBox; using MouseButton = System.Windows.Input.MouseButton; +using TextBox = System.Windows.Controls.TextBox; using ToolTip = System.Windows.Controls.ToolTip; namespace Wox @@ -394,6 +397,27 @@ namespace Wox Source = new Uri(Path.Combine(Directory.GetCurrentDirectory(), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) }; + + Style queryBoxStyle = dict["QueryBoxStyle"] as Style; + if (queryBoxStyle != null) + { + queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(CommonStorage.Instance.UserSetting.QueryBoxFont))); + } + Style resultItemStyle = dict["ItemTitleStyle"] as Style; + Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; + Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; + Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; + if (resultItemStyle != null && resultSubItemStyle != null + && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) + { + Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(CommonStorage.Instance.UserSetting.ResultItemFont)); + + resultItemStyle.Setters.Add(fontFamily); + resultSubItemStyle.Setters.Add(fontFamily); + resultItemSelectedStyle.Setters.Add(fontFamily); + resultSubItemSelectedStyle.Setters.Add(fontFamily); + } + Application.Current.Resources.MergedDictionaries.Clear(); Application.Current.Resources.MergedDictionaries.Add(dict); } diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 41fdbe14a2..438142fdf0 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -19,10 +19,6 @@ - - - - @@ -115,5 +111,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 1bdb638bdd..1310391c7a 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -5,9 +5,11 @@ using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Media; using IWshRuntimeLibrary; using Wox.Infrastructure; using Wox.Infrastructure.UserSettings; +using Wox.Plugin; using Application = System.Windows.Forms.Application; using File = System.IO.File; using MessageBox = System.Windows.MessageBox; @@ -57,6 +59,58 @@ namespace Wox CommonStorage.Instance.Save(); }; + #region Load Theme Data + + if (!string.IsNullOrEmpty(CommonStorage.Instance.UserSetting.QueryBoxFont) && + Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(CommonStorage.Instance.UserSetting.QueryBoxFont)) > 0) + { + cbQueryBoxFont.Text = CommonStorage.Instance.UserSetting.QueryBoxFont; + } + if (!string.IsNullOrEmpty(CommonStorage.Instance.UserSetting.ResultItemFont) && + Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(CommonStorage.Instance.UserSetting.ResultItemFont)) > 0) + { + cbResultItemFont.Text = CommonStorage.Instance.UserSetting.ResultItemFont; + } + resultPanelPreview.AddResults(new List() + { + new Result() + { + Title = "Wox is an effective launcher for windows", + SubTitle = "Wox provide bundles of features let you access infomations quickly.", + IcoPath = "Images/work.png", + PluginDirectory = AppDomain.CurrentDomain.BaseDirectory + }, + new Result() + { + Title = "Search applications", + SubTitle = "Search applications, files (via everything plugin) and chrome bookmarks", + IcoPath = "Images/work.png", + PluginDirectory = AppDomain.CurrentDomain.BaseDirectory + }, + new Result() + { + Title = "Search web contents with shortcuts", + SubTitle = "e.g. search google with g keyword or youtube keyword)", + IcoPath = "Images/work.png", + PluginDirectory = AppDomain.CurrentDomain.BaseDirectory + }, + new Result() + { + Title = "clipboard history ", + IcoPath = "Images/work.png", + PluginDirectory = AppDomain.CurrentDomain.BaseDirectory + }, + new Result() + { + Title = "Themes support", + SubTitle = "get more themes from http://www.getwox.com/theme", + IcoPath = "Images/work.png", + PluginDirectory = AppDomain.CurrentDomain.BaseDirectory + } + }); + + #endregion + foreach (string theme in LoadAvailableThemes()) { @@ -83,13 +137,7 @@ namespace Wox return Directory.GetFiles(themePath).Where(filePath => filePath.EndsWith(".xaml") && !filePath.EndsWith("Default.xaml")).ToList(); } - private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) - { - string themeName = themeComboBox.SelectedItem.ToString(); - MainWindow.SetTheme(themeName); - CommonStorage.Instance.UserSetting.Theme = themeName; - CommonStorage.Instance.Save(); - } + private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e) { @@ -231,5 +279,32 @@ namespace Wox { Process.Start("Wox.UAC.exe", "AssociatePluginInstaller"); } + + #region Theme + private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + string themeName = themeComboBox.SelectedItem.ToString(); + MainWindow.SetTheme(themeName); + CommonStorage.Instance.UserSetting.Theme = themeName; + CommonStorage.Instance.Save(); + } + + private void CbQueryBoxFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + string queryBoxFontName = cbQueryBoxFont.SelectedItem.ToString(); + CommonStorage.Instance.UserSetting.QueryBoxFont = queryBoxFontName; + CommonStorage.Instance.Save(); + App.Window.SetTheme(CommonStorage.Instance.UserSetting.Theme); + } + + private void CbResultItemFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + string resultItemFont = cbResultItemFont.SelectedItem.ToString(); + CommonStorage.Instance.UserSetting.ResultItemFont = resultItemFont; + CommonStorage.Instance.Save(); + App.Window.SetTheme(CommonStorage.Instance.UserSetting.Theme); + } + + #endregion } } diff --git a/Wox/Themes/Default.xaml b/Wox/Themes/Default.xaml index 6ce11e4848..b11b3c532c 100644 --- a/Wox/Themes/Default.xaml +++ b/Wox/Themes/Default.xaml @@ -11,6 +11,7 @@ +