mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Conditions - Big refactor to prepare for conditional databindings
Conditions - Improved list-condition functionality
This commit is contained in:
1 parent
a646ff95ed
commit
8aba0a55ec
55 files changed
+1382
-1608
No files matched your search
@@ -13,7 +13,7 @@
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DisplayConditions.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DataModelConditions.xaml" />
|
||||
<ResourceDictionary>
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<shared:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
<Button Background="{Binding ButtonBrush}"
|
||||
BorderBrush="{Binding ButtonBrush}"
|
||||
Style="{StaticResource DisplayConditionButton}"
|
||||
Style="{StaticResource DataModelConditionButton}"
|
||||
ToolTip="{Binding SelectedPropertyViewModel.DisplayPropertyPath}"
|
||||
IsEnabled="{Binding IsEnabled}"
|
||||
HorizontalAlignment="Left"
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Artemis.UI.Shared.Input
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
||||
public Brush ButtonBrush
|
||||
{
|
||||
get => _buttonBrush;
|
||||
@@ -75,7 +75,7 @@ namespace Artemis.UI.Shared.Input
|
||||
public DataModelVisualizationViewModel SelectedPropertyViewModel
|
||||
{
|
||||
get => _selectedPropertyViewModel;
|
||||
private set => SetAndNotify(ref _selectedPropertyViewModel, value);
|
||||
set => SetAndNotify(ref _selectedPropertyViewModel, value);
|
||||
}
|
||||
|
||||
public void PopulateSelectedPropertyViewModel(DataModel datamodel, string path)
|
||||
@@ -86,6 +86,17 @@ namespace Artemis.UI.Shared.Input
|
||||
SelectedPropertyViewModel = DataModelViewModel.GetChildByPath(datamodel.PluginInfo.Guid, path);
|
||||
}
|
||||
|
||||
public void ChangeDataModel(DataModelPropertiesViewModel dataModel)
|
||||
{
|
||||
if (DataModelViewModel != null)
|
||||
DataModelViewModel.UpdateRequested -= DataModelOnUpdateRequested;
|
||||
|
||||
DataModelViewModel = dataModel;
|
||||
|
||||
if (DataModelViewModel != null)
|
||||
DataModelViewModel.UpdateRequested += DataModelOnUpdateRequested;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Get the data models
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DisplayConditions.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DataModelConditions.xaml" />
|
||||
<ResourceDictionary>
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</ResourceDictionary>
|
||||
@@ -22,12 +22,13 @@
|
||||
</UserControl.Resources>
|
||||
|
||||
<materialDesign:Transitioner SelectedIndex="{Binding TransitionIndex}" DefaultTransitionOrigin="0.5, 0.5" Margin="3 -4">
|
||||
<Button Style="{StaticResource DisplayConditionButton}"
|
||||
<Button Style="{StaticResource DataModelConditionButton}"
|
||||
Background="{Binding ButtonBrush}"
|
||||
BorderBrush="{Binding ButtonBrush}"
|
||||
Margin="0 4"
|
||||
Command="{s:Action ActivateInputViewModel}"
|
||||
HorizontalAlignment="Left">
|
||||
HorizontalAlignment="Left"
|
||||
IsEnabled="{Binding IsEnabled}">
|
||||
<Grid>
|
||||
<StackPanel Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}}" Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Light"
|
||||
|
||||
@@ -22,15 +22,17 @@ namespace Artemis.UI.Shared.Input
|
||||
private Type _targetType;
|
||||
private int _transitionIndex;
|
||||
private object _value;
|
||||
private bool _isEnabled;
|
||||
|
||||
internal DataModelStaticViewModel(Type targetType, IDataModelUIService dataModelUIService)
|
||||
{
|
||||
TargetType = targetType;
|
||||
_dataModelUIService = dataModelUIService;
|
||||
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType, true);
|
||||
|
||||
_rootView = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
|
||||
|
||||
TargetType = targetType;
|
||||
IsEnabled = TargetType != null;
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), true);
|
||||
|
||||
if (_rootView != null)
|
||||
{
|
||||
_rootView.MouseUp += RootViewOnMouseUp;
|
||||
@@ -90,6 +92,12 @@ namespace Artemis.UI.Shared.Input
|
||||
set => SetAndNotify(ref _placeholder, value);
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
private set => SetAndNotify(ref _isEnabled, value);
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
@@ -116,16 +124,26 @@ namespace Artemis.UI.Shared.Input
|
||||
|
||||
public void UpdateTargetType(Type target)
|
||||
{
|
||||
TargetType = target ?? throw new ArgumentNullException(nameof(target));
|
||||
TargetType = target;
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), true);
|
||||
IsEnabled = TargetType != null;
|
||||
|
||||
// If null, clear the input
|
||||
if (TargetType == null)
|
||||
{
|
||||
ApplyFreeInput(null, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the type changed, reset to the default type
|
||||
if (!target.IsCastableFrom(Value.GetType()))
|
||||
if (Value == null || !target.IsCastableFrom(Value.GetType()))
|
||||
{
|
||||
// Force the VM to close if it was open and apply the new value
|
||||
ApplyFreeInput(target.GetDefault(), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ApplyFreeInput(object value, bool submitted)
|
||||
{
|
||||
if (submitted)
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Artemis.UI.Shared
|
||||
public DataModelPropertiesViewModel GetListTypeViewModel(IDataModelUIService dataModelUIService)
|
||||
{
|
||||
// Create a property VM describing the type of the list
|
||||
var viewModel = CreateListChild(dataModelUIService, List.GetType().GenericTypeArguments[0]);
|
||||
var viewModel = CreateListChild(dataModelUIService, PropertyInfo.PropertyType.GenericTypeArguments[0]);
|
||||
|
||||
// Put an empty value into the list type property view model
|
||||
if (viewModel is DataModelListPropertiesViewModel dataModelListClassViewModel)
|
||||
|
||||
+3
-3
@@ -176,9 +176,9 @@ namespace Artemis.UI.Shared
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t == PropertyInfo.PropertyType || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel GetChildForCondition(DataModelConditionPredicate predicate, DisplayConditionSide side)
|
||||
public DataModelVisualizationViewModel GetChildForCondition(DataModelConditionPredicate predicate, DataModelConditionSide side)
|
||||
{
|
||||
if (side == DisplayConditionSide.Left)
|
||||
if (side == DataModelConditionSide.Left)
|
||||
{
|
||||
if (predicate.LeftDataModel == null || predicate.LeftPropertyPath == null)
|
||||
return null;
|
||||
@@ -289,7 +289,7 @@ namespace Artemis.UI.Shared
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum DisplayConditionSide
|
||||
public enum DataModelConditionSide
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
<Grid>
|
||||
<!-- Value display -->
|
||||
<TextBlock Text="{Binding DisplayValue, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
<TextBlock Text="null"
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:dataModel="clr-namespace:Artemis.UI.Shared">
|
||||
<Style x:Key="DisplayConditionButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFlatAccentBgButton}">
|
||||
<Style x:Key="DataModelConditionButton" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFlatAccentBgButton}">
|
||||
<Setter Property="Margin" Value="3 0" />
|
||||
<Setter Property="Padding" Value="6 4" />
|
||||
<Setter Property="Height" Value="22" />
|
||||
@@ -11,7 +11,7 @@
|
||||
<Setter Property="FontSize" Value="12" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="DisplayConditionButtonLeftClickMenu" TargetType="{x:Type Button}" BasedOn="{StaticResource DisplayConditionButton}">
|
||||
<Style x:Key="DataModelConditionButtonLeftClickMenu" TargetType="{x:Type Button}" BasedOn="{StaticResource DataModelConditionButton}">
|
||||
<Style.Triggers>
|
||||
<EventTrigger RoutedEvent="Click">
|
||||
<EventTrigger.Actions>
|
||||
@@ -201,7 +201,6 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
public DataModelStaticViewModel GetStaticInputViewModel(Type targetType)
|
||||
{
|
||||
if (targetType == null) throw new ArgumentNullException(nameof(targetType));
|
||||
return _kernel.Get<DataModelStaticViewModel>(new ConstructorArgument("targetType", targetType));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user