Skip to content

Add Setting for Changing Font in Settings Window #3470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Save()
{
_storage.Save();
}

private string _theme = Constant.DefaultTheme;
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
Expand Down Expand Up @@ -96,6 +96,7 @@ public string Theme
public string ResultSubFontStyle { get; set; }
public string ResultSubFontWeight { get; set; }
public string ResultSubFontStretch { get; set; }
public string SettingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
public bool UseGlyphIcons { get; set; } = true;
public bool UseAnimation { get; set; } = true;
public bool UseSound { get; set; } = true;
Expand Down
32 changes: 22 additions & 10 deletions Flow.Launcher.Infrastructure/Win32Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,21 +628,33 @@ public static void OpenImeSettings()
{ "pt", "Noto Sans" }
};

public static string GetSystemDefaultFont()
/// <summary>
/// Gets the system default font.
/// </summary>
/// <param name="useNoto">
/// If true, it will try to find the Noto font for the current culture.
/// </param>
/// <returns>
/// The name of the system default font.
/// </returns>
public static string GetSystemDefaultFont(bool useNoto = true)
{
try
{
var culture = CultureInfo.CurrentCulture;
var language = culture.Name; // e.g., "zh-TW"
var langPrefix = language.Split('-')[0]; // e.g., "zh"

// First, try to find by full name, and if not found, fallback to prefix
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
if (useNoto)
{
// If the font is installed, return it
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
var culture = CultureInfo.CurrentCulture;
var language = culture.Name; // e.g., "zh-TW"
var langPrefix = language.Split('-')[0]; // e.g., "zh"

// First, try to find by full name, and if not found, fallback to prefix
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
{
return notoFont;
// If the font is installed, return it
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
{
return notoFont;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,24 @@ private static string BytesToReadableString(long bytes)

return "0 B";
}

public string SettingWindowFont
{
get => _settings.SettingWindowFont;
set
{
if (_settings.SettingWindowFont != value)
{
_settings.SettingWindowFont = value;
OnPropertyChanged();
}
}
}

[RelayCommand]
private void ResetSettingWindowFont()
{
string defaultFont = Win32Helper.GetSystemDefaultFont(false);
_settings.SettingWindowFont = defaultFont;
}
}
46 changes: 39 additions & 7 deletions Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<ui:Page.Resources>
<ResourceDictionary>
<CollectionViewSource x:Key="SortedFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}" />
</ResourceDictionary>
</ui:Page.Resources>
<ScrollViewer
Margin="0"
CanContentScroll="True"
Expand Down Expand Up @@ -127,13 +132,40 @@
</StackPanel>
</cc:Card>

<cc:Card Title="{DynamicResource logLevel}" Icon="&#xE749;">
<ComboBox
DisplayMemberPath="Display"
ItemsSource="{Binding LogLevels}"
SelectedValue="{Binding LogLevel}"
SelectedValuePath="Value" />
</cc:Card>
<cc:ExCard
Title="Advanced"
Margin="0 14 0 0"
Icon="&#xE8B7;">
<StackPanel>
<cc:Card
Title="{DynamicResource logLevel}"
Icon="&#xE749;"
Type="Inside">
<ComboBox
DisplayMemberPath="Display"
ItemsSource="{Binding LogLevels}"
SelectedValue="{Binding LogLevel}"
SelectedValuePath="Value" />
</cc:Card>
<cc:Card
Title="Setting Window Font"
Icon="&#xf259;"
Type="Inside">
<StackPanel Orientation="Horizontal">
<Button Command="{Binding ResetSettingWindowFontCommand}" Content="Reset" />
<ComboBox
Margin="12 8 0 8"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
DisplayMemberPath="Source"
ItemsSource="{Binding Source={StaticResource SortedFonts}}"
SelectedValue="{Binding SettingWindowFont, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="Source"
SelectionChanged="SettingWindowFontComboBox_SelectionChanged" />
</StackPanel>
</cc:Card>
</StackPanel>
</cc:ExCard>

<TextBlock
Margin="14 20 0 0"
Expand Down
22 changes: 21 additions & 1 deletion Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Windows.Navigation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Navigation;
using Flow.Launcher.Core;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Infrastructure.UserSettings;
Expand Down Expand Up @@ -28,4 +31,21 @@ private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
App.API.OpenUrl(e.Uri.AbsoluteUri);
e.Handled = true;
}

private void SettingWindowFontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ComboBox comboBox && comboBox.SelectedItem is FontFamily selectedFont)
{
if (DataContext is SettingsPaneAboutViewModel viewModel)
{
viewModel.SettingWindowFont = selectedFont.Source;

// 설정 창 글꼴 즉시 업데이트
if (Window.GetWindow(this) is SettingWindow settingWindow)
{
settingWindow.FontFamily = selectedFont;
}
}
}
}
}
1 change: 1 addition & 0 deletions Flow.Launcher/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MinHeight="600"
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}"
Closed="OnClosed"
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
Icon="Images\app.ico"
Left="{Binding SettingWindowLeft, Mode=TwoWay}"
Loaded="OnLoaded"
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.UserSettings;
Expand Down
26 changes: 24 additions & 2 deletions Flow.Launcher/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Flow.Launcher.Infrastructure.UserSettings;
using System.ComponentModel;
using System.Windows.Media;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.ViewModel;

public partial class SettingWindowViewModel : BaseModel
{
private readonly Settings _settings;
private readonly Settings _settings;

public SettingWindowViewModel(Settings settings)
{
Expand Down Expand Up @@ -43,4 +45,24 @@
get => _settings.SettingWindowLeft;
set => _settings.SettingWindowLeft = value;
}

public string SettingWindowFont
{
get => _settings.SettingWindowFont;
set
{
if (_settings.SettingWindowFont != value)
{
_settings.SettingWindowFont = value;
OnPropertyChanged(nameof(SettingWindowFont));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

Check warning on line 62 in Flow.Launcher/ViewModel/SettingWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / build

'SettingWindowViewModel.PropertyChanged' hides inherited member 'BaseModel.PropertyChanged'. Use the new keyword if hiding was intended.

protected virtual void OnPropertyChanged(string propertyName)

Check warning on line 64 in Flow.Launcher/ViewModel/SettingWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / build

'SettingWindowViewModel.OnPropertyChanged(string)' hides inherited member 'BaseModel.OnPropertyChanged(string)'. Use the new keyword if hiding was intended.
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Loading