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

Conditions UI - Open dropdowns automatically when editing static values

Conditions UI - Added missing defaults for enum/bool
Data models - Use enum descriptions in display
This commit is contained in:
SpoinkyNL 2020-10-17 11:36:00 +02:00
parent 7ccfe775fd
commit ceccc7ceec
9 changed files with 23 additions and 34 deletions

View File

@ -58,7 +58,7 @@ namespace Artemis.Core.DataModelExpansions
/// <param name="key">The key of the child, must be unique to this data model</param>
/// <param name="name">An optional name, if not provided the key will be used in a humanized form</param>
/// <param name="description">An optional description</param>
public DataModel AddDynamicChild(DataModel dynamicDataModel, string key, string name = null, string description = null)
public T AddDynamicChild<T>(T dynamicDataModel, string key, string name = null, string description = null) where T : DataModel
{
if (dynamicDataModel == null)
throw new ArgumentNullException(nameof(dynamicDataModel));

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -45,7 +45,8 @@ namespace Artemis.UI.Shared
}
DisplayValue = GetCurrentValue();
DisplayValueType = DataModelPath.GetPropertyType();
DisplayValueType = DisplayValue != null ? DisplayValue.GetType() : DataModelPath.GetPropertyType();
UpdateDisplayParameters();
}

View File

@ -1,4 +1,6 @@
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display
using System;
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display
{
public class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<object>
{
@ -24,6 +26,9 @@
protected override void OnDisplayValueUpdated()
{
if (DisplayValue is Enum enumDisplayValue)
DisplayValue = EnumUtilities.HumanizeValue(enumDisplayValue);
ShowToString = DisplayValue != null;
ShowNull = DisplayValue == null;
}

View File

@ -216,13 +216,6 @@ namespace Artemis.UI.Shared.Services
private DataModelInputViewModel InstantiateDataModelInputViewModel(DataModelVisualizationRegistration registration, DataModelPropertyAttribute description, object initialValue)
{
// The view models expecting value types shouldn't be given null, avoid that
if (registration.SupportedType.IsValueType)
{
if (initialValue == null)
initialValue = Activator.CreateInstance(registration.SupportedType);
}
// This assumes the type can be converted, that has been checked when the VM was created
if (initialValue != null && initialValue.GetType() != registration.SupportedType)
initialValue = Convert.ChangeType(initialValue, registration.SupportedType);

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using Humanizer;
@ -12,23 +10,6 @@ namespace Artemis.UI.Shared
/// </summary>
public static class EnumUtilities
{
/// <summary>
/// Gets a human readable description of the given enum value
/// </summary>
/// <param name="value">The value to get a description for</param>
/// <returns>A human readable description of the given enum value</returns>
public static string Description(this Enum value)
{
object[] attributes = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes.Any())
return (attributes.First() as DescriptionAttribute).Description;
// If no description is found, the least we can do is replace underscores with spaces
// You can add your own custom default formatting logic here
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
return ti.ToTitleCase(ti.ToLower(value.ToString().Replace("_", " ")));
}
/// <summary>
/// Creates a list containing a <see cref="ValueDescription" /> for each value in the enum type
/// </summary>

View File

@ -14,7 +14,8 @@
<ComboBox Width="140"
materialDesign:ComboBoxAssist.ClassicMode="True"
materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left">
HorizontalAlignment="Left"
IsDropDownOpen="True">
<ComboBoxItem Content="True" IsSelected="{Binding InputValue}" />
<ComboBoxItem Content="False" IsSelected="{Binding InputValue, Converter={StaticResource InverseBooleanConverter}}"/>
</ComboBox>

View File

@ -13,5 +13,6 @@
ItemsSource="{Binding Path=EnumValues}"
SelectedValuePath="Value"
DisplayMemberPath="Description"
SelectedValue="{Binding Path=InputValue}" />
SelectedValue="{Binding Path=InputValue}"
IsDropDownOpen="True"/>
</UserControl>

View File

@ -113,14 +113,16 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
if (DataModelConditionPredicate.Operator == null)
DataModelConditionPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType ?? typeof(object))));
SelectedOperator = DataModelConditionPredicate.Operator;
if (SelectedOperator == null || !SelectedOperator.SupportsRightSide)
{
DisposeRightSideStaticViewModel();
DisposeRightSideDynamicViewModel();
return;
}
// Ensure the right side has the proper VM
if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic && SelectedOperator.SupportsRightSide)
if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
{
DisposeRightSideStaticViewModel();
if (RightSideSelectionViewModel == null)
@ -129,13 +131,16 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
RightSideSelectionViewModel.ChangeDataModelPath(DataModelConditionPredicate.RightPath);
RightSideSelectionViewModel.FilterTypes = new[] {leftSideType};
}
else if (SelectedOperator.SupportsRightSide)
else
{
DisposeRightSideDynamicViewModel();
if (RightSideInputViewModel == null)
CreateRightSideInputViewModel(leftSideType);
RightSideInputViewModel.Value = DataModelConditionPredicate.RightStaticValue;
if (leftSideType != null && leftSideType.IsValueType && DataModelConditionPredicate.RightStaticValue == null)
RightSideInputViewModel.Value = leftSideType.GetDefault();
else
RightSideInputViewModel.Value = DataModelConditionPredicate.RightStaticValue;
if (RightSideInputViewModel.TargetType != leftSideType)
RightSideInputViewModel.UpdateTargetType(leftSideType);
}