mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
feat: Completed the adjustments and bindings of global settings.
This commit is contained in:
parent
a2c44901fd
commit
b57739f543
@ -10,6 +10,7 @@
|
|||||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||||
<PackageVersion Include="QRCoder" Version="1.5.1" />
|
<PackageVersion Include="QRCoder" Version="1.5.1" />
|
||||||
|
<PackageVersion Include="ReactiveUI.Fody" Version="19.5.41" />
|
||||||
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
|
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
|
||||||
<PackageVersion Include="Serilog.Sinks.Async" Version="2.0.0" />
|
<PackageVersion Include="Serilog.Sinks.Async" Version="2.0.0" />
|
||||||
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
|
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
|
3
src/ZonyLrcTools.Desktop/FodyWeavers.xml
Normal file
3
src/ZonyLrcTools.Desktop/FodyWeavers.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||||
|
<ReactiveUI />
|
||||||
|
</Weavers>
|
@ -6,7 +6,8 @@
|
|||||||
x:Class="ZonyLrcTools.Desktop.Pages.SettingsPage"
|
x:Class="ZonyLrcTools.Desktop.Pages.SettingsPage"
|
||||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||||
xmlns:settings="clr-namespace:ZonyLrcTools.Desktop.ViewModels.Settings"
|
xmlns:settings="clr-namespace:ZonyLrcTools.Desktop.ViewModels.Settings"
|
||||||
x:DataType="settings:LyricsSettingsViewModel">
|
x:DataType="settings:SettingsViewModel">
|
||||||
|
|
||||||
<ScrollViewer>
|
<ScrollViewer>
|
||||||
<StackPanel Orientation="Vertical" Margin="24" Spacing="8">
|
<StackPanel Orientation="Vertical" Margin="24" Spacing="8">
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
||||||
@ -34,10 +35,13 @@
|
|||||||
|
|
||||||
<ui:SettingsExpanderItem Content="换行符">
|
<ui:SettingsExpanderItem Content="换行符">
|
||||||
<ui:SettingsExpanderItem.Footer>
|
<ui:SettingsExpanderItem.Footer>
|
||||||
<ComboBox SelectedItem="{Binding Config.LineBreak}">
|
<ComboBox ItemsSource="{Binding Config.LineBreakOptions}"
|
||||||
<ComboBoxItem Content="Windows" />
|
SelectedItem="{Binding Config.SelectedLineBreak}">
|
||||||
<ComboBoxItem Content="Unix" />
|
<ComboBox.ItemTemplate>
|
||||||
<ComboBoxItem Content="Mac" />
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Name}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
</ui:SettingsExpanderItem.Footer>
|
</ui:SettingsExpanderItem.Footer>
|
||||||
</ui:SettingsExpanderItem>
|
</ui:SettingsExpanderItem>
|
||||||
@ -56,10 +60,13 @@
|
|||||||
|
|
||||||
<ui:SettingsExpanderItem Content="文件编码">
|
<ui:SettingsExpanderItem Content="文件编码">
|
||||||
<ui:SettingsExpanderItem.Footer>
|
<ui:SettingsExpanderItem.Footer>
|
||||||
<ComboBox SelectedItem="{Binding Config.FileEncoding}">
|
<ComboBox ItemsSource="{Binding Config.FileEncodingOptions}"
|
||||||
<ComboBoxItem Content="UTF-8" />
|
SelectedItem="{Binding Config.SelectedFileEncoding}">
|
||||||
<ComboBoxItem Content="UTF-16" />
|
<ComboBox.ItemTemplate>
|
||||||
<ComboBoxItem Content="ASCII" />
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Name}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
</ui:SettingsExpanderItem.Footer>
|
</ui:SettingsExpanderItem.Footer>
|
||||||
</ui:SettingsExpanderItem>
|
</ui:SettingsExpanderItem>
|
||||||
|
@ -13,7 +13,7 @@ public partial class SettingsPage : UserControl
|
|||||||
public SettingsPage()
|
public SettingsPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new LyricsSettingsViewModel(App.Current.Services.GetRequiredService<IOptions<GlobalOptions>>().Value);
|
DataContext = new SettingsViewModel(App.Current.Services.GetRequiredService<IOptions<GlobalOptions>>().Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGitHubClick(object? sender, RoutedEventArgs? eventArgs) => UrlHelper.OpenLink("https://github.com/real-zony/ZonyLrcToolsX");
|
private void OnGitHubClick(object? sender, RoutedEventArgs? eventArgs) => UrlHelper.OpenLink("https://github.com/real-zony/ZonyLrcToolsX");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace ZonyLrcTools.Desktop;
|
namespace ZonyLrcTools.Desktop;
|
||||||
|
|
||||||
@ -10,8 +11,11 @@ class Program
|
|||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||||
// yet and stuff might break.
|
// yet and stuff might break.
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
public static void Main(string[] args)
|
||||||
.StartWithClassicDesktopLifetime(args);
|
{
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||||
|
}
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using ReactiveUI;
|
||||||
|
using ReactiveUI.Fody.Helpers;
|
||||||
using ZonyLrcTools.Common.Configuration;
|
using ZonyLrcTools.Common.Configuration;
|
||||||
|
|
||||||
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
|
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
|
||||||
@ -9,77 +15,68 @@ public class GlobalConfigurationViewModel : ViewModelBase
|
|||||||
public GlobalConfigurationViewModel(GlobalLyricsConfigOptions config)
|
public GlobalConfigurationViewModel(GlobalLyricsConfigOptions config)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
|
InitializeLineBreakComboBoxItem();
|
||||||
|
|
||||||
|
IsOneLine = _config.IsOneLine;
|
||||||
|
IsEnableTranslation = _config.IsEnableTranslation;
|
||||||
|
IsSkipExistLyricFiles = _config.IsSkipExistLyricFiles;
|
||||||
|
IsOnlyOutputTranslation = _config.IsOnlyOutputTranslation;
|
||||||
|
|
||||||
|
this.WhenAnyValue(x => x.IsOneLine)
|
||||||
|
.Subscribe(x => _config.IsOneLine = x);
|
||||||
|
this.WhenAnyValue(x => x.IsEnableTranslation)
|
||||||
|
.Subscribe(x => _config.IsEnableTranslation = x);
|
||||||
|
this.WhenAnyValue(x => x.IsSkipExistLyricFiles)
|
||||||
|
.Subscribe(x => _config.IsSkipExistLyricFiles = x);
|
||||||
|
this.WhenAnyValue(x => x.IsOnlyOutputTranslation)
|
||||||
|
.Subscribe(x => _config.IsOnlyOutputTranslation = x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsOneLine
|
[Reactive] public bool IsOneLine { get; set; }
|
||||||
|
|
||||||
|
[Reactive] public bool IsEnableTranslation { get; set; }
|
||||||
|
|
||||||
|
[Reactive] public bool IsSkipExistLyricFiles { get; set; }
|
||||||
|
|
||||||
|
[Reactive] public string FileEncoding { get; set; }
|
||||||
|
|
||||||
|
[Reactive] public bool IsOnlyOutputTranslation { get; set; }
|
||||||
|
|
||||||
|
private void InitializeLineBreakComboBoxItem()
|
||||||
{
|
{
|
||||||
get => _config.IsOneLine;
|
LineBreakOptions =
|
||||||
set
|
[
|
||||||
{
|
new TextComboboxItem { Name = "Windows", Value = "\r\n" },
|
||||||
if (_config.IsOneLine != value)
|
new TextComboboxItem { Name = "Unix", Value = "\n" },
|
||||||
{
|
new TextComboboxItem { Name = "Mac", Value = "\r" }
|
||||||
_config.IsOneLine = value;
|
];
|
||||||
}
|
SelectedLineBreak = LineBreakOptions.FirstOrDefault(x => x.Value == _config.LineBreak)
|
||||||
}
|
?? LineBreakOptions.First();
|
||||||
|
|
||||||
|
FileEncodingOptions = Encoding.GetEncodings()
|
||||||
|
.Select(x => new TextComboboxItem { Name = x.DisplayName, Value = x.Name })
|
||||||
|
.ToList();
|
||||||
|
FileEncodingOptions.Insert(0, new TextComboboxItem { Name = "UTF-8-BOM", Value = "utf-8-bom" });
|
||||||
|
SelectedFileEncoding = FileEncodingOptions.FirstOrDefault(x => x.Value == _config.FileEncoding)
|
||||||
|
?? FileEncodingOptions.First();
|
||||||
|
|
||||||
|
this.WhenAnyValue(x => x.SelectedLineBreak)
|
||||||
|
.Subscribe(x => _config.LineBreak = x.Value);
|
||||||
|
this.WhenAnyValue(x => x.SelectedFileEncoding)
|
||||||
|
.Subscribe(x => _config.FileEncoding = x.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string LineBreak
|
public List<TextComboboxItem> LineBreakOptions { get; private set; }
|
||||||
{
|
|
||||||
get => _config.LineBreak;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_config.LineBreak != value)
|
|
||||||
{
|
|
||||||
_config.LineBreak = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsEnableTranslation
|
[Reactive] public TextComboboxItem SelectedLineBreak { get; set; }
|
||||||
{
|
|
||||||
get => _config.IsEnableTranslation;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_config.IsEnableTranslation != value)
|
|
||||||
{
|
|
||||||
_config.IsEnableTranslation = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsSkipExistLyricFiles
|
public List<TextComboboxItem> FileEncodingOptions { get; private set; }
|
||||||
{
|
|
||||||
get => _config.IsSkipExistLyricFiles;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_config.IsSkipExistLyricFiles != value)
|
|
||||||
{
|
|
||||||
_config.IsSkipExistLyricFiles = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string FileEncoding
|
[Reactive] public TextComboboxItem SelectedFileEncoding { get; set; }
|
||||||
{
|
|
||||||
get => _config.FileEncoding;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_config.FileEncoding != value)
|
|
||||||
{
|
|
||||||
_config.FileEncoding = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsOnlyOutputTranslation
|
public class TextComboboxItem
|
||||||
{
|
{
|
||||||
get => _config.IsOnlyOutputTranslation;
|
public string Name { get; set; } = default!;
|
||||||
set
|
public string Value { get; set; } = default!;
|
||||||
{
|
|
||||||
if (_config.IsOnlyOutputTranslation != value)
|
|
||||||
{
|
|
||||||
_config.IsOnlyOutputTranslation = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,16 +6,16 @@ using ZonyLrcTools.Common.Configuration;
|
|||||||
|
|
||||||
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
|
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
|
||||||
|
|
||||||
public class LyricsSettingsViewModel : ViewModelBase
|
public class SettingsViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private readonly GlobalOptions _globalOptions;
|
private readonly GlobalOptions _globalOptions;
|
||||||
|
|
||||||
public LyricsSettingsViewModel(GlobalOptions globalOptions)
|
public SettingsViewModel(GlobalOptions globalOptions)
|
||||||
{
|
{
|
||||||
_globalOptions = globalOptions;
|
_globalOptions = globalOptions;
|
||||||
|
|
||||||
Config = new GlobalConfigurationViewModel(globalOptions.Provider.Lyric.Config);
|
Config = new GlobalConfigurationViewModel(globalOptions.Provider.Lyric.Config);
|
||||||
Plugin = new ObservableCollection<LyricsProviderViewModel>(
|
Plugin = new ObservableCollection<LyricsProviderViewModel>(globalOptions.Provider.Lyric.Plugin.Select(p => new LyricsProviderViewModel(p)));
|
||||||
globalOptions.Provider.Lyric.Plugin.Select(p => new LyricsProviderViewModel(p)));
|
|
||||||
Tag = new TagInfoViewModel(globalOptions.Provider.Tag);
|
Tag = new TagInfoViewModel(globalOptions.Provider.Tag);
|
||||||
BrowseBlockWordFileCommand = ReactiveCommand.Create(BrowseBlockWordFile);
|
BrowseBlockWordFileCommand = ReactiveCommand.Create(BrowseBlockWordFile);
|
||||||
}
|
}
|
@ -23,6 +23,7 @@
|
|||||||
<PackageReference Include="FluentAvaloniaUI" />
|
<PackageReference Include="FluentAvaloniaUI" />
|
||||||
<PackageReference Include="FluentIcons.Avalonia.Fluent" />
|
<PackageReference Include="FluentIcons.Avalonia.Fluent" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting"/>
|
<PackageReference Include="Microsoft.Extensions.Hosting"/>
|
||||||
|
<PackageReference Include="ReactiveUI.Fody" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user