Use partial properties

This commit is contained in:
Tyrrrz 2025-03-18 19:58:54 +02:00
parent 569a099ec7
commit 0a3a6f465c
7 changed files with 50 additions and 103 deletions

View File

@ -11,7 +11,7 @@ public abstract partial class DialogViewModelBase<T> : ViewModelBase
);
[ObservableProperty]
private T? _dialogResult;
public partial T? DialogResult { get; set; }
[RelayCommand]
protected void Close(T dialogResult)

View File

@ -12,107 +12,53 @@ using Container = YoutubeExplode.Videos.Streams.Container;
namespace YoutubeDownloader.Services;
// Can't use [ObservableProperty] here because System.Text.Json's source generator doesn't see
// the generated properties.
[INotifyPropertyChanged]
[ObservableObject]
public partial class SettingsService()
: SettingsBase(
Path.Combine(AppContext.BaseDirectory, "Settings.dat"),
SerializerContext.Default
)
{
private bool _isUkraineSupportMessageEnabled = true;
public bool IsUkraineSupportMessageEnabled
{
get => _isUkraineSupportMessageEnabled;
set => SetProperty(ref _isUkraineSupportMessageEnabled, value);
}
[ObservableProperty]
public partial bool IsUkraineSupportMessageEnabled { get; set; } = true;
private ThemeVariant _theme;
public ThemeVariant Theme
{
get => _theme;
set => SetProperty(ref _theme, value);
}
[ObservableProperty]
public partial ThemeVariant Theme { get; set; }
private bool _isAutoUpdateEnabled = true;
public bool IsAutoUpdateEnabled
{
get => _isAutoUpdateEnabled;
set => SetProperty(ref _isAutoUpdateEnabled, value);
}
[ObservableProperty]
public partial bool IsAutoUpdateEnabled { get; set; } = true;
private bool _isAuthPersisted = true;
public bool IsAuthPersisted
{
get => _isAuthPersisted;
set => SetProperty(ref _isAuthPersisted, value);
}
[ObservableProperty]
public partial bool IsAuthPersisted { get; set; } = true;
private bool _shouldInjectLanguageSpecificAudioStreams = true;
public bool ShouldInjectLanguageSpecificAudioStreams
{
get => _shouldInjectLanguageSpecificAudioStreams;
set => SetProperty(ref _shouldInjectLanguageSpecificAudioStreams, value);
}
[ObservableProperty]
public partial bool ShouldInjectLanguageSpecificAudioStreams { get; set; } = true;
private bool _shouldInjectSubtitles = true;
public bool ShouldInjectSubtitles
{
get => _shouldInjectSubtitles;
set => SetProperty(ref _shouldInjectSubtitles, value);
}
[ObservableProperty]
public partial bool ShouldInjectSubtitles { get; set; } = true;
private bool _shouldInjectTags = true;
public bool ShouldInjectTags
{
get => _shouldInjectTags;
set => SetProperty(ref _shouldInjectTags, value);
}
[ObservableProperty]
public partial bool ShouldInjectTags { get; set; } = true;
private bool _shouldSkipExistingFiles;
public bool ShouldSkipExistingFiles
{
get => _shouldSkipExistingFiles;
set => SetProperty(ref _shouldSkipExistingFiles, value);
}
[ObservableProperty]
public partial bool ShouldSkipExistingFiles { get; set; }
private string _fileNameTemplate = "$title";
public string FileNameTemplate
{
get => _fileNameTemplate;
set => SetProperty(ref _fileNameTemplate, value);
}
[ObservableProperty]
public partial string FileNameTemplate { get; set; } = "$title";
private int _parallelLimit = 2;
public int ParallelLimit
{
get => _parallelLimit;
set => SetProperty(ref _parallelLimit, value);
}
[ObservableProperty]
public partial int ParallelLimit { get; set; } = 2;
private IReadOnlyList<Cookie>? _lastAuthCookies;
public IReadOnlyList<Cookie>? LastAuthCookies
{
get => _lastAuthCookies;
set => SetProperty(ref _lastAuthCookies, value);
}
private Container _lastContainer = Container.Mp4;
[ObservableProperty]
public partial IReadOnlyList<Cookie>? LastAuthCookies { get; set; }
[ObservableProperty]
[JsonConverter(typeof(ContainerJsonConverter))]
public Container LastContainer
{
get => _lastContainer;
set => SetProperty(ref _lastContainer, value);
}
public partial Container LastContainer { get; set; } = Container.Mp4;
private VideoQualityPreference _lastVideoQualityPreference = VideoQualityPreference.Highest;
public VideoQualityPreference LastVideoQualityPreference
{
get => _lastVideoQualityPreference;
set => SetProperty(ref _lastVideoQualityPreference, value);
}
[ObservableProperty]
public partial VideoQualityPreference LastVideoQualityPreference { get; set; } =
VideoQualityPreference.Highest;
public override void Save()
{

View File

@ -33,11 +33,11 @@ public partial class DashboardViewModel : ViewModelBase
[NotifyCanExecuteChangedFor(nameof(ProcessQueryCommand))]
[NotifyCanExecuteChangedFor(nameof(ShowAuthSetupCommand))]
[NotifyCanExecuteChangedFor(nameof(ShowSettingsCommand))]
private bool _isBusy;
public partial bool IsBusy { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(ProcessQueryCommand))]
private string? _query;
public partial string? Query { get; set; }
public DashboardViewModel(
ViewModelManager viewModelManager,

View File

@ -25,28 +25,28 @@ public partial class DownloadViewModel : ViewModelBase
private bool _isDisposed;
[ObservableProperty]
private IVideo? _video;
public partial IVideo? Video { get; set; }
[ObservableProperty]
private VideoDownloadOption? _downloadOption;
public partial VideoDownloadOption? DownloadOption { get; set; }
[ObservableProperty]
private VideoDownloadPreference? _downloadPreference;
public partial VideoDownloadPreference? DownloadPreference { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FileName))]
private string? _filePath;
public partial string? FilePath { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsCanceledOrFailed))]
[NotifyCanExecuteChangedFor(nameof(CancelCommand))]
[NotifyCanExecuteChangedFor(nameof(ShowFileCommand))]
[NotifyCanExecuteChangedFor(nameof(OpenFileCommand))]
private DownloadStatus _status = DownloadStatus.Enqueued;
public partial DownloadStatus Status { get; set; } = DownloadStatus.Enqueued;
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CopyErrorMessageCommand))]
private string? _errorMessage;
public partial string? ErrorMessage { get; set; }
public DownloadViewModel(ViewModelManager viewModelManager, DialogManager dialogManager)
{

View File

@ -25,21 +25,22 @@ public partial class DownloadMultipleSetupViewModel(
) : DialogViewModelBase<IReadOnlyList<DownloadViewModel>>
{
[ObservableProperty]
private string? _title;
public partial string? Title { get; set; }
[ObservableProperty]
private IReadOnlyList<IVideo>? _availableVideos;
public partial IReadOnlyList<IVideo>? AvailableVideos { get; set; }
[ObservableProperty]
private Container _selectedContainer = Container.Mp4;
public partial Container SelectedContainer { get; set; } = Container.Mp4;
[ObservableProperty]
private VideoQualityPreference _selectedVideoQualityPreference = VideoQualityPreference.Highest;
public partial VideoQualityPreference SelectedVideoQualityPreference { get; set; } =
VideoQualityPreference.Highest;
public ObservableCollection<IVideo> SelectedVideos { get; } = [];
public IReadOnlyList<Container> AvailableContainers { get; } =
[Container.Mp4, Container.WebM, Container.Mp3, new Container("ogg")];
[Container.Mp4, Container.WebM, Container.Mp3, new("ogg")];
public IReadOnlyList<VideoQualityPreference> AvailableVideoQualityPreferences { get; } =
Enum.GetValues<VideoQualityPreference>().Reverse().ToArray();

View File

@ -23,13 +23,13 @@ public partial class DownloadSingleSetupViewModel(
) : DialogViewModelBase<DownloadViewModel>
{
[ObservableProperty]
private IVideo? _video;
public partial IVideo? Video { get; set; }
[ObservableProperty]
private IReadOnlyList<VideoDownloadOption>? _availableDownloadOptions;
public partial IReadOnlyList<VideoDownloadOption>? AvailableDownloadOptions { get; set; }
[ObservableProperty]
private VideoDownloadOption? _selectedDownloadOption;
public partial VideoDownloadOption? SelectedDownloadOption { get; set; }
[RelayCommand]
private void Initialize()

View File

@ -6,20 +6,20 @@ namespace YoutubeDownloader.ViewModels.Dialogs;
public partial class MessageBoxViewModel : DialogViewModelBase
{
[ObservableProperty]
private string? _title = "Title";
public partial string? Title { get; set; } = "Title";
[ObservableProperty]
private string? _message = "Message";
public partial string? Message { get; set; } = "Message";
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsDefaultButtonVisible))]
[NotifyPropertyChangedFor(nameof(ButtonsCount))]
private string? _defaultButtonText = "OK";
public partial string? DefaultButtonText { get; set; } = "OK";
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsCancelButtonVisible))]
[NotifyPropertyChangedFor(nameof(ButtonsCount))]
private string? _cancelButtonText = "Cancel";
public partial string? CancelButtonText { get; set; } = "Cancel";
public bool IsDefaultButtonVisible => !string.IsNullOrWhiteSpace(DefaultButtonText);