close #48 Refactor setting storage.

This commit is contained in:
qianlifeng
2014-03-23 16:17:41 +08:00
parent fc07979966
commit 4ca0453cff
27 changed files with 319 additions and 321 deletions

View File

@@ -11,7 +11,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox
{
@@ -43,9 +44,9 @@ namespace Wox
return;
}
if (CommonStorage.Instance.UserSetting.CustomPluginHotkeys == null)
if (UserSettingStorage.Instance.CustomPluginHotkeys == null)
{
CommonStorage.Instance.UserSetting.CustomPluginHotkeys = new List<CustomPluginHotkey>();
UserSettingStorage.Instance.CustomPluginHotkeys = new List<CustomPluginHotkey>();
}
var pluginHotkey = new CustomPluginHotkey()
@@ -53,7 +54,7 @@ namespace Wox
Hotkey = ctlHotkey.CurrentHotkey.ToString(),
ActionKeyword = tbAction.Text
};
CommonStorage.Instance.UserSetting.CustomPluginHotkeys.Add(pluginHotkey);
UserSettingStorage.Instance.CustomPluginHotkeys.Add(pluginHotkey);
settingWidow.MainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString(), delegate
{
settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword);
@@ -81,14 +82,14 @@ namespace Wox
MessageBox.Show("Update successfully!");
}
CommonStorage.Instance.Save();
UserSettingStorage.Instance.Save();
settingWidow.ReloadCustomPluginHotkeyView();
Close();
}
public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = CommonStorage.Instance.UserSetting.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
updateCustomHotkey = UserSettingStorage.Instance.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
MessageBox.Show("Invalid plugin hotkey");

View File

@@ -17,7 +17,8 @@ using NHotkey.Wpf;
using Wox.Commands;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin;
using Wox.PluginLoader;
using Application = System.Windows.Application;
@@ -60,14 +61,14 @@ namespace Wox
ThreadPool.SetMaxThreads(30, 10);
try
{
SetTheme(CommonStorage.Instance.UserSetting.Theme);
SetTheme(UserSettingStorage.Instance.Theme);
}
catch (Exception)
{
SetTheme(CommonStorage.Instance.UserSetting.Theme = "Dark");
SetTheme(UserSettingStorage.Instance.Theme = "Dark");
}
SetHotkey(CommonStorage.Instance.UserSetting.Hotkey, OnHotkey);
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
SetCustomPluginHotkey();
globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
@@ -131,8 +132,8 @@ namespace Wox
private void SetCustomPluginHotkey()
{
if (CommonStorage.Instance.UserSetting.CustomPluginHotkeys == null) return;
foreach (CustomPluginHotkey hotkey in CommonStorage.Instance.UserSetting.CustomPluginHotkeys)
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
{
CustomPluginHotkey hotkey1 = hotkey;
SetHotkey(hotkey.Hotkey, delegate
@@ -285,7 +286,7 @@ namespace Wox
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
{
if (CommonStorage.Instance.UserSetting.ReplaceWinR)
if (UserSettingStorage.Instance.ReplaceWinR)
{
//todo:need refatoring. move those codes to CMD file or expose events
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
@@ -388,7 +389,8 @@ namespace Wox
{
HideWox();
}
CommonStorage.Instance.UserSelectedRecords.Add(result);
UserSelectedRecordStorage.Instance.Add(result);
UserSelectedRecordStorage.Instance.Add(result);
}
}
}
@@ -405,7 +407,7 @@ namespace Wox
list.ForEach(
o =>
{
if (o.AutoAjustScore) o.Score += CommonStorage.Instance.UserSelectedRecords.GetSelectedCount(o);
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
});
lock (locker)
{
@@ -431,7 +433,7 @@ namespace Wox
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
if (queryBoxStyle != null)
{
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(CommonStorage.Instance.UserSetting.QueryBoxFont)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
}
Style resultItemStyle = dict["ItemTitleStyle"] as Style;
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
@@ -440,7 +442,7 @@ namespace Wox
if (resultItemStyle != null && resultSubItemStyle != null
&& resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(CommonStorage.Instance.UserSetting.ResultItemFont));
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
resultItemStyle.Setters.Add(fontFamily);
resultSubItemStyle.Setters.Add(fontFamily);

View File

@@ -6,6 +6,8 @@ using System.Threading;
using Microsoft.CSharp;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin;
namespace Wox.PluginLoader
@@ -20,7 +22,7 @@ namespace Wox.PluginLoader
plugins.Clear();
BasePluginLoader.ParsePluginsConfig();
if (CommonStorage.Instance.UserSetting.EnablePythonPlugins)
if (UserSettingStorage.Instance.EnablePythonPlugins)
{
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
}

View File

@@ -13,7 +13,8 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using MessageBox = System.Windows.MessageBox;
namespace Wox
@@ -34,7 +35,7 @@ namespace Wox
public void UpdateItem(ProgramSource programSource)
{
updateProgramSource = CommonStorage.Instance.UserSetting.ProgramSources.FirstOrDefault(o => o == programSource);
updateProgramSource = UserSettingStorage.Instance.ProgramSources.FirstOrDefault(o => o == programSource);
if (updateProgramSource == null)
{
MessageBox.Show("Invalid program source");
@@ -84,17 +85,17 @@ namespace Wox
Type = type,
BonusPoints = bonusPoint
};
if (CommonStorage.Instance.UserSetting.ProgramSources.Exists(o => o.ToString() == p.ToString() && o != p))
if (UserSettingStorage.Instance.ProgramSources.Exists(o => o.ToString() == p.ToString() && o != p))
{
MessageBox.Show("Program source already exists!");
return;
}
CommonStorage.Instance.UserSetting.ProgramSources.Add(p);
UserSettingStorage.Instance.ProgramSources.Add(p);
MessageBox.Show(string.Format("Add {0} program source successfully!", p.ToString()));
}
else
{
if (CommonStorage.Instance.UserSetting.ProgramSources.Exists(o => o.ToString() == updateProgramSource.ToString() && o != updateProgramSource))
if (UserSettingStorage.Instance.ProgramSources.Exists(o => o.ToString() == updateProgramSource.ToString() && o != updateProgramSource))
{
MessageBox.Show("Program source already exists!");
return;
@@ -105,7 +106,7 @@ namespace Wox
updateProgramSource.BonusPoints = bonusPoint;
MessageBox.Show(string.Format("Update {0} program source successfully!", updateProgramSource.ToString()));
}
CommonStorage.Instance.Save();
UserSettingStorage.Instance.Save();
settingWindow.ReloadProgramSourceView();
Close();
}

View File

@@ -7,8 +7,10 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using IWshRuntimeLibrary;
using Microsoft.VisualBasic.ApplicationServices;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin;
using Application = System.Windows.Forms.Application;
using File = System.IO.File;
@@ -36,40 +38,40 @@ namespace Wox
private void Setting_Loaded(object sender, RoutedEventArgs ev)
{
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
ctlHotkey.SetHotkey(CommonStorage.Instance.UserSetting.Hotkey, false);
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
cbReplaceWinR.Checked += (o, e) =>
{
CommonStorage.Instance.UserSetting.ReplaceWinR = true;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.ReplaceWinR = true;
UserSettingStorage.Instance.Save();
};
cbReplaceWinR.Unchecked += (o, e) =>
{
CommonStorage.Instance.UserSetting.ReplaceWinR = false;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.ReplaceWinR = false;
UserSettingStorage.Instance.Save();
};
cbEnablePythonPlugins.Checked += (o, e) =>
{
CommonStorage.Instance.UserSetting.EnablePythonPlugins = true;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.EnablePythonPlugins = true;
UserSettingStorage.Instance.Save();
};
cbEnablePythonPlugins.Unchecked += (o, e) =>
{
CommonStorage.Instance.UserSetting.EnablePythonPlugins = false;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.EnablePythonPlugins = false;
UserSettingStorage.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)
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0)
{
cbQueryBoxFont.Text = CommonStorage.Instance.UserSetting.QueryBoxFont;
cbQueryBoxFont.Text = UserSettingStorage.Instance.QueryBoxFont;
}
if (!string.IsNullOrEmpty(CommonStorage.Instance.UserSetting.ResultItemFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(CommonStorage.Instance.UserSetting.ResultItemFont)) > 0)
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.ResultItemFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.ResultItemFont)) > 0)
{
cbResultItemFont.Text = CommonStorage.Instance.UserSetting.ResultItemFont;
cbResultItemFont.Text = UserSettingStorage.Instance.ResultItemFont;
}
resultPanelPreview.AddResults(new List<Result>()
{
@@ -118,12 +120,12 @@ namespace Wox
themeComboBox.Items.Add(themeName);
}
themeComboBox.SelectedItem = CommonStorage.Instance.UserSetting.Theme;
cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR;
webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches;
programSourceView.ItemsSource = CommonStorage.Instance.UserSetting.ProgramSources;
lvCustomHotkey.ItemsSource = CommonStorage.Instance.UserSetting.CustomPluginHotkeys;
cbEnablePythonPlugins.IsChecked = CommonStorage.Instance.UserSetting.EnablePythonPlugins;
themeComboBox.SelectedItem = UserSettingStorage.Instance.Theme;
cbReplaceWinR.IsChecked = UserSettingStorage.Instance.ReplaceWinR;
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches;
programSourceView.ItemsSource = UserSettingStorage.Instance.ProgramSources;
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
cbEnablePythonPlugins.IsChecked = UserSettingStorage.Instance.EnablePythonPlugins;
cbStartWithWindows.IsChecked = File.Exists(woxLinkPath);
}
@@ -158,7 +160,7 @@ namespace Wox
MessageBox.Show("Are your sure to delete " + seletedWebSearch.Title, "Delete WebSearch",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
CommonStorage.Instance.UserSetting.WebSearches.Remove(seletedWebSearch);
UserSettingStorage.Instance.WebSearches.Remove(seletedWebSearch);
webSearchView.Items.Refresh();
}
else
@@ -195,7 +197,7 @@ namespace Wox
MessageBox.Show("Are your sure to delete " + seletedProgramSource.ToString(), "Delete ProgramSource",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
CommonStorage.Instance.UserSetting.ProgramSources.Remove(seletedProgramSource);
UserSettingStorage.Instance.ProgramSources.Remove(seletedProgramSource);
programSourceView.Items.Refresh();
}
else
@@ -222,8 +224,8 @@ namespace Wox
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{
CreateStartupFolderShortcut();
CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup = true;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.StartWoxOnSystemStartup = true;
UserSettingStorage.Instance.Save();
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
@@ -233,8 +235,8 @@ namespace Wox
File.Delete(woxLinkPath);
}
CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup = false;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.StartWoxOnSystemStartup = false;
UserSettingStorage.Instance.Save();
}
private void CreateStartupFolderShortcut()
@@ -265,9 +267,9 @@ namespace Wox
MainWindow.HideApp();
}
});
MainWindow.RemoveHotkey(CommonStorage.Instance.UserSetting.Hotkey);
CommonStorage.Instance.UserSetting.Hotkey = ctlHotkey.CurrentHotkey.ToString();
CommonStorage.Instance.Save();
MainWindow.RemoveHotkey(UserSettingStorage.Instance.Hotkey);
UserSettingStorage.Instance.Hotkey = ctlHotkey.CurrentHotkey.ToString();
UserSettingStorage.Instance.Save();
}
}
@@ -280,9 +282,9 @@ namespace Wox
MessageBox.Show("Are your sure to delete " + item.Hotkey + " plugin hotkey?", "Delete Custom Plugin Hotkey",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
CommonStorage.Instance.UserSetting.CustomPluginHotkeys.Remove(item);
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh();
CommonStorage.Instance.Save();
UserSettingStorage.Instance.Save();
MainWindow.RemoveHotkey(item.Hotkey);
}
else
@@ -328,24 +330,24 @@ namespace Wox
{
string themeName = themeComboBox.SelectedItem.ToString();
MainWindow.SetTheme(themeName);
CommonStorage.Instance.UserSetting.Theme = themeName;
CommonStorage.Instance.Save();
UserSettingStorage.Instance.Theme = themeName;
UserSettingStorage.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);
UserSettingStorage.Instance.QueryBoxFont = queryBoxFontName;
UserSettingStorage.Instance.Save();
App.Window.SetTheme(UserSettingStorage.Instance.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);
UserSettingStorage.Instance.ResultItemFont = resultItemFont;
UserSettingStorage.Instance.Save();
App.Window.SetTheme(UserSettingStorage.Instance.Theme);
}
#endregion

View File

@@ -13,7 +13,8 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.UserSettings;
using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using MessageBox = System.Windows.MessageBox;
namespace Wox
@@ -32,7 +33,7 @@ namespace Wox
public void UpdateItem(WebSearch webSearch)
{
updateWebSearch = CommonStorage.Instance.UserSetting.WebSearches.FirstOrDefault(o => o == webSearch);
updateWebSearch = UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch);
if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url))
{
MessageBox.Show("Invalid web search");
@@ -92,12 +93,12 @@ namespace Wox
if (!update)
{
if (CommonStorage.Instance.UserSetting.WebSearches.Exists(o => o.ActionWord == action))
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action))
{
MessageBox.Show("ActionWord has existed, please input a new one.");
return;
}
CommonStorage.Instance.UserSetting.WebSearches.Add(new WebSearch()
UserSettingStorage.Instance.WebSearches.Add(new WebSearch()
{
ActionWord = action,
Enabled = cbEnable.IsChecked ?? false,
@@ -109,7 +110,7 @@ namespace Wox
}
else
{
if (CommonStorage.Instance.UserSetting.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch))
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == action && o != updateWebSearch))
{
MessageBox.Show("ActionWord has existed, please input a new one.");
return;
@@ -121,7 +122,7 @@ namespace Wox
updateWebSearch.Title= title;
MessageBox.Show(string.Format("Update {0} web search successfully!", title));
}
CommonStorage.Instance.Save();
UserSettingStorage.Instance.Save();
settingWindow.ReloadWebSearchView();
Close();
}

View File

@@ -341,6 +341,14 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Images\websearch\google.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\websearch\wiki.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>