mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Databinding for theme tab
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<ISettingProvider, Control> _featureControls = new Dictionary<ISettingProvider, Control>();
|
||||
|
||||
public Tab SelectedTab { get; set; } = Tab.General;
|
||||
#region general
|
||||
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
|
||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
#endregion
|
||||
#region plugin
|
||||
public PluginViewModel SelectedPlugin { get; set; }
|
||||
public IList<PluginViewModel> 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<string> 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<Result> results = new List<Result>
|
||||
{
|
||||
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>();
|
||||
Settings = _storage.Load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//todo happlebao save
|
||||
public void Save()
|
||||
{
|
||||
_storage.Save();
|
||||
|
||||
Reference in New Issue
Block a user