Use variable instead of global static method

1. introduce variable
2. part of #389
3. refactoring program suffix in program plugin
4. 全局变量一时爽,代码重构火葬场
This commit is contained in:
bao-qian
2016-03-28 03:09:57 +01:00
parent c596039453
commit b22a4501cc
36 changed files with 402 additions and 343 deletions

View File

@@ -10,11 +10,13 @@ namespace Wox
public partial class ActionKeywords : Window
{
private PluginPair _plugin;
private UserSettingStorage _settings;
public ActionKeywords(string pluginId)
public ActionKeywords(string pluginId, UserSettingStorage settings)
{
InitializeComponent();
_plugin = PluginManager.GetPluginForId(pluginId);
_settings = settings;
if (_plugin == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
@@ -48,7 +50,7 @@ namespace Wox
return;
}
// update persistant data
UserSettingStorage.Instance.UpdateActionKeyword(_plugin.Metadata);
_settings.UpdateActionKeyword(_plugin.Metadata);
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
Close();

View File

@@ -8,6 +8,7 @@ using System.Threading;
using System.Windows;
using Wox.CommandArgs;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure;
@@ -49,17 +50,21 @@ namespace Wox
PluginManager.Initialize();
UserSettingStorage settings = UserSettingStorage.Instance;
// happlebao temp fix for instance code logic
HttpProxy.Instance.Settings = settings;
InternationalizationManager.Instance.Settings = settings;
ThemeManager.Instance.Settings = settings;
MainViewModel mainVM = new MainViewModel(settings);
API = new PublicAPIInstance(mainVM);
API = new PublicAPIInstance(mainVM, settings);
PluginManager.InitializePlugins(API);
Window = new MainWindow {DataContext = mainVM};
Window = new MainWindow (settings, mainVM);
NotifyIconManager notifyIconManager = new NotifyIconManager(API);
CommandArgsFactory.Execute(e.Args.ToList());
// happlebao todo: the whole setting releated initialization should be put into seperate class/method
API.SetHotkey(UserSettingStorage.Instance.Hotkey, API.OnHotkey);
API.SetCustomPluginHotkey();
});
}

View File

@@ -12,14 +12,16 @@ namespace Wox
{
public partial class CustomQueryHotkeySetting : Window
{
private SettingWindow settingWidow;
private SettingWindow _settingWidow;
private bool update;
private CustomPluginHotkey updateCustomHotkey;
private UserSettingStorage _settings;
public CustomQueryHotkeySetting(SettingWindow settingWidow)
public CustomQueryHotkeySetting(SettingWindow settingWidow, UserSettingStorage settings)
{
this.settingWidow = settingWidow;
_settingWidow = settingWidow;
InitializeComponent();
_settings = settings;
}
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
@@ -37,9 +39,9 @@ namespace Wox
return;
}
if (UserSettingStorage.Instance.CustomPluginHotkeys == null)
if (_settings.CustomPluginHotkeys == null)
{
UserSettingStorage.Instance.CustomPluginHotkeys = new List<CustomPluginHotkey>();
_settings.CustomPluginHotkeys = new List<CustomPluginHotkey>();
}
var pluginHotkey = new CustomPluginHotkey
@@ -47,7 +49,7 @@ namespace Wox
Hotkey = ctlHotkey.CurrentHotkey.ToString(),
ActionKeyword = tbAction.Text
};
UserSettingStorage.Instance.CustomPluginHotkeys.Add(pluginHotkey);
_settings.CustomPluginHotkeys.Add(pluginHotkey);
SetHotkey(ctlHotkey.CurrentHotkey, delegate
{
@@ -76,14 +78,14 @@ namespace Wox
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
}
UserSettingStorage.Instance.Save();
settingWidow.ReloadCustomPluginHotkeyView();
_settings.Save();
_settingWidow.ReloadCustomPluginHotkeyView();
Close();
}
public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = UserSettingStorage.Instance.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));

View File

@@ -4,17 +4,17 @@ using System.Windows;
namespace Wox.Helper
{
public static class SingletonWindowOpener
{
public static T Open<T>(params object[] args) where T : Window
{
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetType() == typeof(T))
?? (T)Activator.CreateInstance(typeof(T), args);
public static class SingletonWindowOpener
{
public static T Open<T>(params object[] args) where T : Window
{
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetType() == typeof(T))
?? (T)Activator.CreateInstance(typeof(T), args);
App.API.HideApp();
window.Show();
window.Focus();
return (T)window;
}
}
window.Show();
window.Focus();
return (T)window;
}
}
}

View File

@@ -36,6 +36,13 @@ namespace Wox.ImageLoader
".appref-ms"
};
private static ImageCacheStroage _imageCache;
static ImageLoader()
{
_imageCache = ImageCacheStroage.Instance;
}
private static ImageSource GetIcon(string fileName)
{
try
@@ -56,7 +63,7 @@ namespace Wox.ImageLoader
public static void PreloadImages()
{
//ImageCacheStroage.Instance.TopUsedImages can be changed during foreach, so we need to make a copy
var imageList = new Dictionary<string, int>(ImageCacheStroage.Instance.TopUsedImages);
var imageList = new Dictionary<string, int>(_imageCache.TopUsedImages);
Stopwatch.Debug($"Preload {imageList.Count} images", () =>
{
foreach (var image in imageList)
@@ -87,7 +94,7 @@ namespace Wox.ImageLoader
if (addToCache)
{
ImageCacheStroage.Instance.Add(path);
_imageCache.Add(path);
}

View File

@@ -37,9 +37,9 @@
PreviewDragOver="OnPreviewDragOver"
AllowDrop="True"
x:Name="QueryTextBox" />
<Line Style="{DynamicResource PendingLineStyle}" x:Name="progressBar" Y1="0" Y2="0" X2="100" Height="2"
<Line Style="{DynamicResource PendingLineStyle}" x:Name="ProgressBar" Y1="0" Y2="0" X2="100" Height="2"
StrokeThickness="1"
Visibility="{Binding ProgressBarVisibility}">
Visibility="{Binding ProgressBarVisibility}" HorizontalAlignment="Right" Width="752">
<Line.ToolTip>
<ToolTip IsOpen="{Binding IsProgressBarTooltipVisible}" />
</Line.ToolTip>

View File

@@ -25,27 +25,33 @@ namespace Wox
#region Private Fields
private readonly Storyboard _progressBarStoryboard = new Storyboard();
private UserSettingStorage _settings;
#endregion
public MainWindow(UserSettingStorage settings, MainViewModel mainVM)
{
DataContext = mainVM;
InitializeComponent();
_settings = settings;
}
public MainWindow()
{
InitializeComponent();
}
private void OnClosing(object sender, CancelEventArgs e)
{
UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save();
_settings.WindowLeft = Left;
_settings.WindowTop = Top;
_settings.Save();
}
private void OnLoaded(object sender, RoutedEventArgs _)
{
CheckUpdate();
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
ThemeManager.Instance.ChangeTheme(_settings.Theme);
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
InitProgressbarAnimation();
WindowIntelopHelper.DisableControlBox(this);
@@ -65,13 +71,13 @@ namespace Wox
QueryTextBox.Focus();
Left = GetWindowsLeft();
Top = GetWindowsTop();
UserSettingStorage.Instance.IncreaseActivateTimes();
_settings.IncreaseActivateTimes();
}
else
{
UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save();
_settings.WindowLeft = Left;
_settings.WindowTop = Top;
_settings.Save();
}
};
@@ -83,9 +89,9 @@ namespace Wox
private double GetWindowsLeft()
{
if (UserSettingStorage.Instance.RememberLastLaunchLocation)
if (_settings.RememberLastLaunchLocation)
{
return UserSettingStorage.Instance.WindowLeft;
return _settings.WindowLeft;
}
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
@@ -97,9 +103,9 @@ namespace Wox
private double GetWindowsTop()
{
if (UserSettingStorage.Instance.RememberLastLaunchLocation)
if (_settings.RememberLastLaunchLocation)
{
return UserSettingStorage.Instance.WindowTop;
return _settings.WindowTop;
}
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
@@ -132,15 +138,15 @@ namespace Wox
private void InitProgressbarAnimation()
{
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
_progressBarStoryboard.Children.Add(da);
_progressBarStoryboard.Children.Add(da1);
_progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
progressBar.Visibility = Visibility.Hidden;
progressBar.BeginStoryboard(_progressBarStoryboard);
ProgressBar.Visibility = Visibility.Hidden;
ProgressBar.BeginStoryboard(_progressBarStoryboard);
}
private void OnMouseDown(object sender, MouseButtonEventArgs e)
@@ -150,7 +156,7 @@ namespace Wox
private void OnDeactivated(object sender, EventArgs e)
{
if (UserSettingStorage.Instance.HideWhenDeactive)
if (_settings.HideWhenDeactive)
{
App.API.HideApp();
}

View File

@@ -22,11 +22,15 @@ namespace Wox
private UserSettingStorage _settings;
#region Constructor
public PublicAPIInstance(MainViewModel mainVM)
public PublicAPIInstance(MainViewModel mainVM, UserSettingStorage settings)
{
MainVM = mainVM;
_settings = settings;
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
SetHotkey(_settings.Hotkey, OnHotkey);
SetCustomPluginHotkey();
}
#endregion
@@ -94,7 +98,7 @@ namespace Wox
{
Application.Current.Dispatcher.Invoke(() =>
{
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this);
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settings);
sw.SwitchTo(tabName);
});
}
@@ -206,7 +210,7 @@ namespace Wox
private bool ShouldIgnoreHotkeys()
{
//double if to omit calling win32 function
if (UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen)
if (_settings.IgnoreHotkeysOnFullscreen)
if (WindowIntelopHelper.IsWindowFullscreen())
return true;
@@ -215,8 +219,8 @@ namespace Wox
internal void SetCustomPluginHotkey()
{
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
if (_settings.CustomPluginHotkeys == null) return;
foreach (CustomPluginHotkey hotkey in _settings.CustomPluginHotkeys)
{
CustomPluginHotkey hotkey1 = hotkey;
SetHotkey(hotkey.Hotkey, delegate

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Windows;
using System.Windows.Controls;
using Wox.Plugin;
using Wox.ViewModel;
@@ -9,10 +11,12 @@ namespace Wox
[Synchronization]
public partial class ResultListBox
{
public void AddResults(List<Result> newResults, string resultId)
public void AddResults(List<Result> newRawResults)
{
var vm = DataContext as ResultsViewModel;
vm.AddResults(newResults, resultId);
var newResults = newRawResults.Select(r => new ResultViewModel(r)).ToList();
vm.Results.Update(newResults);
vm.SelectedResult = vm.Results[0];
}

View File

@@ -32,12 +32,14 @@ namespace Wox
bool settingsLoaded;
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
private bool themeTabLoaded;
private UserSettingStorage _settings;
public SettingWindow(IPublicAPI api)
public SettingWindow(IPublicAPI api, UserSettingStorage settings)
{
_api = api;
InitializeComponent();
ResultListBoxPreview.DataContext = new ResultsViewModel();
_settings = settings;
_api = api;
ResultListBoxPreview.DataContext = new ResultsViewModel(_settings, null);
Loaded += Setting_Loaded;
}
@@ -46,70 +48,70 @@ namespace Wox
#region General
cbHideWhenDeactive.Checked += (o, e) =>
{
UserSettingStorage.Instance.HideWhenDeactive = true;
UserSettingStorage.Instance.Save();
_settings.HideWhenDeactive = true;
_settings.Save();
};
cbHideWhenDeactive.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.HideWhenDeactive = false;
UserSettingStorage.Instance.Save();
_settings.HideWhenDeactive = false;
_settings.Save();
};
cbRememberLastLocation.Checked += (o, e) =>
{
UserSettingStorage.Instance.RememberLastLaunchLocation = true;
UserSettingStorage.Instance.Save();
_settings.RememberLastLaunchLocation = true;
_settings.Save();
};
cbRememberLastLocation.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.RememberLastLaunchLocation = false;
UserSettingStorage.Instance.Save();
_settings.RememberLastLaunchLocation = false;
_settings.Save();
};
cbDontPromptUpdateMsg.Checked += (o, e) =>
{
UserSettingStorage.Instance.DontPromptUpdateMsg = true;
UserSettingStorage.Instance.Save();
_settings.DontPromptUpdateMsg = true;
_settings.Save();
};
cbDontPromptUpdateMsg.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.DontPromptUpdateMsg = false;
UserSettingStorage.Instance.Save();
_settings.DontPromptUpdateMsg = false;
_settings.Save();
};
cbIgnoreHotkeysOnFullscreen.Checked += (o, e) =>
{
UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen = true;
UserSettingStorage.Instance.Save();
_settings.IgnoreHotkeysOnFullscreen = true;
_settings.Save();
};
cbIgnoreHotkeysOnFullscreen.Unchecked += (o, e) =>
{
UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen = false;
UserSettingStorage.Instance.Save();
_settings.IgnoreHotkeysOnFullscreen = false;
_settings.Save();
};
cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow();
comboMaxResultsToShow.SelectionChanged += (o, e) =>
{
UserSettingStorage.Instance.MaxResultsToShow = (int)comboMaxResultsToShow.SelectedItem;
UserSettingStorage.Instance.Save();
_settings.MaxResultsToShow = (int)comboMaxResultsToShow.SelectedItem;
_settings.Save();
//MainWindow.pnlResult.lbResults.GetBindingExpression(MaxHeightProperty).UpdateTarget();
};
cbHideWhenDeactive.IsChecked = UserSettingStorage.Instance.HideWhenDeactive;
cbDontPromptUpdateMsg.IsChecked = UserSettingStorage.Instance.DontPromptUpdateMsg;
cbRememberLastLocation.IsChecked = UserSettingStorage.Instance.RememberLastLaunchLocation;
cbIgnoreHotkeysOnFullscreen.IsChecked = UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen;
cbHideWhenDeactive.IsChecked = _settings.HideWhenDeactive;
cbDontPromptUpdateMsg.IsChecked = _settings.DontPromptUpdateMsg;
cbRememberLastLocation.IsChecked = _settings.RememberLastLaunchLocation;
cbIgnoreHotkeysOnFullscreen.IsChecked = _settings.IgnoreHotkeysOnFullscreen;
LoadLanguages();
comboMaxResultsToShow.ItemsSource = Enumerable.Range(2, 16);
var maxResults = UserSettingStorage.Instance.MaxResultsToShow;
var maxResults = _settings.MaxResultsToShow;
comboMaxResultsToShow.SelectedItem = maxResults == 0 ? 6 : maxResults;
#endregion
@@ -118,15 +120,15 @@ namespace Wox
cbEnableProxy.Checked += (o, e) => EnableProxy();
cbEnableProxy.Unchecked += (o, e) => DisableProxy();
cbEnableProxy.IsChecked = UserSettingStorage.Instance.ProxyEnabled;
tbProxyServer.Text = UserSettingStorage.Instance.ProxyServer;
if (UserSettingStorage.Instance.ProxyPort != 0)
cbEnableProxy.IsChecked = _settings.ProxyEnabled;
tbProxyServer.Text = _settings.ProxyServer;
if (_settings.ProxyPort != 0)
{
tbProxyPort.Text = UserSettingStorage.Instance.ProxyPort.ToString();
tbProxyPort.Text = _settings.ProxyPort.ToString();
}
tbProxyUserName.Text = UserSettingStorage.Instance.ProxyUserName;
tbProxyPassword.Password = UserSettingStorage.Instance.ProxyPassword;
if (UserSettingStorage.Instance.ProxyEnabled)
tbProxyUserName.Text = _settings.ProxyUserName;
tbProxyPassword.Password = _settings.ProxyPassword;
if (_settings.ProxyEnabled)
{
EnableProxy();
}
@@ -141,7 +143,7 @@ namespace Wox
tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString();
string activateTimes = string.Format(InternationalizationManager.Instance.GetTranslation("about_activate_times"),
UserSettingStorage.Instance.ActivateTimes);
_settings.ActivateTimes);
tbActivatedTimes.Text = activateTimes;
#endregion
@@ -200,7 +202,7 @@ namespace Wox
cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.DisplayMemberPath = "Display";
cbLanguages.SelectedValuePath = "LanguageCode";
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
cbLanguages.SelectedValue = _settings.Language;
cbLanguages.SelectionChanged += cbLanguages_SelectionChanged;
}
@@ -212,15 +214,15 @@ namespace Wox
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
{
AddApplicationToStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = true;
UserSettingStorage.Instance.Save();
_settings.StartWoxOnSystemStartup = true;
_settings.Save();
}
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
{
RemoveApplicationFromStartup();
UserSettingStorage.Instance.StartWoxOnSystemStartup = false;
UserSettingStorage.Instance.Save();
_settings.StartWoxOnSystemStartup = false;
_settings.Save();
}
private void AddApplicationToStartup()
@@ -266,9 +268,9 @@ namespace Wox
_api.HideApp();
}
});
RemoveHotkey(UserSettingStorage.Instance.Hotkey);
UserSettingStorage.Instance.Hotkey = ctlHotkey.CurrentHotkey.ToString();
UserSettingStorage.Instance.Save();
RemoveHotkey(_settings.Hotkey);
_settings.Hotkey = ctlHotkey.CurrentHotkey.ToString();
_settings.Save();
}
}
@@ -297,8 +299,8 @@ namespace Wox
private void OnHotkeyTabSelected()
{
ctlHotkey.HotkeyChanged += ctlHotkey_OnHotkeyChanged;
ctlHotkey.SetHotkey(UserSettingStorage.Instance.Hotkey, false);
lvCustomHotkey.ItemsSource = UserSettingStorage.Instance.CustomPluginHotkeys;
ctlHotkey.SetHotkey(_settings.Hotkey, false);
lvCustomHotkey.ItemsSource = _settings.CustomPluginHotkeys;
}
private void BtnDeleteCustomHotkey_OnClick(object sender, RoutedEventArgs e)
@@ -313,9 +315,9 @@ namespace Wox
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
_settings.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh();
UserSettingStorage.Instance.Save();
_settings.Save();
RemoveHotkey(item.Hotkey);
}
}
@@ -325,7 +327,7 @@ namespace Wox
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item != null)
{
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this);
CustomQueryHotkeySetting window = new CustomQueryHotkeySetting(this, _settings);
window.UpdateItem(item);
window.ShowDialog();
}
@@ -337,7 +339,7 @@ namespace Wox
private void BtnAddCustomeHotkey_OnClick(object sender, RoutedEventArgs e)
{
new CustomQueryHotkeySetting(this).ShowDialog();
new CustomQueryHotkeySetting(this, _settings).ShowDialog();
}
public void ReloadCustomPluginHotkeyView()
@@ -364,26 +366,26 @@ namespace Wox
if (themeTabLoaded) return;
themeTabLoaded = true;
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.QueryBoxFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.QueryBoxFont)) > 0)
if (!string.IsNullOrEmpty(_settings.QueryBoxFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(_settings.QueryBoxFont)) > 0)
{
cbQueryBoxFont.Text = UserSettingStorage.Instance.QueryBoxFont;
cbQueryBoxFont.Text = _settings.QueryBoxFont;
cbQueryBoxFontFaces.SelectedItem = SyntaxSugars.CallOrRescueDefault(() => ((FontFamily)cbQueryBoxFont.SelectedItem).ConvertFromInvariantStringsOrNormal(
UserSettingStorage.Instance.QueryBoxFontStyle,
UserSettingStorage.Instance.QueryBoxFontWeight,
UserSettingStorage.Instance.QueryBoxFontStretch
_settings.QueryBoxFontStyle,
_settings.QueryBoxFontWeight,
_settings.QueryBoxFontStretch
));
}
if (!string.IsNullOrEmpty(UserSettingStorage.Instance.ResultFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(UserSettingStorage.Instance.ResultFont)) > 0)
if (!string.IsNullOrEmpty(_settings.ResultFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(_settings.ResultFont)) > 0)
{
ResultFontComboBox.Text = UserSettingStorage.Instance.ResultFont;
ResultFontComboBox.Text = _settings.ResultFont;
ResultFontFacesComboBox.SelectedItem = SyntaxSugars.CallOrRescueDefault(() => ((FontFamily)ResultFontComboBox.SelectedItem).ConvertFromInvariantStringsOrNormal(
UserSettingStorage.Instance.ResultFontStyle,
UserSettingStorage.Instance.ResultFontWeight,
UserSettingStorage.Instance.ResultFontStretch
_settings.ResultFontStyle,
_settings.ResultFontWeight,
_settings.ResultFontStretch
));
}
@@ -437,15 +439,15 @@ namespace Wox
IcoPath = "Images/app.png",
PluginDirectory = Path.GetDirectoryName(Application.ExecutablePath)
}
}, "test id");
});
foreach (string theme in ThemeManager.Theme.LoadAvailableThemes())
foreach (string theme in ThemeManager.Instance.LoadAvailableThemes())
{
string themeName = Path.GetFileNameWithoutExtension(theme);
themeComboBox.Items.Add(themeName);
}
themeComboBox.SelectedItem = UserSettingStorage.Instance.Theme;
themeComboBox.SelectedItem = _settings.Theme;
var wallpaper = WallpaperPathRetrieval.GetWallpaperPath();
if (wallpaper != null && File.Exists(wallpaper))
@@ -470,17 +472,17 @@ namespace Wox
private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
string themeName = themeComboBox.SelectedItem.ToString();
ThemeManager.Theme.ChangeTheme(themeName);
ThemeManager.Instance.ChangeTheme(themeName);
}
private void CbQueryBoxFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!settingsLoaded) return;
string queryBoxFontName = cbQueryBoxFont.SelectedItem.ToString();
UserSettingStorage.Instance.QueryBoxFont = queryBoxFontName;
_settings.QueryBoxFont = queryBoxFontName;
cbQueryBoxFontFaces.SelectedItem = ((FontFamily)cbQueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface();
UserSettingStorage.Instance.Save();
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
_settings.Save();
ThemeManager.Instance.ChangeTheme(_settings.Theme);
}
private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -494,11 +496,11 @@ namespace Wox
}
else
{
UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
_settings.QueryBoxFontStretch = typeface.Stretch.ToString();
_settings.QueryBoxFontWeight = typeface.Weight.ToString();
_settings.QueryBoxFontStyle = typeface.Style.ToString();
_settings.Save();
ThemeManager.Instance.ChangeTheme(_settings.Theme);
}
}
@@ -506,10 +508,10 @@ namespace Wox
{
if (!settingsLoaded) return;
string resultItemFont = ResultFontComboBox.SelectedItem.ToString();
UserSettingStorage.Instance.ResultFont = resultItemFont;
_settings.ResultFont = resultItemFont;
ResultFontFacesComboBox.SelectedItem = ((FontFamily)ResultFontComboBox.SelectedItem).ChooseRegularFamilyTypeface();
UserSettingStorage.Instance.Save();
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
_settings.Save();
ThemeManager.Instance.ChangeTheme(_settings.Theme);
}
private void OnResultFontFacesSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -523,11 +525,11 @@ namespace Wox
}
else
{
UserSettingStorage.Instance.ResultFontStretch = typeface.Stretch.ToString();
UserSettingStorage.Instance.ResultFontWeight = typeface.Weight.ToString();
UserSettingStorage.Instance.ResultFontStyle = typeface.Style.ToString();
UserSettingStorage.Instance.Save();
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
_settings.ResultFontStretch = typeface.Stretch.ToString();
_settings.ResultFontWeight = typeface.Weight.ToString();
_settings.ResultFontStyle = typeface.Style.ToString();
_settings.Save();
ThemeManager.Instance.ChangeTheme(_settings.Theme);
}
}
@@ -567,7 +569,7 @@ namespace Wox
pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[pluginId];
var customizedPluginConfig = _settings.CustomizedPluginConfigs[pluginId];
cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled;
PluginContentPanel.Content = null;
@@ -585,7 +587,7 @@ namespace Wox
// update in-memory data
PluginManager.UpdateActionKeywordForPlugin(pair, e.OldActionKeyword, e.NewActionKeyword);
// update persistant data
UserSettingStorage.Instance.UpdateActionKeyword(pair.Metadata);
_settings.UpdateActionKeyword(pair.Metadata);
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
};
@@ -615,11 +617,11 @@ namespace Wox
id = pair.Metadata.ID;
name = pair.Metadata.Name;
}
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[id];
var customizedPluginConfig = _settings.CustomizedPluginConfigs[id];
if (customizedPluginConfig == null)
{
// todo when this part will be invoked
UserSettingStorage.Instance.CustomizedPluginConfigs[id] = new CustomizedPluginConfig
_settings.CustomizedPluginConfigs[id] = new CustomizedPluginConfig
{
Disabled = cbDisabled.IsChecked ?? true,
ID = id,
@@ -631,7 +633,7 @@ namespace Wox
{
customizedPluginConfig.Disabled = cbDisabled.IsChecked ?? true;
}
UserSettingStorage.Instance.Save();
_settings.Save();
}
private void PluginActionKeywords_OnMouseUp(object sender, MouseButtonEventArgs e)
@@ -643,7 +645,7 @@ namespace Wox
{
//third-party plugin
string id = pair.Metadata.ID;
ActionKeywords changeKeywordsWindow = new ActionKeywords(id);
ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings);
changeKeywordsWindow.ShowDialog();
PluginPair plugin = PluginManager.GetPluginForId(id);
if (plugin != null) pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords.ToArray());
@@ -716,10 +718,10 @@ namespace Wox
#region Proxy
private void btnSaveProxy_Click(object sender, RoutedEventArgs e)
{
UserSettingStorage.Instance.ProxyEnabled = cbEnableProxy.IsChecked ?? false;
_settings.ProxyEnabled = cbEnableProxy.IsChecked ?? false;
int port = 80;
if (UserSettingStorage.Instance.ProxyEnabled)
if (_settings.ProxyEnabled)
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
@@ -738,11 +740,11 @@ namespace Wox
}
}
UserSettingStorage.Instance.ProxyServer = tbProxyServer.Text;
UserSettingStorage.Instance.ProxyPort = port;
UserSettingStorage.Instance.ProxyUserName = tbProxyUserName.Text;
UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password;
UserSettingStorage.Instance.Save();
_settings.ProxyServer = tbProxyServer.Text;
_settings.ProxyPort = port;
_settings.ProxyUserName = tbProxyUserName.Text;
_settings.ProxyPassword = tbProxyPassword.Password;
_settings.Save();
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("saveProxySuccessfully"));
}

View File

@@ -51,13 +51,19 @@ namespace Wox.ViewModel
_queryText = "";
_lastQuery = new Query();
_settings = settings;
_queryHistory = QueryHistoryStorage.Instance;
_userSelectedRecord = UserSelectedRecordStorage.Instance;
_topMostRecord = TopMostRecordStorage.Instance;
InitializeResultListBox();
InitializeContextMenu();
InitializeKeyCommands();
_queryHistory = QueryHistoryStorage.Instance;
_userSelectedRecord = UserSelectedRecordStorage.Instance;
_topMostRecord = TopMostRecordStorage.Instance;
}
public MainViewModel()
{
}
#endregion
@@ -331,14 +337,14 @@ namespace Wox.ViewModel
private void InitializeResultListBox()
{
Results = new ResultsViewModel();
Results = new ResultsViewModel(_settings, _topMostRecord);
ResultListBoxVisibility = Visibility.Collapsed;
}
private void InitializeContextMenu()
{
ContextMenu = new ResultsViewModel();
ContextMenu = new ResultsViewModel(_settings, _topMostRecord);
ContextMenuVisibility = Visibility.Collapsed;
}

View File

@@ -20,12 +20,20 @@ namespace Wox.ViewModel
private Thickness _margin;
private readonly object _resultsUpdateLock = new object();
private UserSettingStorage _settings;
private TopMostRecordStorage _topMostRecord;
public ResultsViewModel(UserSettingStorage settings, TopMostRecordStorage topMostRecord)
{
_settings = settings;
_topMostRecord = topMostRecord;
}
#endregion
#region ViewModel Properties
public int MaxHeight => UserSettingStorage.Instance.MaxResultsToShow * 50;
public int MaxHeight => _settings.MaxResultsToShow * 50;
public ResultViewModel SelectedResult
{
@@ -75,7 +83,7 @@ namespace Wox.ViewModel
private bool IsTopMostResult(Result result)
{
return TopMostRecordStorage.Instance.IsTopMost(result);
return _topMostRecord.IsTopMost(result);
}
private int InsertIndexOf(int newScore, IList<ResultViewModel> list)