82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
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));
|
||
}
|