mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Databinding for theme tab
This commit is contained in:
@@ -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<Result>
|
||||
{
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user