Skip to content

Commit a28ee70

Browse files
committed
Add settingwindowfont config and menu
1 parent 9981fab commit a28ee70

File tree

7 files changed

+147
-19
lines changed

7 files changed

+147
-19
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,21 @@ public void Save()
6565
{ "pt", "Noto Sans" }
6666
};
6767

68-
public static string GetSystemDefaultFont()
68+
public static string GetSystemDefaultFont(bool? useNoto = null)
6969
{
7070
try
7171
{
72-
var culture = CultureInfo.CurrentCulture;
73-
var language = culture.Name; // e.g., "zh-TW"
74-
var langPrefix = language.Split('-')[0]; // e.g., "zh"
75-
76-
// First, try to find by full name, and if not found, fallback to prefix
77-
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
72+
if (useNoto != false)
7873
{
79-
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
80-
return notoFont;
74+
var culture = CultureInfo.CurrentCulture;
75+
var language = culture.Name; // e.g., "zh-TW"
76+
var langPrefix = language.Split('-')[0]; // e.g., "zh"
77+
78+
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
79+
{
80+
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
81+
return notoFont;
82+
}
8183
}
8284

8385
var font = SystemFonts.MessageFontFamily;
@@ -162,6 +164,7 @@ public string Theme
162164
public string ResultSubFontStyle { get; set; }
163165
public string ResultSubFontWeight { get; set; }
164166
public string ResultSubFontStretch { get; set; }
167+
public string SettingWindowFont { get; set; } = GetSystemDefaultFont(false);
165168
public bool UseGlyphIcons { get; set; } = true;
166169
public bool UseAnimation { get; set; } = true;
167170
public bool UseSound { get; set; } = true;

Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.IO;
45
using System.Linq;
56
using System.Threading.Tasks;
67
using System.Windows;
8+
using System.Windows.Media;
79
using CommunityToolkit.Mvvm.Input;
810
using Flow.Launcher.Core;
911
using Flow.Launcher.Infrastructure;
@@ -268,4 +270,51 @@ private static string BytesToReadableString(long bytes)
268270

269271
return "0 B";
270272
}
273+
274+
public event PropertyChangedEventHandler PropertyChanged;
275+
protected virtual void OnPropertyChanged(string propertyName)
276+
{
277+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
278+
}
279+
280+
private string _settingWindowFont;
281+
282+
public string SettingWindowFont
283+
{
284+
get => _settings.SettingWindowFont;
285+
set
286+
{
287+
if (_settings.SettingWindowFont != value)
288+
{
289+
_settings.SettingWindowFont = value;
290+
OnPropertyChanged(nameof(SettingWindowFont));
291+
}
292+
}
293+
}
294+
295+
[RelayCommand]
296+
private void ResetSettingWindowFont()
297+
{
298+
string defaultFont = GetSystemDefaultFont();
299+
_settings.SettingWindowFont = defaultFont;
300+
}
301+
302+
public static string GetSystemDefaultFont()
303+
{
304+
try
305+
{
306+
var font = SystemFonts.MessageFontFamily;
307+
if (font.FamilyNames.TryGetValue(System.Windows.Markup.XmlLanguage.GetLanguage("en-US"), out var englishName))
308+
{
309+
return englishName;
310+
}
311+
312+
return font.Source ?? "Segoe UI";
313+
}
314+
catch
315+
{
316+
return "Segoe UI";
317+
}
318+
}
319+
271320
}

Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
d:DesignHeight="450"
1313
d:DesignWidth="800"
1414
mc:Ignorable="d">
15+
<ui:Page.Resources>
16+
<ResourceDictionary>
17+
<CollectionViewSource x:Key="SortedFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}" />
18+
</ResourceDictionary>
19+
</ui:Page.Resources>
1520
<ScrollViewer
1621
Margin="0"
1722
CanContentScroll="True"
@@ -127,13 +132,40 @@
127132
</StackPanel>
128133
</cc:Card>
129134

130-
<cc:Card Title="{DynamicResource logLevel}" Icon="&#xE749;">
131-
<ComboBox
132-
DisplayMemberPath="Display"
133-
ItemsSource="{Binding LogLevels}"
134-
SelectedValue="{Binding LogLevel}"
135-
SelectedValuePath="Value" />
136-
</cc:Card>
135+
<cc:ExCard
136+
Title="Advanced"
137+
Margin="0 14 0 0"
138+
Icon="&#xE8B7;">
139+
<StackPanel>
140+
<cc:Card
141+
Title="{DynamicResource logLevel}"
142+
Icon="&#xE749;"
143+
Type="Inside">
144+
<ComboBox
145+
DisplayMemberPath="Display"
146+
ItemsSource="{Binding LogLevels}"
147+
SelectedValue="{Binding LogLevel}"
148+
SelectedValuePath="Value" />
149+
</cc:Card>
150+
<cc:Card
151+
Title="Setting Window Font"
152+
Icon="&#xf259;"
153+
Type="Inside">
154+
<StackPanel Orientation="Horizontal">
155+
<Button Command="{Binding ResetSettingWindowFontCommand}" Content="Reset" />
156+
<ComboBox
157+
Margin="12 8 0 8"
158+
HorizontalAlignment="Stretch"
159+
VerticalAlignment="Top"
160+
DisplayMemberPath="Source"
161+
ItemsSource="{Binding Source={StaticResource SortedFonts}}"
162+
SelectedValue="{Binding SettingWindowFont, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
163+
SelectedValuePath="Source"
164+
SelectionChanged="SettingWindowFontComboBox_SelectionChanged" />
165+
</StackPanel>
166+
</cc:Card>
167+
</StackPanel>
168+
</cc:ExCard>
137169

138170
<TextBlock
139171
Margin="14 20 0 0"

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Windows.Navigation;
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
using System.Windows.Media;
4+
using System.Windows.Navigation;
25
using Flow.Launcher.Core;
36
using Flow.Launcher.SettingPages.ViewModels;
47
using Flow.Launcher.Infrastructure.UserSettings;
@@ -28,4 +31,21 @@ private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
2831
App.API.OpenUrl(e.Uri.AbsoluteUri);
2932
e.Handled = true;
3033
}
34+
35+
private void SettingWindowFontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
36+
{
37+
if (sender is ComboBox comboBox && comboBox.SelectedItem is FontFamily selectedFont)
38+
{
39+
if (DataContext is SettingsPaneAboutViewModel viewModel)
40+
{
41+
viewModel.SettingWindowFont = selectedFont.Source;
42+
43+
// 설정 창 글꼴 즉시 업데이트
44+
if (Window.GetWindow(this) is SettingWindow settingWindow)
45+
{
46+
settingWindow.FontFamily = selectedFont;
47+
}
48+
}
49+
}
50+
}
3151
}

Flow.Launcher/SettingWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
MinHeight="600"
1414
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}"
1515
Closed="OnClosed"
16+
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
1617
Icon="Images\app.ico"
1718
Left="{Binding SettingWindowLeft, Mode=TwoWay}"
1819
Loaded="OnLoaded"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Windows.Forms;
44
using System.Windows.Input;
55
using System.Windows.Interop;
6+
using System.Windows.Media;
67
using CommunityToolkit.Mvvm.DependencyInjection;
78
using Flow.Launcher.Infrastructure;
89
using Flow.Launcher.Infrastructure.UserSettings;

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using Flow.Launcher.Infrastructure.UserSettings;
1+
using System.ComponentModel;
2+
using System.Windows.Media;
3+
using Flow.Launcher.Infrastructure.UserSettings;
24
using Flow.Launcher.Plugin;
35

46
namespace Flow.Launcher.ViewModel;
57

68
public partial class SettingWindowViewModel : BaseModel
79
{
8-
private readonly Settings _settings;
10+
private readonly Settings _settings;
911

1012
public SettingWindowViewModel(Settings settings)
1113
{
@@ -43,4 +45,24 @@ public double? SettingWindowLeft
4345
get => _settings.SettingWindowLeft;
4446
set => _settings.SettingWindowLeft = value;
4547
}
48+
49+
public string SettingWindowFont
50+
{
51+
get => _settings.SettingWindowFont;
52+
set
53+
{
54+
if (_settings.SettingWindowFont != value)
55+
{
56+
_settings.SettingWindowFont = value;
57+
OnPropertyChanged(nameof(SettingWindowFont));
58+
}
59+
}
60+
}
61+
62+
public event PropertyChangedEventHandler PropertyChanged;
63+
64+
protected virtual void OnPropertyChanged(string propertyName)
65+
{
66+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
67+
}
4668
}

0 commit comments

Comments
 (0)