Skip to content

Commit 9b9ebfc

Browse files
Merge pull request #2749 from Flow-Launcher/binding
Use binding for values introduced in Resizable PR
2 parents 27e7f0b + 7d81167 commit 9b9ebfc

File tree

3 files changed

+31
-98
lines changed

3 files changed

+31
-98
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Flow.Launcher.SettingPages.ViewModels;
2222

2323
public partial class SettingsPaneThemeViewModel : BaseModel
2424
{
25+
private const string DefaultFont = "Segoe UI";
2526
public Settings Settings { get; }
2627

2728
public static string LinkHowToCreateTheme => @"https://flowlauncher.com/docs/#/how-to-create-a-theme";
@@ -82,6 +83,7 @@ public double QueryBoxFontSize
8283
get => Settings.QueryBoxFontSize;
8384
set => Settings.QueryBoxFontSize = value;
8485
}
86+
8587
public double ResultItemFontSize
8688
{
8789
get => Settings.ResultItemFontSize;
@@ -97,30 +99,9 @@ public double ResultSubItemFontSize
9799
private List<Theme.ThemeData> _themes;
98100
public List<Theme.ThemeData> Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes();
99101

102+
public class ColorSchemeData : DropdownDataGeneric<ColorSchemes> { }
100103

101-
public class ColorScheme
102-
{
103-
public string Display { get; set; }
104-
public ColorSchemes Value { get; set; }
105-
}
106-
107-
public List<ColorScheme> ColorSchemes
108-
{
109-
get
110-
{
111-
List<ColorScheme> modes = new List<ColorScheme>();
112-
var enums = (ColorSchemes[])Enum.GetValues(typeof(ColorSchemes));
113-
foreach (var e in enums)
114-
{
115-
var key = $"ColorScheme{e}";
116-
var display = InternationalizationManager.Instance.GetTranslation(key);
117-
var m = new ColorScheme { Display = display, Value = e, };
118-
modes.Add(m);
119-
}
120-
121-
return modes;
122-
}
123-
}
104+
public List<ColorSchemeData> ColorSchemes { get; } = DropdownDataGeneric<ColorSchemes>.GetValues<ColorSchemeData>("ColorScheme");
124105

125106
public List<string> TimeFormatList { get; } = new()
126107
{
@@ -167,11 +148,13 @@ public string DateFormat
167148
}
168149

169150
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
151+
170152
public bool KeepMaxResults
171153
{
172154
get => Settings.KeepMaxResults;
173155
set => Settings.KeepMaxResults = value;
174156
}
157+
175158
public string ClockText => DateTime.Now.ToString(TimeFormat, CultureInfo.CurrentCulture);
176159

177160
public string DateText => DateTime.Now.ToString(DateFormat, CultureInfo.CurrentCulture);
@@ -188,29 +171,9 @@ public bool UseAnimation
188171
set => Settings.UseAnimation = value;
189172
}
190173

191-
public class AnimationSpeed
192-
{
193-
public string Display { get; set; }
194-
public AnimationSpeeds Value { get; set; }
195-
}
174+
public class AnimationSpeedData : DropdownDataGeneric<AnimationSpeeds> { }
175+
public List<AnimationSpeedData> AnimationSpeeds { get; } = DropdownDataGeneric<AnimationSpeeds>.GetValues<AnimationSpeedData>("AnimationSpeed");
196176

197-
public List<AnimationSpeed> AnimationSpeeds
198-
{
199-
get
200-
{
201-
List<AnimationSpeed> speeds = new List<AnimationSpeed>();
202-
var enums = (AnimationSpeeds[])Enum.GetValues(typeof(AnimationSpeeds));
203-
foreach (var e in enums)
204-
{
205-
var key = $"AnimationSpeed{e}";
206-
var display = InternationalizationManager.Instance.GetTranslation(key);
207-
var m = new AnimationSpeed { Display = display, Value = e, };
208-
speeds.Add(m);
209-
}
210-
211-
return speeds;
212-
}
213-
}
214177
public bool UseSound
215178
{
216179
get => Settings.UseSound;
@@ -329,7 +292,7 @@ public FontFamily SelectedQueryBoxFont
329292
return fontExists switch
330293
{
331294
true => new FontFamily(Settings.QueryBoxFont),
332-
_ => new FontFamily("Segoe UI")
295+
_ => new FontFamily(DefaultFont)
333296
};
334297
}
335298
set
@@ -373,7 +336,7 @@ public FontFamily SelectedResultFont
373336
return fontExists switch
374337
{
375338
true => new FontFamily(Settings.ResultFont),
376-
_ => new FontFamily("Segoe UI")
339+
_ => new FontFamily(DefaultFont)
377340
};
378341
}
379342
set
@@ -418,7 +381,7 @@ public FontFamily SelectedResultSubFont
418381
}
419382
else
420383
{
421-
var font = new FontFamily("Segoe UI");
384+
var font = new FontFamily(DefaultFont);
422385
return font;
423386
}
424387
}
@@ -449,6 +412,7 @@ public FamilyTypeface SelectedResultSubFontFaces
449412
ThemeManager.Instance.ChangeTheme(Settings.Theme);
450413
}
451414
}
415+
452416
public string ThemeImage => Constant.QueryTextBoxIconImagePath;
453417

454418
[RelayCommand]
@@ -473,4 +437,22 @@ public SettingsPaneThemeViewModel(Settings settings)
473437
Settings = settings;
474438
}
475439

440+
[RelayCommand]
441+
public void Reset()
442+
{
443+
SelectedQueryBoxFont = new FontFamily(DefaultFont);
444+
SelectedQueryBoxFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
445+
QueryBoxFontSize = 20;
446+
447+
SelectedResultFont = new FontFamily(DefaultFont);
448+
SelectedResultFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
449+
ResultItemFontSize = 16;
450+
451+
SelectedResultSubFont = new FontFamily(DefaultFont);
452+
SelectedResultSubFontFaces = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
453+
ResultSubItemFontSize = 13;
454+
455+
WindowHeightSize = 42;
456+
ItemHeightSize = 58;
457+
}
476458
}

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,8 @@
255255
<Button
256256
Margin="8"
257257
HorizontalAlignment="Stretch"
258-
Click="Reset_Click"
258+
Command="{Binding ResetCommand}"
259259
Content="{DynamicResource resetCustomize}" />
260-
261260
</StackPanel>
262261
</ScrollViewer>
263262
</Border>

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,4 @@ private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArg
3030
{
3131
_viewModel.UpdateColorScheme();
3232
}
33-
34-
private void Reset_Click(object sender, RoutedEventArgs e)
35-
{
36-
/*The FamilyTypeface should initialize all of its various properties.*/
37-
FamilyTypeface targetTypeface = new FamilyTypeface { Stretch = FontStretches.Normal, Weight = FontWeights.Normal, Style = FontStyles.Normal };
38-
39-
QueryBoxFontSize.Value = 20;
40-
QueryBoxFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", QueryBoxFontComboBox);
41-
QueryBoxFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, QueryBoxFontStyleComboBox);
42-
43-
ResultItemFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", ResultItemFontComboBox);
44-
ResultItemFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, ResultItemFontStyleComboBox);
45-
ResultItemFontSize.Value = 16;
46-
47-
ResultSubItemFontComboBox.SelectedIndex = SearchFontIndex("Segoe UI", ResultSubItemFontComboBox);
48-
ResultSubItemFontStyleComboBox.SelectedIndex = SearchFontStyleIndex(targetTypeface, ResultSubItemFontStyleComboBox);
49-
ResultSubItemFontSize.Value = 13;
50-
51-
WindowHeightValue.Value = 42;
52-
ItemHeightValue.Value = 58;
53-
}
54-
55-
private int SearchFontIndex(string targetFont, ComboBox combo)
56-
{
57-
for (int i = 0; i < combo.Items.Count; i++)
58-
{
59-
if (combo.Items[i]?.ToString() == targetFont)
60-
{
61-
return i;
62-
}
63-
}
64-
return 0;
65-
}
66-
67-
private int SearchFontStyleIndex(FamilyTypeface targetTypeface, ComboBox combo)
68-
{
69-
for (int i = 0; i < combo.Items.Count; i++)
70-
{
71-
if (combo.Items[i] is FamilyTypeface typefaceItem &&
72-
typefaceItem.Stretch == targetTypeface.Stretch &&
73-
typefaceItem.Weight == targetTypeface.Weight &&
74-
typefaceItem.Style == targetTypeface.Style)
75-
{
76-
return i;
77-
}
78-
}
79-
return 0;
80-
}
8133
}

0 commit comments

Comments
 (0)