mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Data model paths - Moved all condition code over to the new pats API
This commit is contained in:
1 parent
94bde1fe38
commit
d46a610e23
25 files changed
+238
-179
No files matched your search
@@ -15,16 +15,12 @@ namespace Artemis.UI.Shared
|
||||
else
|
||||
direction = (Parameters) Enum.Parse(typeof(Parameters), (string) parameter);
|
||||
|
||||
if (direction == Parameters.Normal)
|
||||
{
|
||||
if (value == null)
|
||||
return Visibility.Collapsed;
|
||||
return Visibility.Visible;
|
||||
}
|
||||
if (value is string stringValue && string.IsNullOrWhiteSpace(stringValue))
|
||||
value = null;
|
||||
|
||||
if (value == null)
|
||||
return Visibility.Visible;
|
||||
return Visibility.Collapsed;
|
||||
if (direction == Parameters.Normal)
|
||||
return value == null ? Visibility.Collapsed : Visibility.Visible;
|
||||
return value == null ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared"
|
||||
xmlns:input="clr-namespace:Artemis.UI.Shared.Input"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance input:DataModelDynamicViewModel}">
|
||||
@@ -30,7 +31,7 @@
|
||||
<Button Background="{Binding ButtonBrush}"
|
||||
BorderBrush="{Binding ButtonBrush}"
|
||||
Style="{StaticResource DataModelConditionButton}"
|
||||
ToolTip="{Binding SelectedPropertyViewModel.DisplayPath}"
|
||||
ToolTip="{Binding DisplayPath}"
|
||||
IsEnabled="{Binding IsEnabled}"
|
||||
HorizontalAlignment="Left"
|
||||
Click="PropertyButton_OnClick">
|
||||
@@ -50,11 +51,17 @@
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding DisplayValue}"
|
||||
Visibility="{Binding DataModelPath, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<Grid Visibility="{Binding IsValid,Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||
<TextBlock Text="{Binding DisplayValue}"
|
||||
Visibility="{Binding DataModelPath, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock FontStyle="Italic"
|
||||
Visibility="{Binding DataModelPath, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
<TextBlock FontStyle="Italic"
|
||||
Visibility="{Binding DataModelPath, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
|
||||
Visibility="{Binding IsValid, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||
« Invalid »
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</Button>
|
||||
|
||||
@@ -83,15 +83,30 @@ namespace Artemis.UI.Shared.Input
|
||||
|
||||
public DataModelPath DataModelPath
|
||||
{
|
||||
private get => _dataModelPath;
|
||||
set
|
||||
get => _dataModelPath;
|
||||
private set
|
||||
{
|
||||
if (!SetAndNotify(ref _dataModelPath, value)) return;
|
||||
NotifyOfPropertyChange(nameof(IsValid));
|
||||
NotifyOfPropertyChange(nameof(DisplayValue));
|
||||
NotifyOfPropertyChange(nameof(DisplayPath));
|
||||
}
|
||||
}
|
||||
|
||||
public string DisplayValue => DataModelPath.GetPropertyDescription()?.Name ?? DataModelPath.Segments.LastOrDefault()?.Identifier;
|
||||
public bool IsValid => DataModelPath?.IsValid ?? true;
|
||||
public string DisplayValue => DataModelPath?.GetPropertyDescription()?.Name ?? DataModelPath?.Segments.LastOrDefault()?.Identifier;
|
||||
|
||||
public string DisplayPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataModelPath == null)
|
||||
return "Click to select a property";
|
||||
if (!DataModelPath.IsValid)
|
||||
return "Invalid path";
|
||||
return string.Join(" › ", DataModelPath.Segments.Select(s => s.GetPropertyDescription()?.Name ?? s.Identifier));
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeDataModel(DataModelPropertiesViewModel dataModel)
|
||||
{
|
||||
@@ -104,6 +119,12 @@ namespace Artemis.UI.Shared.Input
|
||||
DataModelViewModel.UpdateRequested += DataModelOnUpdateRequested;
|
||||
}
|
||||
|
||||
public void ChangeDataModelPath(DataModelPath dataModelPath)
|
||||
{
|
||||
DataModelPath?.Dispose();
|
||||
DataModelPath = dataModelPath != null ? new DataModelPath(dataModelPath) : null;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Get the data models
|
||||
@@ -130,7 +151,7 @@ namespace Artemis.UI.Shared.Input
|
||||
if (!(context is DataModelVisualizationViewModel selected))
|
||||
return;
|
||||
|
||||
DataModelPath = selected.DataModelPath;
|
||||
ChangeDataModelPath(selected.DataModelPath);
|
||||
OnPropertySelected(new DataModelInputDynamicEventArgs(DataModelPath));
|
||||
}
|
||||
|
||||
@@ -139,6 +160,8 @@ namespace Artemis.UI.Shared.Input
|
||||
_updateTimer.Stop();
|
||||
_updateTimer.Dispose();
|
||||
_updateTimer.Elapsed -= OnUpdateTimerOnElapsed;
|
||||
|
||||
DataModelPath?.Dispose();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
@@ -32,13 +32,7 @@
|
||||
Visibility="{Binding InputViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Grid>
|
||||
<StackPanel Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}}" Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Light"
|
||||
Text="{Binding TargetDescription.Prefix}"
|
||||
Visibility="{Binding TargetDescription.Prefix, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<ContentControl s:View.Model="{Binding DisplayViewModel}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
|
||||
<TextBlock FontWeight="Light"
|
||||
Text="{Binding TargetDescription.Affix}"
|
||||
Visibility="{Binding TargetDescription.Affix, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock FontStyle="Italic" Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
|
||||
@@ -23,14 +23,15 @@ namespace Artemis.UI.Shared.Input
|
||||
private object _value;
|
||||
private bool _isEnabled;
|
||||
|
||||
internal DataModelStaticViewModel(Type targetType, IDataModelUIService dataModelUIService)
|
||||
internal DataModelStaticViewModel(Type targetType, DataModelPropertyAttribute targetDescription, IDataModelUIService dataModelUIService)
|
||||
{
|
||||
_dataModelUIService = dataModelUIService;
|
||||
_rootView = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
|
||||
|
||||
TargetType = targetType;
|
||||
TargetDescription = targetDescription;
|
||||
IsEnabled = TargetType != null;
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), true);
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), TargetDescription, true);
|
||||
|
||||
if (_rootView != null)
|
||||
{
|
||||
@@ -117,7 +118,7 @@ namespace Artemis.UI.Shared.Input
|
||||
public void UpdateTargetType(Type target)
|
||||
{
|
||||
TargetType = target;
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), true);
|
||||
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType ?? typeof(object), TargetDescription, true);
|
||||
IsEnabled = TargetType != null;
|
||||
|
||||
// If null, clear the input
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ namespace Artemis.UI.Shared
|
||||
((ListPredicateWrapperDataModel)DataModel).UntypedValue = DisplayValue;
|
||||
|
||||
if (DisplayViewModel == null)
|
||||
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(DisplayValue.GetType(), true);
|
||||
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(DisplayValue.GetType(), PropertyDescription, true);
|
||||
|
||||
ListType = DisplayValue.GetType();
|
||||
UpdateDisplayParameters();
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace Artemis.UI.Shared
|
||||
protected DataModelVisualizationViewModel CreateListChild(IDataModelUIService dataModelUIService, Type listType)
|
||||
{
|
||||
// If a display VM was found, prefer to use that in any case
|
||||
DataModelDisplayViewModel typeViewModel = dataModelUIService.GetDataModelDisplayViewModel(listType);
|
||||
DataModelDisplayViewModel typeViewModel = dataModelUIService.GetDataModelDisplayViewModel(listType, PropertyDescription);
|
||||
if (typeViewModel != null)
|
||||
return new DataModelListPropertyViewModel(listType, typeViewModel);
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Artemis.UI.Shared
|
||||
|
||||
if (DisplayViewModel == null)
|
||||
{
|
||||
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(DataModelPath.GetPropertyType(), true);
|
||||
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(DataModelPath.GetPropertyType(), PropertyDescription, true);
|
||||
DisplayViewModel.PropertyDescription = DataModelPath.GetPropertyDescription();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ namespace Artemis.UI.Shared
|
||||
return null;
|
||||
|
||||
// If a display VM was found, prefer to use that in any case
|
||||
DataModelDisplayViewModel typeViewModel = dataModelUIService.GetDataModelDisplayViewModel(propertyType);
|
||||
DataModelDisplayViewModel typeViewModel = dataModelUIService.GetDataModelDisplayViewModel(propertyType, PropertyDescription);
|
||||
if (typeViewModel != null)
|
||||
return new DataModelPropertyViewModel(DataModel, this, dataModelPath) {DisplayViewModel = typeViewModel, Depth = depth};
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
|
||||
@@ -159,14 +159,24 @@ namespace Artemis.UI.Shared.Services
|
||||
}
|
||||
}
|
||||
|
||||
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, bool fallBackToDefault)
|
||||
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, DataModelPropertyAttribute description, bool fallBackToDefault)
|
||||
{
|
||||
lock (_registeredDataModelDisplays)
|
||||
{
|
||||
DataModelDisplayViewModel result;
|
||||
|
||||
DataModelVisualizationRegistration match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType);
|
||||
if (match != null)
|
||||
return (DataModelDisplayViewModel) match.PluginInfo.Kernel.Get(match.ViewModelType);
|
||||
return !fallBackToDefault ? null : _kernel.Get<DefaultDataModelDisplayViewModel>();
|
||||
result = (DataModelDisplayViewModel) match.PluginInfo.Kernel.Get(match.ViewModelType);
|
||||
else if (!fallBackToDefault)
|
||||
result = null;
|
||||
else
|
||||
result = _kernel.Get<DefaultDataModelDisplayViewModel>();
|
||||
|
||||
if (result != null)
|
||||
result.PropertyDescription = description;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,9 +209,9 @@ namespace Artemis.UI.Shared.Services
|
||||
return _kernel.Get<DataModelDynamicViewModel>(new ConstructorArgument("module", module));
|
||||
}
|
||||
|
||||
public DataModelStaticViewModel GetStaticInputViewModel(Type targetType)
|
||||
public DataModelStaticViewModel GetStaticInputViewModel(Type targetType, DataModelPropertyAttribute targetDescription)
|
||||
{
|
||||
return _kernel.Get<DataModelStaticViewModel>(new ConstructorArgument("targetType", targetType));
|
||||
return _kernel.Get<DataModelStaticViewModel>(new ConstructorArgument("targetType", targetType), new ConstructorArgument("targetDescription", targetDescription));
|
||||
}
|
||||
|
||||
private DataModelInputViewModel InstantiateDataModelInputViewModel(DataModelVisualizationRegistration registration, DataModelPropertyAttribute description, object initialValue)
|
||||
@@ -219,7 +229,7 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
IParameter[] parameters = new IParameter[]
|
||||
{
|
||||
new ConstructorArgument("description", description),
|
||||
new ConstructorArgument("targetDescription", description),
|
||||
new ConstructorArgument("initialValue", initialValue)
|
||||
};
|
||||
DataModelInputViewModel viewModel = (DataModelInputViewModel) registration.PluginInfo.Kernel.Get(registration.ViewModelType, parameters);
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace Artemis.UI.Shared.Services
|
||||
void RemoveDataModelInput(DataModelVisualizationRegistration registration);
|
||||
void RemoveDataModelDisplay(DataModelVisualizationRegistration registration);
|
||||
|
||||
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, bool fallBackToDefault = false);
|
||||
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, DataModelPropertyAttribute description, bool fallBackToDefault = false);
|
||||
DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action<object, bool> updateCallback);
|
||||
|
||||
DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module);
|
||||
DataModelStaticViewModel GetStaticInputViewModel(Type targetType);
|
||||
DataModelStaticViewModel GetStaticInputViewModel(Type targetType, DataModelPropertyAttribute targetDescription);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user