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 all 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
16 changes: 15 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 @@ -103,6 +103,20 @@ public string Theme
public bool ShowBadges { get; set; } = false;
public bool ShowBadgesGlobalOnly { get; set; } = false;

private string _settingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
public string SettingWindowFont
{
get => _settingWindowFont;
set
{
if (_settingWindowFont != value)
{
_settingWindowFont = value;
OnPropertyChanged();
}
}
}

public bool UseClock { get; set; } = true;
public bool UseDate { get; set; } = false;
public string TimeFormat { get; set; } = "hh:mm tt";
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 @@ -8,6 +8,7 @@
Width="530"
Background="{DynamicResource PopuBGColor}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
Foreground="{DynamicResource PopupTextColor}"
Icon="Images\app.png"
MouseDown="window_MouseDown"
Expand Down
17 changes: 9 additions & 8 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure.UserSettings;

namespace Flow.Launcher
{
public partial class CustomQueryHotkeySetting : Window
{
private readonly Settings _settings;
public Settings Settings { get; }

private bool update;
private CustomPluginHotkey updateCustomHotkey;

public CustomQueryHotkeySetting(Settings settings)
{
_settings = settings;
Settings = settings;
InitializeComponent();
}

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

var pluginHotkey = new CustomPluginHotkey
{
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
};
_settings.CustomPluginHotkeys.Add(pluginHotkey);
Settings.CustomPluginHotkeys.Add(pluginHotkey);

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

public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
Expand Down
27 changes: 14 additions & 13 deletions Flow.Launcher/CustomShortcutSetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Width="530"
Background="{DynamicResource PopuBGColor}"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
Foreground="{DynamicResource PopupTextColor}"
Icon="Images\app.png"
ResizeMode="NoResize"
Expand Down Expand Up @@ -56,11 +57,11 @@
</Button>
</Grid>
</StackPanel>
<StackPanel Margin="26,0,26,0">
<StackPanel Grid.Row="0" Margin="0,0,0,12">
<StackPanel Margin="26 0 26 0">
<StackPanel Grid.Row="0" 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 customQueryShortcut}"
Expand All @@ -73,18 +74,18 @@
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
<TextBlock
Margin="0,20,0,0"
Margin="0 20 0 0"
FontSize="14"
Text="{DynamicResource customeQueryShortcutGuide}"
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
<Image
Width="478"
Margin="0,20,0,0"
Margin="0 20 0 0"
Source="/Images/illustration_02.png" />
</StackPanel>

<StackPanel Margin="0,10,0,10" Orientation="Horizontal">
<StackPanel Margin="0 10 0 10" Orientation="Horizontal">
<Grid Width="478">
<Grid.RowDefinitions>
<RowDefinition />
Expand Down Expand Up @@ -124,14 +125,14 @@
LastChildFill="True">
<Button
x:Name="btnTestShortcut"
Margin="0,0,10,0"
Padding="10,5,10,5"
Margin="0 0 10 0"
Padding="10 5 10 5"
Click="BtnTestShortcut_OnClick"
Content="{DynamicResource preview}"
DockPanel.Dock="Right" />
<TextBox
x:Name="tbExpand"
Margin="10,0,10,0"
Margin="10 0 10 0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Text="{Binding Value}" />
Expand All @@ -142,21 +143,21 @@
</StackPanel>
<Border
Grid.Row="1"
Margin="0,10,0,0"
Margin="0 10 0 0"
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"
MinWidth="140"
Margin="10,0,5,0"
Margin="10 0 5 0"
Click="BtnCancel_OnClick"
Content="{DynamicResource cancel}" />
<Button
x:Name="btnAdd"
MinWidth="140"
Margin="5,0,10,0"
Margin="5 0 10 0"
Click="BtnAdd_OnClick"
Style="{StaticResource AccentButtonStyle}">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
Expand Down
11 changes: 7 additions & 4 deletions Flow.Launcher/CustomShortcutSetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using System.Windows;
using System.Windows;
using System.Windows.Input;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.SettingPages.ViewModels;

namespace Flow.Launcher
{
public partial class CustomShortcutSetting : Window
{
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();

private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
public string Key { get; set; } = String.Empty;
public string Value { get; set; } = String.Empty;
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
private string originalKey { get; } = null;
private string originalValue { get; } = null;
private bool update { get; } = false;
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
Loading
Loading