diff --git a/src/ZonyLrcTools.Desktop/Pages/SettingsPage.axaml b/src/ZonyLrcTools.Desktop/Pages/SettingsPage.axaml
index 9a9ccd6..217e848 100644
--- a/src/ZonyLrcTools.Desktop/Pages/SettingsPage.axaml
+++ b/src/ZonyLrcTools.Desktop/Pages/SettingsPage.axaml
@@ -8,6 +8,10 @@
xmlns:settings="clr-namespace:ZonyLrcTools.Desktop.ViewModels.Settings"
x:DataType="settings:SettingsViewModel">
+
+
+
+
@@ -80,7 +84,7 @@
-
+
@@ -90,13 +94,13 @@
-
+
-
+
@@ -118,13 +122,13 @@
-
+
-
+
@@ -134,7 +138,7 @@
-
+
diff --git a/src/ZonyLrcTools.Desktop/ViewModels/Settings/BlockWordViewModel.cs b/src/ZonyLrcTools.Desktop/ViewModels/Settings/BlockWordViewModel.cs
index a44ecf6..0fb5215 100644
--- a/src/ZonyLrcTools.Desktop/ViewModels/Settings/BlockWordViewModel.cs
+++ b/src/ZonyLrcTools.Desktop/ViewModels/Settings/BlockWordViewModel.cs
@@ -1,37 +1,26 @@
+using System;
+using ReactiveUI;
+using ReactiveUI.Fody.Helpers;
using ZonyLrcTools.Common.Configuration;
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
public class BlockWordViewModel : ViewModelBase
{
- private readonly BlockWordOptions _options;
-
- public BlockWordViewModel(BlockWordOptions options)
+ public BlockWordViewModel(GlobalOptions options)
{
- _options = options;
- }
+ IsEnable = options.Provider.Tag.BlockWord.IsEnable;
+ FilePath = options.Provider.Tag.BlockWord.FilePath;
- public bool IsEnable
- {
- get => _options.IsEnable;
- set
- {
- if (_options.IsEnable != value)
+ this.WhenAnyValue(x => x.IsEnable, x => x.FilePath)
+ .Subscribe(_ =>
{
- _options.IsEnable = value;
- }
- }
+ options.Provider.Tag.BlockWord.IsEnable = IsEnable;
+ options.Provider.Tag.BlockWord.FilePath = FilePath;
+ });
}
- public string FilePath
- {
- get => _options.FilePath;
- set
- {
- if (_options.FilePath != value)
- {
- _options.FilePath = value;
- }
- }
- }
+ [Reactive] public bool IsEnable { get; set; }
+
+ [Reactive] public string? FilePath { get; set; }
}
\ No newline at end of file
diff --git a/src/ZonyLrcTools.Desktop/ViewModels/Settings/GlobalConfigurationViewModel.cs b/src/ZonyLrcTools.Desktop/ViewModels/Settings/GlobalConfigurationViewModel.cs
index bdd54c7..ce30281 100644
--- a/src/ZonyLrcTools.Desktop/ViewModels/Settings/GlobalConfigurationViewModel.cs
+++ b/src/ZonyLrcTools.Desktop/ViewModels/Settings/GlobalConfigurationViewModel.cs
@@ -10,26 +10,25 @@ namespace ZonyLrcTools.Desktop.ViewModels.Settings;
public class GlobalConfigurationViewModel : ViewModelBase
{
- private readonly GlobalLyricsConfigOptions _config;
-
- public GlobalConfigurationViewModel(GlobalLyricsConfigOptions config)
+ public GlobalConfigurationViewModel(GlobalOptions config)
{
- _config = config;
- InitializeLineBreakComboBoxItem();
+ var globalConfig = config.Provider.Lyric.Config;
- IsOneLine = _config.IsOneLine;
- IsEnableTranslation = _config.IsEnableTranslation;
- IsSkipExistLyricFiles = _config.IsSkipExistLyricFiles;
- IsOnlyOutputTranslation = _config.IsOnlyOutputTranslation;
+ InitializeLineBreakComboBoxItem(globalConfig);
+
+ IsOneLine = globalConfig.IsOneLine;
+ IsEnableTranslation = globalConfig.IsEnableTranslation;
+ IsSkipExistLyricFiles = globalConfig.IsSkipExistLyricFiles;
+ IsOnlyOutputTranslation = globalConfig.IsOnlyOutputTranslation;
this.WhenAnyValue(x => x.IsOneLine)
- .Subscribe(x => _config.IsOneLine = x);
+ .Subscribe(x => globalConfig.IsOneLine = x);
this.WhenAnyValue(x => x.IsEnableTranslation)
- .Subscribe(x => _config.IsEnableTranslation = x);
+ .Subscribe(x => globalConfig.IsEnableTranslation = x);
this.WhenAnyValue(x => x.IsSkipExistLyricFiles)
- .Subscribe(x => _config.IsSkipExistLyricFiles = x);
+ .Subscribe(x => globalConfig.IsSkipExistLyricFiles = x);
this.WhenAnyValue(x => x.IsOnlyOutputTranslation)
- .Subscribe(x => _config.IsOnlyOutputTranslation = x);
+ .Subscribe(x => globalConfig.IsOnlyOutputTranslation = x);
}
[Reactive] public bool IsOneLine { get; set; }
@@ -38,11 +37,9 @@ public class GlobalConfigurationViewModel : ViewModelBase
[Reactive] public bool IsSkipExistLyricFiles { get; set; }
- [Reactive] public string FileEncoding { get; set; }
-
[Reactive] public bool IsOnlyOutputTranslation { get; set; }
- private void InitializeLineBreakComboBoxItem()
+ private void InitializeLineBreakComboBoxItem(GlobalLyricsConfigOptions config)
{
LineBreakOptions =
[
@@ -50,20 +47,20 @@ public class GlobalConfigurationViewModel : ViewModelBase
new TextComboboxItem { Name = "Unix", Value = "\n" },
new TextComboboxItem { Name = "Mac", Value = "\r" }
];
- SelectedLineBreak = LineBreakOptions.FirstOrDefault(x => x.Value == _config.LineBreak)
+ 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)
+ SelectedFileEncoding = FileEncodingOptions.FirstOrDefault(x => x.Value == config.FileEncoding)
?? FileEncodingOptions.First();
this.WhenAnyValue(x => x.SelectedLineBreak)
- .Subscribe(x => _config.LineBreak = x.Value);
+ .Subscribe(x => config.LineBreak = x.Value);
this.WhenAnyValue(x => x.SelectedFileEncoding)
- .Subscribe(x => _config.FileEncoding = x.Value);
+ .Subscribe(x => config.FileEncoding = x.Value);
}
public List LineBreakOptions { get; private set; }
diff --git a/src/ZonyLrcTools.Desktop/ViewModels/Settings/LyricsProviderViewModel.cs b/src/ZonyLrcTools.Desktop/ViewModels/Settings/LyricsProviderViewModel.cs
index b0c33bb..1e2176f 100644
--- a/src/ZonyLrcTools.Desktop/ViewModels/Settings/LyricsProviderViewModel.cs
+++ b/src/ZonyLrcTools.Desktop/ViewModels/Settings/LyricsProviderViewModel.cs
@@ -1,49 +1,52 @@
+using System;
+using System.Globalization;
+using Avalonia.Data;
+using Avalonia.Data.Converters;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+using ReactiveUI;
+using ReactiveUI.Fody.Helpers;
using ZonyLrcTools.Common.Configuration;
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
public class LyricsProviderViewModel : ViewModelBase
{
- private readonly LyricsProviderOptions _options;
-
public LyricsProviderViewModel(LyricsProviderOptions options)
{
- _options = options;
+ var globalOptions = App.Current.Services.GetRequiredService>().Value;
+
+ Name = options.Name;
+ Priority = options.Priority;
+ Depth = options.Depth;
+
+ this.WhenAnyValue(x => x.Priority)
+ .Subscribe(priority => globalOptions.Provider.Lyric.GetLyricProviderOption(Name).Priority = priority);
+ this.WhenAnyValue(x => x.Depth)
+ .Subscribe(depth => globalOptions.Provider.Lyric.GetLyricProviderOption(Name).Depth = depth);
}
- public string Name
+ public string Name { get; set; }
+
+ [Reactive] public int Priority { get; set; }
+
+ [Reactive] public int Depth { get; set; }
+}
+
+internal class NullToDefaultValueConverter : IValueConverter
+{
+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- get => _options.Name;
- set
- {
- if (_options.Name != value)
- {
- _options.Name = value;
- }
- }
+ return value != null ? System.Convert.ToDecimal(value) : 0;
}
- public int Priority
+ public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- get => _options.Priority;
- set
+ if (value is decimal dValue)
{
- if (_options.Priority != value)
- {
- _options.Priority = value;
- }
+ return System.Convert.ToInt32(dValue);
}
- }
- public int Depth
- {
- get => _options.Depth;
- set
- {
- if (_options.Depth != value)
- {
- _options.Depth = value;
- }
- }
+ return BindingOperations.DoNothing;
}
}
\ No newline at end of file
diff --git a/src/ZonyLrcTools.Desktop/ViewModels/Settings/SettingsViewModel.cs b/src/ZonyLrcTools.Desktop/ViewModels/Settings/SettingsViewModel.cs
index 954b594..0b84221 100644
--- a/src/ZonyLrcTools.Desktop/ViewModels/Settings/SettingsViewModel.cs
+++ b/src/ZonyLrcTools.Desktop/ViewModels/Settings/SettingsViewModel.cs
@@ -1,6 +1,9 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
+using System.Threading.Tasks;
+using Avalonia.Controls;
+using Avalonia.Platform.Storage;
using ReactiveUI;
using ZonyLrcTools.Common.Configuration;
@@ -8,31 +11,46 @@ namespace ZonyLrcTools.Desktop.ViewModels.Settings;
public class SettingsViewModel : ViewModelBase
{
- private readonly GlobalOptions _globalOptions;
-
public SettingsViewModel(GlobalOptions globalOptions)
{
- _globalOptions = globalOptions;
-
- Config = new GlobalConfigurationViewModel(globalOptions.Provider.Lyric.Config);
- Plugin = new ObservableCollection(globalOptions.Provider.Lyric.Plugin.Select(p => new LyricsProviderViewModel(p)));
- Tag = new TagInfoViewModel(globalOptions.Provider.Tag);
- BrowseBlockWordFileCommand = ReactiveCommand.Create(BrowseBlockWordFile);
+ Config = new GlobalConfigurationViewModel(globalOptions);
+ LyricsProviders = new ObservableCollection(globalOptions.Provider.Lyric.Plugin.Select(p => new LyricsProviderViewModel(p)));
+ Tag = new TagInfoViewModel(globalOptions);
+ BrowseBlockWordFileCommand = ReactiveCommand.CreateFromTask(BrowseBlockWordFile);
}
public static string Version => typeof(Program).Assembly.GetName().Version!.ToString();
public TagInfoViewModel Tag { get; }
- public ReactiveCommand BrowseBlockWordFileCommand { get; }
+ public ReactiveCommand BrowseBlockWordFileCommand { get; }
public GlobalConfigurationViewModel Config { get; }
- public ObservableCollection Plugin { get; }
+ public ObservableCollection LyricsProviders { get; }
- private void BrowseBlockWordFile()
+ private async Task BrowseBlockWordFile(Window parentWindow)
{
- // Implement file browsing logic here
- // Update Tag.BlockWord.FilePath with the selected file path
+ var storage = parentWindow.StorageProvider;
+ if (storage.CanOpen)
+ {
+ var options = new FilePickerOpenOptions
+ {
+ AllowMultiple = false,
+ FileTypeFilter = new[]
+ {
+ new FilePickerFileType("JSON")
+ {
+ Patterns = new[] { "*.json" }
+ }
+ }
+ };
+
+ var files = await storage.OpenFilePickerAsync(options);
+ if (files.Count > 0)
+ {
+ Tag.BlockWord.FilePath = files[0].Path.LocalPath;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoProviderViewModel.cs b/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoProviderViewModel.cs
index f57ae06..19dcbf5 100644
--- a/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoProviderViewModel.cs
+++ b/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoProviderViewModel.cs
@@ -1,42 +1,22 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using ReactiveUI.Fody.Helpers;
using ZonyLrcTools.Common.Configuration;
namespace ZonyLrcTools.Desktop.ViewModels.Settings;
public class TagInfoProviderViewModel : ViewModelBase
{
- private readonly TagInfoProviderOptions _options;
-
public TagInfoProviderViewModel(TagInfoProviderOptions options)
{
- _options = options;
+ Name = options.Name;
+ Priority = options.Priority;
Extensions = new ObservableCollection>(options.Extensions ?? new Dictionary());
}
- public string Name
- {
- get => _options.Name;
- set
- {
- if (_options.Name != value)
- {
- _options.Name = value;
- }
- }
- }
+ public string? Name { get; set; }
- public int Priority
- {
- get => _options.Priority;
- set
- {
- if (_options.Priority != value)
- {
- _options.Priority = value;
- }
- }
- }
+ [Reactive] public int Priority { get; set; }
public ObservableCollection> Extensions { get; }
}
\ No newline at end of file
diff --git a/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoViewModel.cs b/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoViewModel.cs
index 7a7cbad..0ab2ef5 100644
--- a/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoViewModel.cs
+++ b/src/ZonyLrcTools.Desktop/ViewModels/Settings/TagInfoViewModel.cs
@@ -6,16 +6,16 @@ namespace ZonyLrcTools.Desktop.ViewModels.Settings;
public class TagInfoViewModel : ViewModelBase
{
- private readonly TagInfoOptions _options;
+ private readonly GlobalOptions _options;
- public TagInfoViewModel(TagInfoOptions options)
+ public TagInfoViewModel(GlobalOptions options)
{
_options = options;
- BlockWord = new BlockWordViewModel(options.BlockWord);
- Plugin = new ObservableCollection(
- options.Plugin.Select(p => new TagInfoProviderViewModel(p)));
+ BlockWord = new BlockWordViewModel(options);
+ TagInfoProviders = new ObservableCollection(options.Provider.Tag.Plugin.Select(p => new TagInfoProviderViewModel(p)));
}
public BlockWordViewModel BlockWord { get; }
- public ObservableCollection Plugin { get; }
+
+ public ObservableCollection TagInfoProviders { get; }
}
\ No newline at end of file