UI - Streamlined VM names

This commit is contained in:
Robert committed 2022-04-24 22:05:29 +02:00
1 parent cd8656cb0d
commit eac08050bc
9 files changed
+76 -54

No files matched your search

@@ -0,0 +1,24 @@
using System;
using System.Reactive.Linq;
using Artemis.Core;
namespace Artemis.UI.Shared.Extensions;
/// <summary>
/// Provides utilities when working with layer properties in a UI context.
/// </summary>
public static class LayerPropertyExtensions
{
/// <summary>
/// Returns an observable sequence of layer property values starting with the current value.
/// </summary>
/// <param name="layerProperty">The layer property to create the sequence of.</param>
/// <typeparam name="T">The value type of the layer property.</typeparam>
/// <returns>An observable sequence of layer property values starting with the current value.</returns>
public static IObservable<T> AsObservable<T>(this LayerProperty<T> layerProperty)
{
return Observable.FromEventPattern<LayerPropertyEventArgs>(x => layerProperty.Updated += x, x => layerProperty.Updated -= x)
.Select(_ => layerProperty.CurrentValue)
.StartWith(layerProperty.CurrentValue);
}
}
@@ -7,7 +7,7 @@ namespace Artemis.UI.Shared.LayerBrushes
/// <summary>
/// Represents a view model for a brush configuration window
/// </summary>
public abstract class BrushConfigurationViewModel : ActivatableViewModelBase
public abstract class BrushConfigurationViewModel : ValidatableViewModelBase
{
/// <summary>
/// Creates a new instance of the <see cref="BrushConfigurationViewModel" /> class
@@ -8,7 +8,7 @@ namespace Artemis.UI.Shared.LayerEffects;
/// <summary>
/// Represents a view model for an effect configuration window
/// </summary>
public abstract class EffectConfigurationViewModel : ActivatableViewModelBase
public abstract class EffectConfigurationViewModel : ValidatableViewModelBase
{
/// <summary>
/// Creates a new instance of the <see cref="EffectConfigurationViewModel" /> class
@@ -6,7 +6,7 @@ namespace Artemis.UI.Shared
/// <summary>
/// Represents a view model for a plugin configuration window
/// </summary>
public abstract class PluginConfigurationViewModel : ViewModelValidationBase, IPluginConfigurationViewModel
public abstract class PluginConfigurationViewModel : ValidatableViewModelBase, IPluginConfigurationViewModel
{
/// <summary>
/// Creates a new instance of the <see cref="PluginConfigurationViewModel" /> class
+43 -47
View File
@@ -12,7 +12,7 @@ namespace Artemis.UI.Shared;
/// <summary>
/// Represents the base class for Artemis view models
/// </summary>
public abstract class ContentDialogViewModelBase : ReactiveValidationObject, IActivatableViewModel, IDisposable
public abstract class ContentDialogViewModelBase : ValidatableViewModelBase, IDisposable
{
/// <summary>
/// Gets the content dialog that hosts the view model
@@ -29,14 +29,7 @@ public abstract class ContentDialogViewModelBase : ReactiveValidationObject, IAc
protected virtual void Dispose(bool disposing)
{
}
#region Implementation of IActivatableViewModel
/// <inheritdoc />
public ViewModelActivator Activator { get; } = new();
#endregion
/// <inheritdoc />
public void Dispose()
{
@@ -46,9 +39,35 @@ public abstract class ContentDialogViewModelBase : ReactiveValidationObject, IAc
}
/// <summary>
/// Represents the base class for Artemis view models
/// Represents the base class for Artemis view models used to drive dialogs
/// </summary>
public abstract class ViewModelValidationBase : ReactiveValidationObject
public abstract class DialogViewModelBase<TResult> : ValidatableViewModelBase
{
/// <summary>
/// Closes the dialog with the given <paramref name="result" />
/// </summary>
/// <param name="result">The result of the dialog</param>
public void Close(TResult result)
{
CloseRequested?.Invoke(this, new DialogClosedEventArgs<TResult>(result));
}
/// <summary>
/// Closes the dialog without a result
/// </summary>
public void Cancel()
{
CancelRequested?.Invoke(this, EventArgs.Empty);
}
internal event EventHandler<DialogClosedEventArgs<TResult>>? CloseRequested;
internal event EventHandler? CancelRequested;
}
/// <summary>
/// Represents the base class for Artemis view models that are interested in validation and the activated event
/// </summary>
public abstract class ValidatableViewModelBase : ReactiveValidationObject, IActivatableViewModel
{
private string? _displayName;
@@ -60,7 +79,10 @@ public abstract class ViewModelValidationBase : ReactiveValidationObject
get => _displayName;
set => RaiseAndSetIfChanged(ref _displayName, value);
}
/// <inheritdoc />
public ViewModelActivator Activator { get; } = new();
/// <summary>
/// RaiseAndSetIfChanged fully implements a Setter for a read-write property on a ReactiveObject, using
/// CallerMemberName to raise the notification and the ref to the backing field to set the property.
@@ -89,6 +111,15 @@ public abstract class ViewModelValidationBase : ReactiveValidationObject
}
}
/// <summary>
/// Represents the base class for Artemis view models that are interested in the activated event
/// </summary>
public abstract class ActivatableViewModelBase : ViewModelBase, IActivatableViewModel
{
/// <inheritdoc />
public ViewModelActivator Activator { get; } = new();
}
/// <summary>
/// Represents the base class for Artemis view models
/// </summary>
@@ -131,39 +162,4 @@ public abstract class ViewModelBase : ReactiveObject
this.RaisePropertyChanged(propertyName);
return newValue;
}
}
/// <summary>
/// Represents the base class for Artemis view models that are interested in the activated event
/// </summary>
public abstract class ActivatableViewModelBase : ViewModelBase, IActivatableViewModel
{
/// <inheritdoc />
public ViewModelActivator Activator { get; } = new();
}
/// <summary>
/// Represents the base class for Artemis view models used to drive dialogs
/// </summary>
public abstract class DialogViewModelBase<TResult> : ActivatableViewModelBase
{
/// <summary>
/// Closes the dialog with the given <paramref name="result" />
/// </summary>
/// <param name="result">The result of the dialog</param>
public void Close(TResult result)
{
CloseRequested?.Invoke(this, new DialogClosedEventArgs<TResult>(result));
}
/// <summary>
/// Closes the dialog without a result
/// </summary>
public void Cancel()
{
CancelRequested?.Invoke(this, EventArgs.Empty);
}
internal event EventHandler<DialogClosedEventArgs<TResult>>? CloseRequested;
internal event EventHandler? CancelRequested;
}