diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml
index b3d4fd5bd0..0e457c5507 100644
--- a/Wox/MainWindow.xaml
+++ b/Wox/MainWindow.xaml
@@ -24,12 +24,7 @@
Left="{Binding Left, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Top="{Binding Top, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
- d:DataContext="{d:DesignInstance vm:MainViewModel, IsDesignTimeCreatable=True}">
-
-
-
-
-
+ d:DataContext="{d:DesignInstance vm:MainViewModel}">
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs
index 687e634258..253e43f0c5 100644
--- a/Wox/PublicAPIInstance.cs
+++ b/Wox/PublicAPIInstance.cs
@@ -101,8 +101,8 @@ namespace Wox
{
Application.Current.Dispatcher.Invoke(() =>
{
+ _settingsViewModel.SelectedTab = (Tab)tab;
SettingWindow sw = SingletonWindowOpener.Open(this, _settingsViewModel);
- _settingsViewModel.SelectedTab = (Tab) tab;
});
}
diff --git a/Wox/ResultListBox.xaml b/Wox/ResultListBox.xaml
index ac064d5da0..d770b20d4f 100644
--- a/Wox/ResultListBox.xaml
+++ b/Wox/ResultListBox.xaml
@@ -9,7 +9,8 @@
MaxHeight="{Binding MaxHeight}"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}"
- HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}" Margin="{Binding Margin}"
+ HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}"
+ Margin="{Binding Margin}"
Style="{DynamicResource BaseListboxStyle}" Focusable="False"
KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single"
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard"
diff --git a/Wox/ResultListBox.xaml.cs b/Wox/ResultListBox.xaml.cs
index 51e47fd211..23b70f3e32 100644
--- a/Wox/ResultListBox.xaml.cs
+++ b/Wox/ResultListBox.xaml.cs
@@ -12,15 +12,6 @@ namespace Wox
[Synchronization]
public partial class ResultListBox
{
- public void AddResults(List newRawResults)
- {
- var vm = (ResultsViewModel) DataContext;
- var newResults = newRawResults.Select(r => new ResultViewModel(r)).ToList();
- vm.Results.Update(newResults);
- vm.SelectedIndex = 0;
- }
-
-
public ResultListBox()
{
InitializeComponent();
diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml
index 9781a65cda..86a11d9716 100644
--- a/Wox/SettingWindow.xaml
+++ b/Wox/SettingWindow.xaml
@@ -12,7 +12,7 @@
WindowStartupLocation="CenterScreen"
Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown"
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}">
-
+
@@ -64,7 +64,7 @@
MouseUp="OnMorePluginsClicked" Foreground="Blue"
Text="{DynamicResource browserMorePlugins}" />
@@ -152,7 +152,7 @@
-
+
@@ -160,18 +160,18 @@
-
+
-
+
@@ -182,7 +182,9 @@
-
+
+
+
@@ -191,15 +193,13 @@
-
-
+
+
@@ -215,15 +215,14 @@
-
-
+
+
@@ -242,7 +241,7 @@
-
+
diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs
index aaf573bd08..06a4028f79 100644
--- a/Wox/SettingWindow.xaml.cs
+++ b/Wox/SettingWindow.xaml.cs
@@ -42,7 +42,6 @@ namespace Wox
DataContext = viewModel;
_viewModel = viewModel;
_api = api;
- ResultListBoxPreview.DataContext = new ResultsViewModel(_settings);
Loaded += Setting_Loaded;
}
@@ -260,189 +259,10 @@ namespace Wox
#region Theme
- private void tbMoreThemes_MouseUp(object sender, MouseButtonEventArgs e)
+ private void OnMoreThemesClick(object sender, MouseButtonEventArgs e)
{
Process.Start("http://www.getwox.com/theme");
}
-
- public void OnThemeTabSelected(object sender, RoutedEventArgs e)
- {
- Stopwatch.Debug("theme load", () =>
- {
- var s = Fonts.SystemFontFamilies;
- });
-
- if (themeTabLoaded) return;
-
- themeTabLoaded = true;
- if (!string.IsNullOrEmpty(_settings.QueryBoxFont) &&
- Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(_settings.QueryBoxFont)) > 0)
- {
- QueryBoxFont.Text = _settings.QueryBoxFont;
-
- QueryBoxFontFaces.SelectedItem =
- SyntaxSugars.CallOrRescueDefault(
- () => ((FontFamily)QueryBoxFont.SelectedItem).ConvertFromInvariantStringsOrNormal(
- _settings.QueryBoxFontStyle,
- _settings.QueryBoxFontWeight,
- _settings.QueryBoxFontStretch
- ));
- }
- if (!string.IsNullOrEmpty(_settings.ResultFont) &&
- Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(_settings.ResultFont)) > 0)
- {
- ResultFontComboBox.Text = _settings.ResultFont;
-
- ResultFontFacesComboBox.SelectedItem =
- SyntaxSugars.CallOrRescueDefault(
- () => ((FontFamily)ResultFontComboBox.SelectedItem).ConvertFromInvariantStringsOrNormal(
- _settings.ResultFontStyle,
- _settings.ResultFontWeight,
- _settings.ResultFontStretch
- ));
- }
-
- ResultListBoxPreview.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/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- },
- new Result
- {
- Title = "Search applications",
- SubTitle = "Search applications, files (via everything plugin) and browser bookmarks",
- IcoPath = "Images/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- },
- new Result
- {
- Title = "Search web contents with shortcuts",
- SubTitle = "e.g. search google with g keyword or youtube keyword)",
- IcoPath = "Images/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- },
- new Result
- {
- Title = "clipboard history ",
- IcoPath = "Images/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- },
- new Result
- {
- Title = "Themes support",
- SubTitle = "get more themes from http://www.getwox.com/theme",
- IcoPath = "Images/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- },
- new Result
- {
- Title = "Plugins support",
- SubTitle = "get more plugins from http://www.getwox.com/plugin",
- IcoPath = "Images/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- },
- new Result
- {
- Title = "Wox is an open-source software",
- SubTitle = "Wox benefits from the open-source community a lot",
- IcoPath = "Images/app.png",
- PluginDirectory = Path.GetDirectoryName(Infrastructure.Constant.ProgramDirectory)
- }
- });
-
- foreach (string theme in ThemeManager.Instance.LoadAvailableThemes())
- {
- string themeName = Path.GetFileNameWithoutExtension(theme);
- Theme.Items.Add(themeName);
- }
-
- Theme.SelectedItem = _settings.Theme;
-
- var wallpaper = WallpaperPathRetrieval.GetWallpaperPath();
- if (wallpaper != null && File.Exists(wallpaper))
- {
- var memStream = new MemoryStream(File.ReadAllBytes(wallpaper));
- var bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = memStream;
- bitmap.EndInit();
- var brush = new ImageBrush(bitmap);
- brush.Stretch = Stretch.UniformToFill;
- PreviewPanel.Background = brush;
- }
- else
- {
- var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor();
- PreviewPanel.Background = new SolidColorBrush(wallpaperColor);
- }
-
- }
-
- private void ThemeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- string themeName = Theme.SelectedItem.ToString();
- ThemeManager.Instance.ChangeTheme(themeName);
- }
-
- private void CbQueryBoxFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!settingsLoaded) return;
- string queryBoxFontName = QueryBoxFont.SelectedItem.ToString();
- _settings.QueryBoxFont = queryBoxFontName;
- QueryBoxFontFaces.SelectedItem = ((FontFamily)QueryBoxFont.SelectedItem).ChooseRegularFamilyTypeface();
- ThemeManager.Instance.ChangeTheme(_settings.Theme);
- }
-
- private void CbQueryBoxFontFaces_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!settingsLoaded) return;
- FamilyTypeface typeface = (FamilyTypeface)QueryBoxFontFaces.SelectedItem;
- if (typeface == null)
- {
- if (QueryBoxFontFaces.Items.Count > 0)
- QueryBoxFontFaces.SelectedIndex = 0;
- }
- else
- {
- _settings.QueryBoxFontStretch = typeface.Stretch.ToString();
- _settings.QueryBoxFontWeight = typeface.Weight.ToString();
- _settings.QueryBoxFontStyle = typeface.Style.ToString();
- ThemeManager.Instance.ChangeTheme(_settings.Theme);
- }
- }
-
- private void OnResultFontSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!settingsLoaded) return;
- string resultItemFont = ResultFontComboBox.SelectedItem.ToString();
- _settings.ResultFont = resultItemFont;
- ResultFontFacesComboBox.SelectedItem =
- ((FontFamily)ResultFontComboBox.SelectedItem).ChooseRegularFamilyTypeface();
- ThemeManager.Instance.ChangeTheme(_settings.Theme);
- }
-
- private void OnResultFontFacesSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!settingsLoaded) return;
- FamilyTypeface typeface = (FamilyTypeface)ResultFontFacesComboBox.SelectedItem;
- if (typeface == null)
- {
- if (ResultFontFacesComboBox.Items.Count > 0)
- ResultFontFacesComboBox.SelectedIndex = 0;
- }
- else
- {
- _settings.ResultFontStretch = typeface.Stretch.ToString();
- _settings.ResultFontWeight = typeface.Weight.ToString();
- _settings.ResultFontStyle = typeface.Style.ToString();
- ThemeManager.Instance.ChangeTheme(_settings.Theme);
- }
- }
-
#endregion
#region Plugin
diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs
index 04c08bbce1..cb8493f718 100644
--- a/Wox/ViewModel/MainViewModel.cs
+++ b/Wox/ViewModel/MainViewModel.cs
@@ -232,14 +232,14 @@ namespace Wox.ViewModel
private void InitializeResultListBox()
{
- Results = new ResultsViewModel(_settings);
+ Results = new ResultsViewModel(_settings.MaxResultsToShow);
ResultListBoxVisibility = Visibility.Collapsed;
}
private void InitializeContextMenu()
{
- ContextMenu = new ResultsViewModel(_settings);
+ ContextMenu = new ResultsViewModel(_settings.MaxResultsToShow);
ContextMenuVisibility = Visibility.Collapsed;
}
diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs
index 8320e7e0a0..288e4098bc 100644
--- a/Wox/ViewModel/ResultsViewModel.cs
+++ b/Wox/ViewModel/ResultsViewModel.cs
@@ -19,20 +19,23 @@ namespace Wox.ViewModel
private readonly object _addResultsLock = new object();
private readonly object _collectionLock = new object();
- private readonly Settings _settings;
+ public int MaxResults = 6;
- public ResultsViewModel(Settings settings)
+ public ResultsViewModel()
{
- _settings = settings;
Results = new ResultCollection();
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
}
+ public ResultsViewModel(int maxResults) : this()
+ {
+ MaxResults = maxResults;
+ }
#endregion
#region ViewModel Properties
- public int MaxHeight => _settings.MaxResultsToShow * 50;
+ public int MaxHeight => MaxResults * 50;
public int SelectedIndex
{
@@ -108,12 +111,12 @@ namespace Wox.ViewModel
public void SelectNextPage()
{
- SelectedIndex = NewIndex(SelectedIndex + _settings.MaxResultsToShow);
+ SelectedIndex = NewIndex(SelectedIndex + MaxResults);
}
public void SelectPrevPage()
{
- SelectedIndex = NewIndex(SelectedIndex - _settings.MaxResultsToShow);
+ SelectedIndex = NewIndex(SelectedIndex - MaxResults);
}
public void Clear()
diff --git a/Wox/ViewModel/SettingWindowViewModel.cs b/Wox/ViewModel/SettingWindowViewModel.cs
index cd1a21f0af..e928b2938a 100644
--- a/Wox/ViewModel/SettingWindowViewModel.cs
+++ b/Wox/ViewModel/SettingWindowViewModel.cs
@@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
using PropertyChanged;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
+using Wox.Helper;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using static System.String;
@@ -22,8 +27,11 @@ namespace Wox.ViewModel
private readonly Dictionary _featureControls = new Dictionary();
public Tab SelectedTab { get; set; } = Tab.General;
+ #region general
public List Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
public IEnumerable MaxResultsRange => Enumerable.Range(2, 16);
+ #endregion
+ #region plugin
public PluginViewModel SelectedPlugin { get; set; }
public IList PluginViewModels
{
@@ -92,16 +100,198 @@ namespace Wox.ViewModel
}
}
}
+ #endregion
+ #region theme
+ public string SelectedTheme
+ {
+ get
+ {
+ return Settings.Theme;
+ }
+ set
+ {
+ Settings.Theme = value;
+ ThemeManager.Instance.ChangeTheme(value);
+ }
+ }
+ public List Themes => ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList();
+
+ public Brush PreviewBackground
+ {
+ get
+ {
+ var wallpaper = WallpaperPathRetrieval.GetWallpaperPath();
+ if (wallpaper != null && File.Exists(wallpaper))
+ {
+ var memStream = new MemoryStream(File.ReadAllBytes(wallpaper));
+ var bitmap = new BitmapImage();
+ bitmap.BeginInit();
+ bitmap.StreamSource = memStream;
+ bitmap.EndInit();
+ var brush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill };
+ return brush;
+ }
+ else
+ {
+ var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor();
+ var brush = new SolidColorBrush(wallpaperColor);
+ return brush;
+ }
+ }
+ }
+
+ public ResultsViewModel PreviewResults
+ {
+ get
+ {
+
+ const string image = "app.png";
+ const string theme = "http://www.getwox.com/theme/builder";
+ const string plugin = "http://www.getwox.com/plugin";
+ List results = new List
+ {
+ new Result
+ {
+ Title = "WoX is a launcher for Windows that simply works.",
+ SubTitle = "You can call it Windows omni-eXecutor if you want a long name.",
+ IcoPath = image,
+ },
+ new Result
+ {
+ Title = "Search for everything—applications, folders, files and more.",
+ SubTitle = "Use pinyin to search for programs. (yyy / wangyiyun → 网易云音乐)",
+ IcoPath = image,
+ },
+ new Result
+ {
+ Title = "Keyword plugin search.",
+ SubTitle = "search google with g search_term.",
+ IcoPath = image,
+ },
+ new Result
+ {
+ Title = "Build custom themes at: ",
+ SubTitle = theme,
+ },
+ new Result
+ {
+ Title = "Install plugins from: ",
+ SubTitle = plugin,
+ IcoPath = image,
+ },
+ new Result
+ {
+ Title = $"Open Source: {Infrastructure.Constant.Github}",
+ SubTitle = "Please star it!",
+ IcoPath = image,
+ }
+ };
+ var vm = new ResultsViewModel(6);
+ vm.AddResults(results, "PREVIEW");
+ return vm;
+ }
+ }
+
+ public FontFamily SelectedQueryBoxFont
+ {
+ get
+ {
+ if (Fonts.SystemFontFamilies.Count(o =>
+ o.FamilyNames.Values != null &&
+ o.FamilyNames.Values.Contains(Settings.QueryBoxFont)) > 0)
+ {
+ var font = new FontFamily(Settings.QueryBoxFont);
+ return font;
+ }
+ else
+ {
+ var font = new FontFamily("Segoe UI");
+ return font;
+ }
+ }
+ set
+ {
+ Settings.QueryBoxFont = value.ToString();
+ ThemeManager.Instance.ChangeTheme(Settings.Theme);
+ }
+ }
+
+ public FamilyTypeface SelectedQueryBoxFontFaces
+ {
+ get
+ {
+ var typeface = SyntaxSugars.CallOrRescueDefault(
+ () => SelectedQueryBoxFont.ConvertFromInvariantStringsOrNormal(
+ Settings.QueryBoxFontStyle,
+ Settings.QueryBoxFontWeight,
+ Settings.QueryBoxFontStretch
+ ));
+ return typeface;
+ }
+ set
+ {
+ Settings.QueryBoxFontStretch = value.Stretch.ToString();
+ Settings.QueryBoxFontWeight = value.Weight.ToString();
+ Settings.QueryBoxFontStyle = value.Style.ToString();
+ ThemeManager.Instance.ChangeTheme(Settings.Theme);
+ }
+ }
+
+ public FontFamily SelectedResultFont
+ {
+ get
+ {
+ if (Fonts.SystemFontFamilies.Count(o =>
+ o.FamilyNames.Values != null &&
+ o.FamilyNames.Values.Contains(Settings.ResultFont)) > 0)
+ {
+ var font = new FontFamily(Settings.ResultFont);
+ return font;
+ }
+ else
+ {
+ var font = new FontFamily("Segoe UI");
+ return font;
+ }
+ }
+ set
+ {
+ Settings.ResultFont = value.ToString();
+ ThemeManager.Instance.ChangeTheme(Settings.Theme);
+ }
+ }
+
+ public FamilyTypeface SelectedResultFontFaces
+ {
+ get
+ {
+ var typeface = SyntaxSugars.CallOrRescueDefault(
+ () => SelectedQueryBoxFont.ConvertFromInvariantStringsOrNormal(
+ Settings.ResultFontStyle,
+ Settings.ResultFontWeight,
+ Settings.ResultFontStretch
+ ));
+ return typeface;
+ }
+ set
+ {
+ Settings.ResultFontStretch = value.Stretch.ToString();
+ Settings.ResultFontWeight = value.Weight.ToString();
+ Settings.ResultFontStyle = value.Style.ToString();
+ ThemeManager.Instance.ChangeTheme(Settings.Theme);
+ }
+ }
+
+
+ #endregion
public SettingWindowViewModel()
{
_storage = new JsonStrorage();
Settings = _storage.Load();
}
-
-
-
+ //todo happlebao save
public void Save()
{
_storage.Save();