mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add settingwindowfont config and menu
This commit is contained in:
parent
9981fab885
commit
a28ee701b8
7 changed files with 147 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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="">
|
||||
<ComboBox
|
||||
DisplayMemberPath="Display"
|
||||
ItemsSource="{Binding LogLevels}"
|
||||
SelectedValue="{Binding LogLevel}"
|
||||
SelectedValuePath="Value" />
|
||||
</cc:Card>
|
||||
<cc:ExCard
|
||||
Title="Advanced"
|
||||
Margin="0 14 0 0"
|
||||
Icon="">
|
||||
<StackPanel>
|
||||
<cc:Card
|
||||
Title="{DynamicResource logLevel}"
|
||||
Icon=""
|
||||
Type="Inside">
|
||||
<ComboBox
|
||||
DisplayMemberPath="Display"
|
||||
ItemsSource="{Binding LogLevels}"
|
||||
SelectedValue="{Binding LogLevel}"
|
||||
SelectedValuePath="Value" />
|
||||
</cc:Card>
|
||||
<cc:Card
|
||||
Title="Setting Window Font"
|
||||
Icon=""
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue