From 5e5c64031e32adbf77ed854582cdd7c8a049b746 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 2 Jun 2024 10:49:04 +0800 Subject: [PATCH 1/3] Use new style localization --- .../ViewModels/SettingsPaneThemeViewModel.cs | 50 ++----------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 5046a4754..65087c8bb 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -80,6 +80,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel get => Settings.QueryBoxFontSize; set => Settings.QueryBoxFontSize = value; } + public double ResultItemFontSize { get => Settings.ResultItemFontSize; @@ -94,30 +95,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel public List Themes => ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList(); + public class ColorSchemeData : DropdownDataGeneric { } - public class ColorScheme - { - public string Display { get; set; } - public ColorSchemes Value { get; set; } - } - - public List ColorSchemes - { - get - { - List modes = new List(); - var enums = (ColorSchemes[])Enum.GetValues(typeof(ColorSchemes)); - foreach (var e in enums) - { - var key = $"ColorScheme{e}"; - var display = InternationalizationManager.Instance.GetTranslation(key); - var m = new ColorScheme { Display = display, Value = e, }; - modes.Add(m); - } - - return modes; - } - } + public List ColorSchemes { get; } = DropdownDataGeneric.GetValues("ColorScheme"); public List TimeFormatList { get; } = new() { @@ -185,29 +165,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel set => Settings.UseAnimation = value; } - public class AnimationSpeed - { - public string Display { get; set; } - public AnimationSpeeds Value { get; set; } - } + public class AnimationSpeedData : DropdownDataGeneric { } + public List AnimationSpeeds { get; } = DropdownDataGeneric.GetValues("AnimationSpeed"); - public List AnimationSpeeds - { - get - { - List speeds = new List(); - var enums = (AnimationSpeeds[])Enum.GetValues(typeof(AnimationSpeeds)); - foreach (var e in enums) - { - var key = $"AnimationSpeed{e}"; - var display = InternationalizationManager.Instance.GetTranslation(key); - var m = new AnimationSpeed { Display = display, Value = e, }; - speeds.Add(m); - } - - return speeds; - } - } public bool UseSound { get => Settings.UseSound; 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 2/3] 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(); } } From 7d81167bfd150b3a057f544255335f46cd1777b4 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:11:51 +0800 Subject: [PATCH 3/3] Use relay command for reset --- .../SettingPages/ViewModels/SettingsPaneThemeViewModel.cs | 1 + Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml | 3 +-- Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 88ff93752..f38c1839d 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -434,6 +434,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel Settings = settings; } + [RelayCommand] public void Reset() { SelectedQueryBoxFont = new FontFamily(DefaultFont); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml index 08b49e745..793d65c40 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml @@ -245,9 +245,8 @@