Add settingwindowfont config and menu

This commit is contained in:
DB p 2025-04-17 18:45:31 +09:00
parent 9981fab885
commit a28ee701b8
7 changed files with 147 additions and 19 deletions

View file

@ -65,19 +65,21 @@ namespace Flow.Launcher.Infrastructure.UserSettings
{ "pt", "Noto Sans" }
};
public static string GetSystemDefaultFont()
public static string GetSystemDefaultFont(bool? useNoto = null)
{
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 != false)
{
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
return notoFont;
var culture = CultureInfo.CurrentCulture;
var language = culture.Name; // e.g., "zh-TW"
var langPrefix = language.Split('-')[0]; // e.g., "zh"
if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont))
{
if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont)))
return notoFont;
}
}
var font = SystemFonts.MessageFontFamily;
@ -162,6 +164,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public string ResultSubFontStyle { get; set; }
public string ResultSubFontWeight { get; set; }
public string ResultSubFontStretch { get; set; }
public string SettingWindowFont { get; set; } = GetSystemDefaultFont(false);
public bool UseGlyphIcons { get; set; } = true;
public bool UseAnimation { get; set; } = true;
public bool UseSound { get; set; } = true;

View file

@ -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;
@ -268,4 +270,51 @@ public partial class SettingsPaneAboutViewModel : BaseModel
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";
}
}
}

View file

@ -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"
@ -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"

View file

@ -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;
@ -28,4 +31,21 @@ public partial class SettingsPaneAbout
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;
}
}
}
}
}

View file

@ -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"

View file

@ -3,6 +3,7 @@ using System.Windows;
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;

View file

@ -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)
{
@ -43,4 +45,24 @@ public partial class SettingWindowViewModel : BaseModel
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));
}
}