mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Profile modules - Encapsulation fixes
Data bindings - Abstracted the data model selection
This commit is contained in:
1 parent
76dcbaf6d7
commit
d03ca9c84a
20 files changed
+502
-189
No files matched your search
+10
-50
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Utilities;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
@@ -15,11 +12,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
private readonly IDataBindingService _dataBindingService;
|
||||
private readonly IDataModelUIService _dataModelUIService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly Timer _updateTimer;
|
||||
private DataModelPropertiesViewModel _parameterDataModel;
|
||||
private bool _parameterDataModelOpen;
|
||||
private DataBindingModifierType _selectedModifierType;
|
||||
private DataModelVisualizationViewModel _selectedParameterProperty;
|
||||
|
||||
public DataBindingModifierViewModel(DataBindingModifier modifier,
|
||||
IDataBindingService dataBindingService,
|
||||
@@ -30,7 +23,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
_dataBindingService = dataBindingService;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_updateTimer = new Timer(500);
|
||||
|
||||
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
|
||||
|
||||
@@ -55,37 +47,20 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
set => SetAndNotify(ref _selectedModifierType, value);
|
||||
}
|
||||
|
||||
public DataModelPropertiesViewModel ParameterDataModel
|
||||
{
|
||||
get => _parameterDataModel;
|
||||
set => SetAndNotify(ref _parameterDataModel, value);
|
||||
}
|
||||
|
||||
public bool ParameterDataModelOpen
|
||||
{
|
||||
get => _parameterDataModelOpen;
|
||||
set => SetAndNotify(ref _parameterDataModelOpen, value);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel SelectedParameterProperty
|
||||
{
|
||||
get => _selectedParameterProperty;
|
||||
set => SetAndNotify(ref _selectedParameterProperty, value);
|
||||
}
|
||||
public DataModelSelectionViewModel ParameterSelectionViewModel { get; private set; }
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Get the data models
|
||||
ParameterDataModel = _dataModelUIService.GetMainDataModelVisualization();
|
||||
if (!_dataModelUIService.GetPluginExtendsDataModel(_profileEditorService.GetCurrentModule()))
|
||||
ParameterDataModel.Children.Add(_dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule()));
|
||||
|
||||
ParameterDataModel.UpdateRequested += ParameterDataModelOnUpdateRequested;
|
||||
ParameterSelectionViewModel = _dataModelUIService.GetDataModelSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
ParameterSelectionViewModel.PropertySelected += ParameterSelectionViewModelOnPropertySelected;
|
||||
ParameterSelectionViewModel.FilterTypes = new[] {Modifier.DataBinding.TargetProperty.PropertyType};
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
_updateTimer.Start();
|
||||
_updateTimer.Elapsed += OnUpdateTimerOnElapsed;
|
||||
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelPropertySelectedEventArgs e)
|
||||
{
|
||||
Modifier.UpdateParameter(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -95,11 +70,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
ModifierTypes.AddRange(_dataBindingService.GetCompatibleModifierTypes(Modifier.DataBinding.TargetProperty.PropertyType));
|
||||
SelectedModifierType = Modifier.ModifierType;
|
||||
|
||||
// Determine the parameter property
|
||||
if (Modifier.ParameterDataModel == null)
|
||||
SelectedParameterProperty = null;
|
||||
else
|
||||
SelectedParameterProperty = ParameterDataModel.GetChildByPath(Modifier.ParameterDataModel.PluginInfo.Guid, Modifier.ParameterPropertyPath);
|
||||
ParameterSelectionViewModel.PopulateSelectedPropertyViewModel(Modifier.ParameterDataModel, Modifier.ParameterPropertyPath);
|
||||
}
|
||||
|
||||
private void ExecuteSelectModifierTypeCommand(object context)
|
||||
@@ -112,16 +83,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
private void ParameterDataModelOnUpdateRequested(object sender, EventArgs e)
|
||||
{
|
||||
ParameterDataModel.ApplyTypeFilter(true, Modifier.DataBinding.TargetProperty.PropertyType);
|
||||
}
|
||||
|
||||
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (ParameterDataModelOpen)
|
||||
ParameterDataModel.Update(_dataModelUIService);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-42
@@ -16,18 +16,6 @@
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DisplayConditions.xaml" />
|
||||
<ResourceDictionary>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<utilities:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
<DataTemplate x:Key="DataModelDataTemplate">
|
||||
<Control x:Name="TemplateControl" Focusable="False" Template="{StaticResource DataModelSelectionTemplate}" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Data.ShowDataModelValues.Value, Source={StaticResource DataContextProxy}}" Value="True">
|
||||
<Setter TargetName="TemplateControl" Property="Template" Value="{StaticResource DataModelSelectionTemplateWithValues}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
@@ -49,36 +37,7 @@
|
||||
|
||||
<StackPanel Grid.Row="0" Margin="-3 0 0 0">
|
||||
<Label FontSize="10" Foreground="{StaticResource MaterialDesignNavigationItemSubheader}" Margin="0 0 0 2">Source</Label>
|
||||
<Button Background="#ab47bc"
|
||||
BorderBrush="#ab47bc"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
ToolTip="{Binding SelectedSourceProperty.DisplayPropertyPath}"
|
||||
IsEnabled="{Binding IsDataBindingEnabled}"
|
||||
HorizontalAlignment="Left"
|
||||
Click="PropertyButton_OnClick">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu ItemsSource="{Binding SourceDataModel.Children}" IsOpen="{Binding SourceDataModelOpen, Mode=OneWayToSource}">
|
||||
<ContextMenu.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
|
||||
<Setter Property="ItemsSource" Value="{Binding Children}" />
|
||||
<Setter Property="Command" Value="{Binding Data.SelectSourcePropertyCommand, Source={StaticResource DataContextProxy}}" />
|
||||
<Setter Property="CommandParameter" Value="{Binding}" />
|
||||
<Setter Property="CommandTarget" Value="{Binding}" />
|
||||
<Setter Property="IsEnabled" Value="{Binding IsMatchingFilteredTypes}" />
|
||||
<Setter Property="IsSubmenuOpen" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource DataModelDataTemplate}" />
|
||||
</Style>
|
||||
</ContextMenu.ItemContainerStyle>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding SelectedSourceProperty.PropertyDescription.Name}"
|
||||
Visibility="{Binding SelectedSourceProperty, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Text="« Select a property »"
|
||||
FontStyle="Italic"
|
||||
Visibility="{Binding SelectedSourceProperty, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</Button>
|
||||
<ContentControl s:View.Model="{Binding TargetSelectionViewModel}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</StackPanel>
|
||||
|
||||
<ComboBox Grid.Row="1"
|
||||
|
||||
+36
-66
@@ -27,12 +27,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
private bool _sourceDataModelOpen;
|
||||
private object _testInputValue;
|
||||
private object _testResultValue;
|
||||
private DataModelSelectionViewModel _targetSelectionViewModel;
|
||||
|
||||
public DataBindingViewModel(BaseLayerProperty layerProperty,
|
||||
PropertyInfo targetProperty,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDataModelUIService dataModelUIService,
|
||||
ISettingsService settingsService,
|
||||
IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
@@ -40,47 +40,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
_updateTimer = new Timer(500);
|
||||
|
||||
DisplayName = targetProperty.Name.ToUpper();
|
||||
|
||||
LayerProperty = layerProperty;
|
||||
TargetProperty = targetProperty;
|
||||
|
||||
DisplayName = TargetProperty.Name.ToUpper();
|
||||
SelectSourcePropertyCommand = new DelegateCommand(ExecuteSelectSourceProperty);
|
||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
||||
DataBinding = layerProperty.DataBindings.FirstOrDefault(d => d.TargetProperty == targetProperty);
|
||||
|
||||
ShowDataModelValues = settingsService.GetSetting<bool>("ProfileEditor.ShowDataModelValues");
|
||||
ModifierViewModels = new BindableCollection<DataBindingModifierViewModel>();
|
||||
|
||||
_isDataBindingEnabled = DataBinding != null;
|
||||
|
||||
// Initialize async, no need to wait for it
|
||||
Task.Run(Initialize);
|
||||
Execute.PostToUIThread(Initialize);
|
||||
}
|
||||
|
||||
public DataModelPropertiesViewModel SourceDataModel
|
||||
{
|
||||
get => _sourceDataModel;
|
||||
set => SetAndNotify(ref _sourceDataModel, value);
|
||||
}
|
||||
|
||||
public bool SourceDataModelOpen
|
||||
{
|
||||
get => _sourceDataModelOpen;
|
||||
set => SetAndNotify(ref _sourceDataModelOpen, value);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel SelectedSourceProperty
|
||||
{
|
||||
get => _selectedSourceProperty;
|
||||
set => SetAndNotify(ref _selectedSourceProperty, value);
|
||||
}
|
||||
|
||||
public PluginSetting<bool> ShowDataModelValues { get; }
|
||||
public BaseLayerProperty LayerProperty { get; }
|
||||
public PropertyInfo TargetProperty { get; }
|
||||
public string DisplayName { get; }
|
||||
public BindableCollection<DataBindingModifierViewModel> ModifierViewModels { get; }
|
||||
|
||||
public DelegateCommand SelectSourcePropertyCommand { get; }
|
||||
public DataModelSelectionViewModel TargetSelectionViewModel
|
||||
{
|
||||
get => _targetSelectionViewModel;
|
||||
private set => SetAndNotify(ref _targetSelectionViewModel, value);
|
||||
}
|
||||
|
||||
public bool IsDataBindingEnabled
|
||||
{
|
||||
@@ -105,12 +88,25 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
}
|
||||
}
|
||||
|
||||
public object TestInputValue
|
||||
{
|
||||
get => _testInputValue;
|
||||
set => SetAndNotify(ref _testInputValue, value);
|
||||
}
|
||||
|
||||
public object TestResultValue
|
||||
{
|
||||
get => _testResultValue;
|
||||
set => SetAndNotify(ref _testResultValue, value);
|
||||
}
|
||||
|
||||
public void EnableDataBinding()
|
||||
{
|
||||
if (DataBinding != null)
|
||||
return;
|
||||
|
||||
DataBinding = LayerProperty.AddDataBinding(TargetProperty);
|
||||
Update();
|
||||
}
|
||||
|
||||
public void RemoveDataBinding()
|
||||
@@ -121,6 +117,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
var toRemove = DataBinding;
|
||||
DataBinding = null;
|
||||
LayerProperty.RemoveDataBinding(toRemove);
|
||||
Update();
|
||||
}
|
||||
|
||||
public void AddModifier()
|
||||
@@ -136,12 +133,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Get the data models
|
||||
SourceDataModel = _dataModelUIService.GetMainDataModelVisualization();
|
||||
if (!_dataModelUIService.GetPluginExtendsDataModel(_profileEditorService.GetCurrentModule()))
|
||||
SourceDataModel.Children.Add(_dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule()));
|
||||
|
||||
SourceDataModel.UpdateRequested += SourceDataModelOnUpdateRequested;
|
||||
TargetSelectionViewModel = _dataModelUIService.GetDataModelSelectionViewModel(_profileEditorService.GetCurrentModule());
|
||||
TargetSelectionViewModel.PropertySelected += TargetSelectionViewModelOnPropertySelected;
|
||||
|
||||
Update();
|
||||
|
||||
@@ -151,31 +144,30 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (DataBinding == null || SourceDataModel == null)
|
||||
if (DataBinding == null)
|
||||
{
|
||||
TargetSelectionViewModel.IsEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine the source property
|
||||
if (DataBinding.SourceDataModel == null)
|
||||
SelectedSourceProperty = null;
|
||||
else
|
||||
SelectedSourceProperty = SourceDataModel.GetChildByPath(DataBinding.SourceDataModel.PluginInfo.Guid, DataBinding.SourcePropertyPath);
|
||||
TargetSelectionViewModel.IsEnabled = true;
|
||||
TargetSelectionViewModel.PopulateSelectedPropertyViewModel(DataBinding.SourceDataModel, DataBinding.SourcePropertyPath);
|
||||
TargetSelectionViewModel.FilterTypes = new[] {DataBinding.TargetProperty.PropertyType};
|
||||
}
|
||||
|
||||
private void SourceDataModelOnUpdateRequested(object sender, EventArgs e)
|
||||
private void TargetSelectionViewModelOnPropertySelected(object sender, DataModelPropertySelectedEventArgs e)
|
||||
{
|
||||
SourceDataModel.ApplyTypeFilter(true, DataBinding.TargetProperty.PropertyType);
|
||||
DataBinding.UpdateSource(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
|
||||
}
|
||||
|
||||
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
UpdateTestResult();
|
||||
if (SourceDataModelOpen)
|
||||
SourceDataModel.Update(_dataModelUIService);
|
||||
}
|
||||
|
||||
private void UpdateTestResult()
|
||||
{
|
||||
var currentValue = SelectedSourceProperty?.GetCurrentValue();
|
||||
var currentValue = TargetSelectionViewModel.SelectedPropertyViewModel?.GetCurrentValue();
|
||||
if (currentValue == null && TargetProperty.PropertyType.IsValueType)
|
||||
currentValue = Activator.CreateInstance(TargetProperty.PropertyType);
|
||||
|
||||
@@ -183,18 +175,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
TestResultValue = DataBinding?.GetValue(TestInputValue);
|
||||
}
|
||||
|
||||
public object TestInputValue
|
||||
{
|
||||
get => _testInputValue;
|
||||
set => SetAndNotify(ref _testInputValue, value);
|
||||
}
|
||||
|
||||
public object TestResultValue
|
||||
{
|
||||
get => _testResultValue;
|
||||
set => SetAndNotify(ref _testResultValue, value);
|
||||
}
|
||||
|
||||
private void UpdateModifierViewModels()
|
||||
{
|
||||
ModifierViewModels.Clear();
|
||||
@@ -205,15 +185,5 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
ModifierViewModels.Add(_dataBindingsVmFactory.DataBindingModifierViewModel(dataBindingModifier));
|
||||
}
|
||||
|
||||
private void ExecuteSelectSourceProperty(object context)
|
||||
{
|
||||
if (!(context is DataModelVisualizationViewModel selected))
|
||||
return;
|
||||
|
||||
DataBinding.UpdateSource(selected.DataModel, selected.PropertyPath);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user