Use partial properties

This commit is contained in:
Tyrrrz 2025-03-18 20:06:44 +02:00
parent fca6729ef0
commit deca3fc1bf
5 changed files with 58 additions and 124 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

@ -9,126 +9,60 @@ using DiscordChatExporter.Gui.Models;
namespace DiscordChatExporter.Gui.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 _isTokenPersisted = true;
public bool IsTokenPersisted
{
get => _isTokenPersisted;
set => SetProperty(ref _isTokenPersisted, value);
}
[ObservableProperty]
public partial bool IsTokenPersisted { get; set; } = true;
private ThreadInclusionMode _threadInclusionMode;
public ThreadInclusionMode ThreadInclusionMode
{
get => _threadInclusionMode;
set => SetProperty(ref _threadInclusionMode, value);
}
[ObservableProperty]
public partial ThreadInclusionMode ThreadInclusionMode { get; set; }
private string? _locale;
public string? Locale
{
get => _locale;
set => SetProperty(ref _locale, value);
}
[ObservableProperty]
public partial string? Locale { get; set; }
private bool _isUtcNormalizationEnabled;
public bool IsUtcNormalizationEnabled
{
get => _isUtcNormalizationEnabled;
set => SetProperty(ref _isUtcNormalizationEnabled, value);
}
[ObservableProperty]
public partial bool IsUtcNormalizationEnabled { get; set; }
private int _parallelLimit = 1;
public int ParallelLimit
{
get => _parallelLimit;
set => SetProperty(ref _parallelLimit, value);
}
[ObservableProperty]
public partial int ParallelLimit { get; set; } = 1;
private string? _lastToken;
public string? LastToken
{
get => _lastToken;
set => SetProperty(ref _lastToken, value);
}
[ObservableProperty]
public partial string? LastToken { get; set; }
private ExportFormat _lastExportFormat = ExportFormat.HtmlDark;
public ExportFormat LastExportFormat
{
get => _lastExportFormat;
set => SetProperty(ref _lastExportFormat, value);
}
[ObservableProperty]
public partial ExportFormat LastExportFormat { get; set; } = ExportFormat.HtmlDark;
private string? _lastPartitionLimitValue;
public string? LastPartitionLimitValue
{
get => _lastPartitionLimitValue;
set => SetProperty(ref _lastPartitionLimitValue, value);
}
[ObservableProperty]
public partial string? LastPartitionLimitValue { get; set; }
private string? _lastMessageFilterValue;
public string? LastMessageFilterValue
{
get => _lastMessageFilterValue;
set => SetProperty(ref _lastMessageFilterValue, value);
}
[ObservableProperty]
public partial string? LastMessageFilterValue { get; set; }
private bool _lastShouldFormatMarkdown = true;
public bool LastShouldFormatMarkdown
{
get => _lastShouldFormatMarkdown;
set => SetProperty(ref _lastShouldFormatMarkdown, value);
}
[ObservableProperty]
public partial bool LastShouldFormatMarkdown { get; set; } = true;
private bool _lastShouldDownloadAssets;
public bool LastShouldDownloadAssets
{
get => _lastShouldDownloadAssets;
set => SetProperty(ref _lastShouldDownloadAssets, value);
}
[ObservableProperty]
public partial bool LastShouldDownloadAssets { get; set; }
private bool _lastShouldReuseAssets;
public bool LastShouldReuseAssets
{
get => _lastShouldReuseAssets;
set => SetProperty(ref _lastShouldReuseAssets, value);
}
[ObservableProperty]
public partial bool LastShouldReuseAssets { get; set; }
private string? _lastAssetsDirPath;
public string? LastAssetsDirPath
{
get => _lastAssetsDirPath;
set => SetProperty(ref _lastAssetsDirPath, value);
}
[ObservableProperty]
public partial string? LastAssetsDirPath { get; set; }
public override void Save()
{

View file

@ -38,22 +38,22 @@ public partial class DashboardViewModel : ViewModelBase
[NotifyCanExecuteChangedFor(nameof(PullGuildsCommand))]
[NotifyCanExecuteChangedFor(nameof(PullChannelsCommand))]
[NotifyCanExecuteChangedFor(nameof(ExportCommand))]
private bool _isBusy;
public partial bool IsBusy { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(PullGuildsCommand))]
private string? _token;
public partial string? Token { get; set; }
[ObservableProperty]
private IReadOnlyList<Guild>? _availableGuilds;
public partial IReadOnlyList<Guild>? AvailableGuilds { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(PullChannelsCommand))]
[NotifyCanExecuteChangedFor(nameof(ExportCommand))]
private Guild? _selectedGuild;
public partial Guild? SelectedGuild { get; set; }
[ObservableProperty]
private IReadOnlyList<ChannelConnection>? _availableChannels;
public partial IReadOnlyList<ChannelConnection>? AvailableChannels { get; set; }
public DashboardViewModel(
ViewModelManager viewModelManager,

View file

@ -22,56 +22,56 @@ public partial class ExportSetupViewModel(
) : DialogViewModelBase
{
[ObservableProperty]
private Guild? _guild;
public partial Guild? Guild { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsSingleChannel))]
private IReadOnlyList<Channel>? _channels;
public partial IReadOnlyList<Channel>? Channels { get; set; }
[ObservableProperty]
private string? _outputPath;
public partial string? OutputPath { get; set; }
[ObservableProperty]
private ExportFormat _selectedFormat;
public partial ExportFormat SelectedFormat { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsAfterDateSet))]
[NotifyPropertyChangedFor(nameof(After))]
private DateTimeOffset? _afterDate;
public partial DateTimeOffset? AfterDate { get; set; }
[ObservableProperty]
private TimeSpan? _afterTime;
public partial TimeSpan? AfterTime { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsBeforeDateSet))]
[NotifyPropertyChangedFor(nameof(Before))]
private DateTimeOffset? _beforeDate;
public partial DateTimeOffset? BeforeDate { get; set; }
[ObservableProperty]
private TimeSpan? _beforeTime;
public partial TimeSpan? BeforeTime { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(PartitionLimit))]
private string? _partitionLimitValue;
public partial string? PartitionLimitValue { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(MessageFilter))]
private string? _messageFilterValue;
public partial string? MessageFilterValue { get; set; }
[ObservableProperty]
private bool _shouldFormatMarkdown;
public partial bool ShouldFormatMarkdown { get; set; }
[ObservableProperty]
private bool _shouldDownloadAssets;
public partial bool ShouldDownloadAssets { get; set; }
[ObservableProperty]
private bool _shouldReuseAssets;
public partial bool ShouldReuseAssets { get; set; }
[ObservableProperty]
private string? _assetsDirPath;
public partial string? AssetsDirPath { get; set; }
[ObservableProperty]
private bool _isAdvancedSectionDisplayed;
public partial bool IsAdvancedSectionDisplayed { get; set; }
public bool IsSingleChannel => Channels?.Count == 1;

View file

@ -6,20 +6,20 @@ namespace DiscordChatExporter.Gui.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);