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 9 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
1 change: 1 addition & 0 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
Title="{DynamicResource customeQueryHotkeyTitle}"
Width="530"
Background="{DynamicResource PopuBGColor}"
Expand Down
21 changes: 20 additions & 1 deletion Flow.Launcher/CustomQueryHotkeySetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
Expand All @@ -13,7 +14,25 @@ public partial class CustomQueryHotkeySetting : Window
private readonly Settings _settings;
private bool update;
private CustomPluginHotkey updateCustomHotkey;

public event PropertyChangedEventHandler PropertyChanged;

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

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public CustomQueryHotkeySetting(Settings settings)
{
_settings = settings;
Expand Down
23 changes: 22 additions & 1 deletion Flow.Launcher/CustomShortcutSetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.SettingPages.ViewModels;

namespace Flow.Launcher
Expand All @@ -13,7 +15,26 @@
private string originalKey { get; } = null;
private string originalValue { get; } = null;
private bool update { get; } = false;

private readonly Settings _settings;

Check warning on line 18 in Flow.Launcher/CustomShortcutSetting.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Field 'CustomShortcutSetting._settings' is never assigned to, and will always have its default value null
public event PropertyChangedEventHandler PropertyChanged;

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

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
{
_hotkeyVm = vm;
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
<system:String x:Key="logLevel">Log Level</system:String>
<system:String x:Key="LogLevelDEBUG">Debug</system:String>
<system:String x:Key="LogLevelINFO">Info</system:String>
<system:String x:Key="settingWindowFont">Setting Window Font</system:String>

<!-- FileManager Setting Dialog -->
<system:String x:Key="fileManagerWindow">Select File Manager</system:String>
Expand Down
51 changes: 25 additions & 26 deletions Flow.Launcher/SelectBrowserWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Width="550"
Background="{DynamicResource PopuBGColor}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
Foreground="{DynamicResource PopupTextColor}"
ResizeMode="NoResize"
SizeToContent="Height"
Expand Down Expand Up @@ -54,11 +55,11 @@
</Button>
</Grid>
</StackPanel>
<StackPanel Margin="26,12,26,0">
<StackPanel Margin="0,0,0,12">
<StackPanel Margin="26 12 26 0">
<StackPanel Margin="0 0 0 12">
<TextBlock
Grid.Column="0"
Margin="0,0,0,0"
Margin="0 0 0 0"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource defaultBrowserTitle}"
Expand All @@ -73,7 +74,7 @@
</StackPanel>


<StackPanel Margin="14,28,0,0" Orientation="Horizontal">
<StackPanel Margin="14 28 0 0" Orientation="Horizontal">
<TextBlock
Grid.Column="1"
HorizontalAlignment="Left"
Expand All @@ -84,7 +85,7 @@
Name="comboBox"
Height="35"
MinWidth="200"
Margin="14,0,0,0"
Margin="14 0 0 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
ItemsSource="{Binding CustomBrowsers}"
Expand All @@ -96,22 +97,22 @@
</ComboBox.ItemTemplate>
</ComboBox>
<Button
Margin="10,0,0,0"
Margin="10 0 0 0"
Click="btnAdd_Click"
Content="{DynamicResource add}" />
<Button
Margin="10,0,0,0"
Margin="10 0 0 0"
Click="btnDelete_Click"
Content="{DynamicResource delete}"
IsEnabled="{Binding CustomBrowser.Editable}" />

</StackPanel>
<Rectangle
Height="1"
Margin="0,20,0,12"
Margin="0 20 0 12"
Fill="{DynamicResource SeparatorForeground}" />
<StackPanel
Margin="0,0,0,0"
Margin="0 0 0 0"
HorizontalAlignment="Stretch"
DataContext="{Binding CustomBrowser}"
Orientation="Horizontal">
Expand All @@ -129,7 +130,7 @@
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="14,5,10,0"
Margin="14 5 10 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Expand All @@ -139,15 +140,15 @@
Grid.Row="0"
Grid.Column="1"
Width="Auto"
Margin="10,5,0,0"
Margin="10 5 0 0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
IsEnabled="{Binding Editable}"
Text="{Binding Name}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="14,10,0,0"
Margin="14 10 0 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Expand All @@ -159,7 +160,7 @@
LastChildFill="True">
<Button
Name="btnBrowseFile"
Margin="0,10,0,0"
Margin="0 10 0 0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Click="btnBrowseFile_Click"
Expand All @@ -177,7 +178,7 @@
</Button>
<TextBox
x:Name="PathTextBox"
Margin="10,10,5,0"
Margin="10 10 5 0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
IsEnabled="{Binding Editable}"
Expand All @@ -187,37 +188,35 @@
<StackPanel
Grid.Row="2"
Grid.Column="1"
Margin="14,10,14,0"
Margin="14 10 14 0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Orientation="Horizontal">
<RadioButton IsChecked="{Binding OpenInTab}"
Content="{DynamicResource defaultBrowser_newTab}"></RadioButton>
<RadioButton IsChecked="{Binding OpenInNewWindow, Mode=OneTime}"
Content="{DynamicResource defaultBrowser_newWindow}"></RadioButton>
<RadioButton Content="{DynamicResource defaultBrowser_newTab}" IsChecked="{Binding OpenInTab}" />
<RadioButton Content="{DynamicResource defaultBrowser_newWindow}" IsChecked="{Binding OpenInNewWindow, Mode=OneTime}" />
</StackPanel>
<TextBlock
Grid.Row="3"
Grid.Column="0"
Margin="14,10,0,20"
Margin="14 10 0 20"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource defaultBrowser_parameter}" />
<StackPanel
Grid.Row="3"
Grid.Column="1"
Margin="0,10,0,15"
Margin="0 10 0 15"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBox
x:Name="fileArgTextBox"
Width="180"
Margin="10,0,0,0"
Margin="10 0 0 0"
Text="{Binding PrivateArg}" />
<CheckBox
Margin="12,0,0,0"
Margin="12 0 0 0"
VerticalAlignment="Center"
IsChecked="{Binding EnablePrivate}">
<CheckBox.Style>
Expand All @@ -239,18 +238,18 @@
Grid.Row="1"
Background="{DynamicResource PopupButtonAreaBGColor}"
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
BorderThickness="0,1,0,0">
BorderThickness="0 1 0 0">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
x:Name="btnCancel"
Width="145"
Margin="0,0,5,0"
Margin="0 0 5 0"
Click="btnCancel_Click"
Content="{DynamicResource cancel}" />
<Button
x:Name="btnDone"
Width="145"
Margin="5,0,0,0"
Margin="5 0 0 0"
Click="btnDone_Click"
Content="{DynamicResource done}"
ForceCursor="True"
Expand Down
17 changes: 16 additions & 1 deletion Flow.Launcher/SelectBrowserWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ public partial class SelectBrowserWindow : Window, INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;

public Settings Settings { get; }

public string SettingWindowFont
{
get => Settings.SettingWindowFont;
set
{
if (Settings.SettingWindowFont != value)
{
Settings.SettingWindowFont = value;
OnPropertyChanged(nameof(SettingWindowFont));
}
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public int SelectedCustomBrowserIndex
{
get => selectedCustomBrowserIndex; set
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/SelectFileManagerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Width="600"
Background="{DynamicResource PopuBGColor}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
Foreground="{DynamicResource PopupTextColor}"
ResizeMode="NoResize"
SizeToContent="Height"
Expand Down
16 changes: 16 additions & 0 deletions Flow.Launcher/SelectFileManagerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ public partial class SelectFileManagerWindow : Window, INotifyPropertyChanged

public Settings Settings { get; }

public string SettingWindowFont
{
get => Settings.SettingWindowFont;
set
{
if (Settings.SettingWindowFont != value)
{
Settings.SettingWindowFont = value;
OnPropertyChanged(nameof(SettingWindowFont));
}
}
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public int SelectedCustomExplorerIndex
{
get => selectedCustomExplorerIndex; set
Expand Down
Loading
Loading