1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

UI - Streamlined VM names

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

View File

@ -14,8 +14,10 @@
<entry key="Artemis.UI.Avalonia/Screens/Sidebar/Views/SidebarProfileConfigurationView.axaml" value="Artemis.UI.Avalonia/Artemis.UI.Avalonia.csproj" />
<entry key="Artemis.UI.Avalonia/Screens/SidebarView.axaml" value="Artemis.UI.Avalonia/Artemis.UI.Avalonia.csproj" />
<entry key="Artemis.UI.Avalonia/Views/MainWindow.axaml" value="Artemis.UI.Avalonia/Artemis.UI.Avalonia.csproj" />
<entry key="Artemis.UI.Shared/Styles/Border.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI.Windows/App.axaml" value="Artemis.UI.Windows/Artemis.UI.Windows.csproj" />
<entry key="Artemis.UI/DefaultTypes/PropertyInput/ColorGradientPropertyInputView.axaml" value="Artemis.UI.Windows/Artemis.UI.Windows.csproj" />
<entry key="Artemis.UI/DefaultTypes/PropertyInput/SKSizePropertyInputView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/Dialogs/AddEffectView.axaml" value="Artemis.UI.Windows/Artemis.UI.Windows.csproj" />
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/PropertiesView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />
<entry key="Artemis.UI/Screens/ProfileEditor/Panels/Properties/Tree/ContentDialogs/LayerEffectRenameView.axaml" value="Artemis.UI.Linux/Artemis.UI.Linux.csproj" />

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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

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;
}

View File

@ -6,7 +6,7 @@ namespace Artemis.UI.Extensions;
public static class DataBindingExtensions
{
public static IObservable<IDataBinding> GetObservable(this IDataBinding dataBinding)
public static IObservable<IDataBinding> AsObservable(this IDataBinding dataBinding)
{
return Observable.FromEventPattern<DataBindingEventArgs>(x => dataBinding.DataBindingEnabled += x, x => dataBinding.DataBindingEnabled -= x)
.Merge(Observable.FromEventPattern<DataBindingEventArgs>(x => dataBinding.DataBindingDisabled += x, x => dataBinding.DataBindingDisabled -= x))

View File

@ -30,13 +30,13 @@ public class DataBindingViewModel : ActivatableViewModelBase
{
_layerProperty = profileEditorService.LayerProperty.ToProperty(this, vm => vm.LayerProperty).DisposeWith(d);
_nodeScriptViewModel = profileEditorService.LayerProperty
.Select(p => p != null ? p.BaseDataBinding.GetObservable() : Observable.Never<IDataBinding>())
.Select(p => p != null ? p.BaseDataBinding.AsObservable() : Observable.Never<IDataBinding>())
.Switch()
.Select(b => b.IsEnabled ? nodeVmFactory.NodeScriptViewModel((NodeScript) b.Script, false) : null)
.ToProperty(this, vm => vm.NodeScriptViewModel)
.DisposeWith(d);
_dataBindingEnabled = profileEditorService.LayerProperty
.Select(p => p != null ? p.BaseDataBinding.GetObservable() : Observable.Never<IDataBinding>())
.Select(p => p != null ? p.BaseDataBinding.AsObservable() : Observable.Never<IDataBinding>())
.Switch()
.Select(b => b.IsEnabled)
.ToProperty(this, vm => vm.DataBindingEnabled)

View File

@ -31,7 +31,7 @@ internal class TreePropertyViewModel<T> : ActivatableViewModelBase, ITreePropert
{
_profileEditorService.Time.Subscribe(t => _time = t).DisposeWith(d);
_isCurrentlySelected = _profileEditorService.LayerProperty.Select(l => l == LayerProperty).ToProperty(this, vm => vm.IsCurrentlySelected).DisposeWith(d);
_dataBindingEnabled = LayerProperty.BaseDataBinding.GetObservable().Select(b => b.IsEnabled).ToProperty(this, vm => vm.DataBindingEnabled).DisposeWith(d);
_dataBindingEnabled = LayerProperty.BaseDataBinding.AsObservable().Select(b => b.IsEnabled).ToProperty(this, vm => vm.DataBindingEnabled).DisposeWith(d);
this.WhenAnyValue(vm => vm.LayerProperty.KeyframesEnabled).Subscribe(_ => this.RaisePropertyChanged(nameof(KeyframesEnabled))).DisposeWith(d);
});