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 2 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 @@
{
_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 ResultSubFontStyle { get; set; }
public string ResultSubFontWeight { get; set; }
public string ResultSubFontStretch { get; set; }
public string SettingWindowFont { get; set; } = GetSystemDefaultFont(false);

Check failure on line 99 in Flow.Launcher.Infrastructure/UserSettings/Settings.cs

View workflow job for this annotation

GitHub Actions / build

The name 'GetSystemDefaultFont' does not exist in the current context

Check failure on line 99 in Flow.Launcher.Infrastructure/UserSettings/Settings.cs

View workflow job for this annotation

GitHub Actions / build

The name 'GetSystemDefaultFont' does not exist in the current context
public bool UseGlyphIcons { get; set; } = true;
public bool UseAnimation { get; set; } = true;
public bool UseSound { get; set; } = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core;
using Flow.Launcher.Infrastructure;
Expand Down Expand Up @@ -268,4 +270,51 @@ private static string BytesToReadableString(long bytes)

return "0 B";
}

public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

private string _settingWindowFont;

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

[RelayCommand]
private void ResetSettingWindowFont()
{
string defaultFont = GetSystemDefaultFont();
_settings.SettingWindowFont = defaultFont;
}

public static string GetSystemDefaultFont()
{
try
{
var font = SystemFonts.MessageFontFamily;
if (font.FamilyNames.TryGetValue(System.Windows.Markup.XmlLanguage.GetLanguage("en-US"), out var englishName))
{
return englishName;
}

return font.Source ?? "Segoe UI";
}
catch
{
return "Segoe UI";
}
}

}
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 @@ public double? SettingWindowLeft
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;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Loading