emby-toolbox/EmbyToolbox/ViewModels/AddFilesOptionsViewModel.cs
Emby Toolbox 6264b487fe Initial commit: Emby Toolbox (conversion scroll fix, bulk Del for tracks).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 21:33:47 +05:00

82 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.ComponentModel;
using System.Runtime.CompilerServices;
using EmbyToolbox.Models;
namespace EmbyToolbox.ViewModels;
public sealed class AddFilesOptionsViewModel : INotifyPropertyChanged
{
private readonly Action<AddFilesOptions> _onAdd;
private readonly Action _onCancel;
private bool _removeForeignAudioAndSubtitles;
public AddFilesOptionsViewModel(Action<AddFilesOptions> onAdd, Action onCancel)
{
_onAdd = onAdd;
_onCancel = onCancel;
AddCommand = new RelayCommand(ExecuteAdd);
CancelCommand = new RelayCommand(() => _onCancel());
}
/// <summary>Взаимоисключающие опции: два свойства, чтобы не использовать TwoWay на одно поле с конвертером (переполнение стека в WPF).</summary>
public bool OptionKeepAllTracks
{
get => !_removeForeignAudioAndSubtitles;
set
{
if (!value)
{
return;
}
if (!_removeForeignAudioAndSubtitles)
{
return;
}
_removeForeignAudioAndSubtitles = false;
OnPropertyChanged();
OnPropertyChanged(nameof(OptionRemoveForeignTracks));
}
}
public bool OptionRemoveForeignTracks
{
get => _removeForeignAudioAndSubtitles;
set
{
if (!value)
{
return;
}
if (_removeForeignAudioAndSubtitles)
{
return;
}
_removeForeignAudioAndSubtitles = true;
OnPropertyChanged();
OnPropertyChanged(nameof(OptionKeepAllTracks));
}
}
public RelayCommand AddCommand { get; }
public RelayCommand CancelCommand { get; }
private void ExecuteAdd()
{
_onAdd(
new AddFilesOptions
{
RemoveForeignAudioAndSubtitles = _removeForeignAudioAndSubtitles
});
}
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? name = null) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}