Skip to content

Commit 3da3c59

Browse files
authored
Merge pull request #3470 from onesounds/250412-SettingWindowFont
Add Setting for Changing Font in Settings Window
2 parents dbe3bd5 + f4f8e9a commit 3da3c59

15 files changed

+183
-104
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Save()
3131
{
3232
_storage.Save();
3333
}
34-
34+
3535
private string _theme = Constant.DefaultTheme;
3636
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
3737
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
@@ -103,6 +103,20 @@ public string Theme
103103
public bool ShowBadges { get; set; } = false;
104104
public bool ShowBadgesGlobalOnly { get; set; } = false;
105105

106+
private string _settingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
107+
public string SettingWindowFont
108+
{
109+
get => _settingWindowFont;
110+
set
111+
{
112+
if (_settingWindowFont != value)
113+
{
114+
_settingWindowFont = value;
115+
OnPropertyChanged();
116+
}
117+
}
118+
}
119+
106120
public bool UseClock { get; set; } = true;
107121
public bool UseDate { get; set; } = false;
108122
public string TimeFormat { get; set; } = "hh:mm tt";

Flow.Launcher.Infrastructure/Win32Helper.cs

+22-10
Original file line numberDiff line numberDiff line change
@@ -628,21 +628,33 @@ public static void OpenImeSettings()
628628
{ "pt", "Noto Sans" }
629629
};
630630

631-
public static string GetSystemDefaultFont()
631+
/// <summary>
632+
/// Gets the system default font.
633+
/// </summary>
634+
/// <param name="useNoto">
635+
/// If true, it will try to find the Noto font for the current culture.
636+
/// </param>
637+
/// <returns>
638+
/// The name of the system default font.
639+
/// </returns>
640+
public static string GetSystemDefaultFont(bool useNoto = true)
632641
{
633642
try
634643
{
635-
var culture = CultureInfo.CurrentCulture;
636-
var language = culture.Name; // e.g., "zh-TW"
637-
var langPrefix = language.Split('-')[0]; // e.g., "zh"
638-
639-
// First, try to find by full name, and if not found, fallback to prefix
640-
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
644+
if (useNoto)
641645
{
642-
// If the font is installed, return it
643-
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
646+
var culture = CultureInfo.CurrentCulture;
647+
var language = culture.Name; // e.g., "zh-TW"
648+
var langPrefix = language.Split('-')[0]; // e.g., "zh"
649+
650+
// First, try to find by full name, and if not found, fallback to prefix
651+
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
644652
{
645-
return notoFont;
653+
// If the font is installed, return it
654+
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
655+
{
656+
return notoFont;
657+
}
646658
}
647659
}
648660

Flow.Launcher/CustomQueryHotkeySetting.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Width="530"
99
Background="{DynamicResource PopuBGColor}"
1010
DataContext="{Binding RelativeSource={RelativeSource Self}}"
11+
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1112
Foreground="{DynamicResource PopupTextColor}"
1213
Icon="Images\app.png"
1314
MouseDown="window_MouseDown"

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
using Flow.Launcher.Helper;
2-
using Flow.Launcher.Infrastructure.UserSettings;
3-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
42
using System.Linq;
53
using System.Windows;
64
using System.Windows.Input;
75
using System.Windows.Controls;
6+
using Flow.Launcher.Helper;
7+
using Flow.Launcher.Infrastructure.UserSettings;
88

99
namespace Flow.Launcher
1010
{
1111
public partial class CustomQueryHotkeySetting : Window
1212
{
13-
private readonly Settings _settings;
13+
public Settings Settings { get; }
14+
1415
private bool update;
1516
private CustomPluginHotkey updateCustomHotkey;
1617

1718
public CustomQueryHotkeySetting(Settings settings)
1819
{
19-
_settings = settings;
20+
Settings = settings;
2021
InitializeComponent();
2122
}
2223

@@ -29,13 +30,13 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
2930
{
3031
if (!update)
3132
{
32-
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
33+
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
3334

3435
var pluginHotkey = new CustomPluginHotkey
3536
{
3637
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
3738
};
38-
_settings.CustomPluginHotkeys.Add(pluginHotkey);
39+
Settings.CustomPluginHotkeys.Add(pluginHotkey);
3940

4041
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
4142
}
@@ -54,7 +55,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
5455

5556
public void UpdateItem(CustomPluginHotkey item)
5657
{
57-
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
58+
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
5859
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
5960
if (updateCustomHotkey == null)
6061
{

Flow.Launcher/CustomShortcutSetting.xaml

+14-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Width="530"
88
Background="{DynamicResource PopuBGColor}"
99
DataContext="{Binding RelativeSource={RelativeSource Self}}"
10+
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1011
Foreground="{DynamicResource PopupTextColor}"
1112
Icon="Images\app.png"
1213
ResizeMode="NoResize"
@@ -56,11 +57,11 @@
5657
</Button>
5758
</Grid>
5859
</StackPanel>
59-
<StackPanel Margin="26,0,26,0">
60-
<StackPanel Grid.Row="0" Margin="0,0,0,12">
60+
<StackPanel Margin="26 0 26 0">
61+
<StackPanel Grid.Row="0" Margin="0 0 0 12">
6162
<TextBlock
6263
Grid.Column="0"
63-
Margin="0,0,0,0"
64+
Margin="0 0 0 0"
6465
FontSize="20"
6566
FontWeight="SemiBold"
6667
Text="{DynamicResource customQueryShortcut}"
@@ -73,18 +74,18 @@
7374
TextAlignment="Left"
7475
TextWrapping="WrapWithOverflow" />
7576
<TextBlock
76-
Margin="0,20,0,0"
77+
Margin="0 20 0 0"
7778
FontSize="14"
7879
Text="{DynamicResource customeQueryShortcutGuide}"
7980
TextAlignment="Left"
8081
TextWrapping="WrapWithOverflow" />
8182
<Image
8283
Width="478"
83-
Margin="0,20,0,0"
84+
Margin="0 20 0 0"
8485
Source="/Images/illustration_02.png" />
8586
</StackPanel>
8687

87-
<StackPanel Margin="0,10,0,10" Orientation="Horizontal">
88+
<StackPanel Margin="0 10 0 10" Orientation="Horizontal">
8889
<Grid Width="478">
8990
<Grid.RowDefinitions>
9091
<RowDefinition />
@@ -124,14 +125,14 @@
124125
LastChildFill="True">
125126
<Button
126127
x:Name="btnTestShortcut"
127-
Margin="0,0,10,0"
128-
Padding="10,5,10,5"
128+
Margin="0 0 10 0"
129+
Padding="10 5 10 5"
129130
Click="BtnTestShortcut_OnClick"
130131
Content="{DynamicResource preview}"
131132
DockPanel.Dock="Right" />
132133
<TextBox
133134
x:Name="tbExpand"
134-
Margin="10,0,10,0"
135+
Margin="10 0 10 0"
135136
HorizontalAlignment="Stretch"
136137
VerticalAlignment="Center"
137138
Text="{Binding Value}" />
@@ -142,21 +143,21 @@
142143
</StackPanel>
143144
<Border
144145
Grid.Row="1"
145-
Margin="0,10,0,0"
146+
Margin="0 10 0 0"
146147
Background="{DynamicResource PopupButtonAreaBGColor}"
147148
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
148-
BorderThickness="0,1,0,0">
149+
BorderThickness="0 1 0 0">
149150
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
150151
<Button
151152
x:Name="btnCancel"
152153
MinWidth="140"
153-
Margin="10,0,5,0"
154+
Margin="10 0 5 0"
154155
Click="BtnCancel_OnClick"
155156
Content="{DynamicResource cancel}" />
156157
<Button
157158
x:Name="btnAdd"
158159
MinWidth="140"
159-
Margin="5,0,10,0"
160+
Margin="5 0 10 0"
160161
Click="BtnAdd_OnClick"
161162
Style="{StaticResource AccentButtonStyle}">
162163
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />

Flow.Launcher/CustomShortcutSetting.xaml.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
using System;
2-
using System.Windows;
1+
using System.Windows;
32
using System.Windows.Input;
3+
using CommunityToolkit.Mvvm.DependencyInjection;
4+
using Flow.Launcher.Infrastructure.UserSettings;
45
using Flow.Launcher.SettingPages.ViewModels;
56

67
namespace Flow.Launcher
78
{
89
public partial class CustomShortcutSetting : Window
910
{
11+
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
12+
1013
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
11-
public string Key { get; set; } = String.Empty;
12-
public string Value { get; set; } = String.Empty;
14+
public string Key { get; set; } = string.Empty;
15+
public string Value { get; set; } = string.Empty;
1316
private string originalKey { get; } = null;
1417
private string originalValue { get; } = null;
1518
private bool update { get; } = false;

Flow.Launcher/Languages/en.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
<system:String x:Key="logLevel">Log Level</system:String>
356356
<system:String x:Key="LogLevelDEBUG">Debug</system:String>
357357
<system:String x:Key="LogLevelINFO">Info</system:String>
358+
<system:String x:Key="settingWindowFont">Setting Window Font</system:String>
358359

359360
<!-- FileManager Setting Dialog -->
360361
<system:String x:Key="fileManagerWindow">Select File Manager</system:String>

0 commit comments

Comments
 (0)