From 7acd254c84c0ee4d80b42523a7605711fd6f64cb Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 2 Jun 2024 11:28:58 +0800 Subject: [PATCH] Use binding --- .../ViewModels/SettingsPaneThemeViewModel.cs | 27 +++++++++-- .../Views/SettingsPaneTheme.xaml.cs | 45 +------------------ 2 files changed, 25 insertions(+), 47 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 65087c8bb..88ff93752 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -22,6 +22,7 @@ namespace Flow.Launcher.SettingPages.ViewModels; public partial class SettingsPaneThemeViewModel : BaseModel { + private const string DefaultFont = "Segoe UI"; public Settings Settings { get; } public static string LinkHowToCreateTheme => @"https://flowlauncher.com/docs/#/how-to-create-a-theme"; @@ -144,11 +145,13 @@ public partial class SettingsPaneThemeViewModel : BaseModel } public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); + public bool KeepMaxResults { get => Settings.KeepMaxResults; set => Settings.KeepMaxResults = value; } + public string ClockText => DateTime.Now.ToString(TimeFormat, CultureInfo.CurrentCulture); public string DateText => DateTime.Now.ToString(DateFormat, CultureInfo.CurrentCulture); @@ -286,7 +289,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel return fontExists switch { true => new FontFamily(Settings.QueryBoxFont), - _ => new FontFamily("Segoe UI") + _ => new FontFamily(DefaultFont) }; } set @@ -330,7 +333,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel return fontExists switch { true => new FontFamily(Settings.ResultFont), - _ => new FontFamily("Segoe UI") + _ => new FontFamily(DefaultFont) }; } set @@ -375,7 +378,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel } else { - var font = new FontFamily("Segoe UI"); + var font = new FontFamily(DefaultFont); return font; } } @@ -406,6 +409,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel ThemeManager.Instance.ChangeTheme(Settings.Theme); } } + public string ThemeImage => Constant.QueryTextBoxIconImagePath; [RelayCommand] @@ -430,4 +434,21 @@ public partial class SettingsPaneThemeViewModel : BaseModel Settings = settings; } + public void Reset() + { + SelectedQueryBoxFont = new FontFamily(DefaultFont); + SelectedQueryBoxFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal }; + QueryBoxFontSize = 20; + + SelectedResultFont = new FontFamily(DefaultFont); + SelectedResultFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal }; + ResultItemFontSize = 16; + + SelectedResultSubFont = new FontFamily(DefaultFont); + SelectedResultSubFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal }; + ResultSubItemFontSize = 13; + + WindowHeightSize = 42; + ItemHeightSize = 58; + } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index 7d412296f..022d250cf 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -33,49 +33,6 @@ public partial class SettingsPaneTheme : Page private void Reset_Click(object sender, RoutedEventArgs e) { - /*The FamilyTypeface should initialize all of its various properties.*/ - FamilyTypeface targetTypeface = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal }; - - QueryBoxFontSize.Value = 20; - QueryBoxFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", QueryBoxFontComboBox); - QueryBoxFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, QueryBoxFontStyleComboBox); - - ResultItemFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", ResultItemFontComboBox); - ResultItemFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, ResultItemFontStyleComboBox); - ResultItemFontSize.Value = 16; - - ResultSubItemFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", ResultSubItemFontComboBox); - ResultSubItemFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, ResultSubItemFontStyleComboBox); - ResultSubItemFontSize.Value = 13; - - WindowHeightValue.Value = 42; - ItemHeightValue.Value = 58; - } - - private int SearchFontIndex(string targetFont, ComboBox combo) - { - for (int i = 0; i < combo.Items.Count; i++) - { - if (combo.Items[i]?.ToString() == targetFont) - { - return i; - } - } - return 0; - } - - private int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo) - { - for (int i = 0; i < combo.Items.Count; i++) - { - if (combo.Items[i] is FamilyTypeface typefaceItem && - typefaceItem.Stretch == targetTypeface.Stretch && - typefaceItem.Weight == targetTypeface.Weight && - typefaceItem.Style == targetTypeface.Style) - { - return i; - } - } - return 0; + _viewModel.Reset(); } }