Skip to content

Commit 7acd254

Browse files
Use binding
1 parent 5e5c640 commit 7acd254

File tree

2 files changed

+25
-47
lines changed

2 files changed

+25
-47
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 24 additions & 3 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";
@@ -144,11 +145,13 @@ public string DateFormat
144145
}
145146

146147
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
148+
147149
public bool KeepMaxResults
148150
{
149151
get => Settings.KeepMaxResults;
150152
set => Settings.KeepMaxResults = value;
151153
}
154+
152155
public string ClockText => DateTime.Now.ToString(TimeFormat, CultureInfo.CurrentCulture);
153156

154157
public string DateText => DateTime.Now.ToString(DateFormat, CultureInfo.CurrentCulture);
@@ -286,7 +289,7 @@ public FontFamily SelectedQueryBoxFont
286289
return fontExists switch
287290
{
288291
true => new FontFamily(Settings.QueryBoxFont),
289-
_ => new FontFamily("Segoe UI")
292+
_ => new FontFamily(DefaultFont)
290293
};
291294
}
292295
set
@@ -330,7 +333,7 @@ public FontFamily SelectedResultFont
330333
return fontExists switch
331334
{
332335
true => new FontFamily(Settings.ResultFont),
333-
_ => new FontFamily("Segoe UI")
336+
_ => new FontFamily(DefaultFont)
334337
};
335338
}
336339
set
@@ -375,7 +378,7 @@ public FontFamily SelectedResultSubFont
375378
}
376379
else
377380
{
378-
var font = new FontFamily("Segoe UI");
381+
var font = new FontFamily(DefaultFont);
379382
return font;
380383
}
381384
}
@@ -406,6 +409,7 @@ public FamilyTypeface SelectedResultSubFontFaces
406409
ThemeManager.Instance.ChangeTheme(Settings.Theme);
407410
}
408411
}
412+
409413
public string ThemeImage => Constant.QueryTextBoxIconImagePath;
410414

411415
[RelayCommand]
@@ -430,4 +434,21 @@ public SettingsPaneThemeViewModel(Settings settings)
430434
Settings = settings;
431435
}
432436

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

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

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,6 @@ private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArg
3333

3434
private void Reset_Click(object sender, RoutedEventArgs e)
3535
{
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;
36+
_viewModel.Reset();
8037
}
8138
}

0 commit comments

Comments
 (0)