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] [ObservableProperty]
private T? _dialogResult; public partial T? DialogResult { get; set; }
[RelayCommand] [RelayCommand]
protected void Close(T dialogResult) protected void Close(T dialogResult)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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