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

Data bindings - Added copy/pasting of data binding

This commit is contained in:
Robert 2021-03-24 21:53:23 +01:00
parent b3b7d6819d
commit a0faeb21fd
8 changed files with 136 additions and 75 deletions

View File

@ -63,7 +63,10 @@ namespace Artemis.Core
/// </summary>
public Easings.Functions EasingFunction { get; set; }
internal DataBindingEntity Entity { get; }
/// <summary>
/// Gets the data binding entity this data binding uses for persistent storage
/// </summary>
public DataBindingEntity Entity { get; }
/// <summary>
/// Gets the current value of the data binding
@ -100,6 +103,25 @@ namespace Artemis.Core
return Registration?.Getter.Method.ReturnType;
}
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_disposed = true;
if (Registration != null)
Registration.DataBinding = null;
DataBindingMode?.Dispose();
}
}
private void ResetEasing(TProperty value)
{
_previousValue = GetInterpolatedValue();
@ -192,27 +214,6 @@ namespace Artemis.Core
_reapplyValue = true;
}
#region IDisposable
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_disposed = true;
if (Registration != null)
Registration.DataBinding = null;
DataBindingMode?.Dispose();
}
}
/// <inheritdoc />
public void Dispose()
{
@ -220,8 +221,6 @@ namespace Artemis.Core
GC.SuppressFinalize(this);
}
#endregion
#region Mode management
/// <summary>
@ -245,6 +244,16 @@ namespace Artemis.Core
ApplyDataBindingMode();
}
/// <summary>
/// Replaces the current data binding mode with one based on the provided data binding mode entity
/// </summary>
/// <param name="dataBindingModeEntity">The data binding mode entity to base the new data binding mode upon</param>
public void ApplyDataBindingEntity(IDataBindingModeEntity dataBindingModeEntity)
{
Entity.DataBindingMode = dataBindingModeEntity;
ApplyDataBindingMode();
}
private void ApplyDataBindingMode()
{
DataBindingMode?.Dispose();

View File

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.UI.Extensions;
using Artemis.UI.Ninject.Factories;
@ -16,7 +16,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
private readonly IDataModelConditionsVmFactory _dataModelConditionsVmFactory;
private readonly IProfileEditorService _profileEditorService;
private bool _isEventGroup;
private bool _isInitialized;
private bool _isRootGroup;
public DataModelConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup,
@ -30,12 +29,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
_dataModelConditionsVmFactory = dataModelConditionsVmFactory;
Items.CollectionChanged += (_, _) => NotifyOfPropertyChange(nameof(DisplayBooleanOperator));
Execute.PostToUIThread(async () =>
{
await Task.Delay(50);
IsInitialized = true;
});
}
public ConditionGroupType GroupType { get; }
@ -63,12 +56,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
}
}
public bool IsInitialized
{
get => _isInitialized;
set => SetAndNotify(ref _isInitialized, value);
}
public bool DisplayBooleanOperator => Items.Count > 1;
public bool DisplayEvaluationResult => GroupType == ConditionGroupType.General && !IsEventGroup;
public string SelectedBooleanOperator => DataModelConditionGroup.BooleanOperator.Humanize();
@ -132,7 +119,9 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
{
NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
// Remove VMs of effects no longer applied on the layer
Items.RemoveRange(Items.Where(c => !DataModelConditionGroup.Children.Contains(c.Model)).ToList());
List<DataModelConditionViewModel> toRemove = Items.Where(c => !DataModelConditionGroup.Children.Contains(c.Model)).ToList();
if (toRemove.Any())
Items.RemoveRange(toRemove);
foreach (DataModelConditionPart childModel in Model.Children)
{
@ -169,8 +158,10 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
IsEventGroup = Items.Any(i => i is DataModelConditionEventViewModel);
if (IsEventGroup)
{
if (DataModelConditionGroup.BooleanOperator != BooleanOperator.And)
SelectBooleanOperator("And");
}
OnUpdated();
}

View File

@ -6,6 +6,7 @@
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Border BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" Margin="0 0 0 -4" Padding="0 4">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -15,13 +16,15 @@
s:View.Model="{Binding ActiveItem}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
IsTabStop="False" />
IsTabStop="False"
Margin="0 -10 0 0"/>
<ContentControl Grid.Row="1"
Margin="26 2 0 0"
Margin="26 0 0 0"
s:View.Model="{Binding ValueViewModel}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
IsTabStop="False" />
</Grid>
</Border>
</UserControl>

View File

@ -17,7 +17,7 @@
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.75*" />
<ColumnDefinition Width="0.50*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
@ -33,6 +33,7 @@
<RowDefinition Height="48" />
<RowDefinition Height="48" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ComboBox Grid.Row="0"
@ -93,7 +94,7 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="10 10 0 0">
Data binding result
Result
</TextBlock>
<TextBlock Grid.Row="0"
Grid.Column="1"
@ -101,7 +102,7 @@
Visibility="{Binding AlwaysApplyDataBindings.Value, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}"
ToolTip="Check 'Apply data bindings in editor'"
Cursor="Help">
Other data bindings not updating?
Other bindings not updating?
</TextBlock>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignLightSeparator}" Margin="0" />
<Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10 4 10 10">
@ -134,12 +135,39 @@
</Grid>
</Grid>
</materialDesign:Card>
<Grid Grid.Row="4" VerticalAlignment="Bottom" Margin="0 5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Margin="0 0 5 0"
ToolTip="Copy the entire data binding"
Command="{s:Action CopyDataBinding}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="ContentCopy" />
<TextBlock Text="COPY" Margin="8 0 0 0" />
</StackPanel>
</Button>
<Button Grid.Column="1"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Margin="5 0 0 0"
ToolTip="Paste the entire data binding"
Command="{s:Action PasteDataBinding}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="ContentPaste" />
<TextBlock Text="PASTE" Margin="8 0 0 0" />
</StackPanel>
</Button>
</Grid>
</Grid>
</materialDesign:Card>
<materialDesign:Card Grid.Column="1" UniformCornerRadius="0" Background="{DynamicResource MaterialDesignToolBarBackground}" Panel.ZIndex="1">
<Grid Margin="10 5">
<ContentControl s:View.Model="{Binding ActiveItem, IsAsync=True}"
<ContentControl s:View.Model="{Binding ActiveItem}"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
IsTabStop="False" />

View File

@ -3,6 +3,8 @@ using System.Linq;
using System.Timers;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile.DataBindings;
using Artemis.UI.Exceptions;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline;
using Artemis.UI.Shared;
@ -186,16 +188,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
return;
if (Registration.DataBinding != null && SelectedDataBindingMode == DataBindingModeType.None)
{
RemoveDataBinding();
CreateDataBindingModeModeViewModel();
return;
}
else
{
if (Registration.DataBinding == null && SelectedDataBindingMode != DataBindingModeType.None)
EnableDataBinding();
Registration.DataBinding.ChangeDataBindingMode(SelectedDataBindingMode);
Registration.DataBinding!.ChangeDataBindingMode(SelectedDataBindingMode);
}
CreateDataBindingModeModeViewModel();
_profileEditorService.UpdateSelectedProfileElement();
}
@ -256,6 +257,33 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
_profileEditorService.UpdateSelectedProfileElement();
}
public void CopyDataBinding()
{
if (Registration.DataBinding != null)
JsonClipboard.SetObject(Registration.DataBinding.Entity);
}
public void PasteDataBinding()
{
if (Registration.DataBinding == null)
Registration.LayerProperty.EnableDataBinding(Registration);
if (Registration.DataBinding == null)
throw new ArtemisUIException("Failed to create a data binding in order to paste");
DataBindingEntity dataBindingEntity = JsonClipboard.GetData<DataBindingEntity>();
if (dataBindingEntity == null)
return;
Registration.DataBinding.EasingTime = dataBindingEntity.EasingTime;
Registration.DataBinding.EasingFunction = (Easings.Functions) dataBindingEntity.EasingFunction;
Registration.DataBinding.ApplyDataBindingEntity(dataBindingEntity.DataBindingMode);
CreateDataBindingModeModeViewModel();
Update();
_profileEditorService.UpdateSelectedProfileElement();
}
private void OnFrameRendered(object sender, FrameRenderedEventArgs e)
{
UpdateTestResult();

View File

@ -8,7 +8,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="5 10 0 0">
<Grid Margin="0 5 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
@ -32,11 +32,7 @@
Padding="6 4"
Height="22"
Command="{s:Action AddModifier}">
<StackPanel Orientation="Horizontal">
<TextBlock>
ADD MODIFIER
</TextBlock>
</StackPanel>
</Button>
<ListBox Grid.Row="1"

View File

@ -385,7 +385,8 @@
Width="110"
ToolTip="Add a new segment to the timeline"
VerticalAlignment="Center"
IsEnabled="{Binding SelectedProfileElement, Converter={StaticResource NullToBooleanConverter}}">
IsEnabled="{Binding SelectedProfileElement, Converter={StaticResource NullToBooleanConverter}}"
Visibility="{Binding TimelineVisible, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFlatMidBgButton}">
<Style.Triggers>

View File

@ -134,12 +134,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public int RightSideIndex
{
get => _rightSideIndex;
set => SetAndNotify(ref _rightSideIndex, value);
set
{
if (!SetAndNotify(ref _rightSideIndex, value)) return;
NotifyOfPropertyChange(nameof(TimelineVisible));
}
}
public bool CanToggleEffectsViewModel => SelectedProfileElement != null && DateTime.Now - _lastEffectsViewModelToggle > TimeSpan.FromMilliseconds(250);
public bool PropertyTreeVisible => PropertyTreeIndex == 0;
public bool TimelineVisible => RightSideIndex == 0;
public RenderProfileElement SelectedProfileElement
{