diff --git a/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs b/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs index 3e8647d4d..b0ca3466c 100644 --- a/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs +++ b/src/Artemis.Core/Plugins/DataModelExpansions/DataModel.cs @@ -58,7 +58,7 @@ namespace Artemis.Core.DataModelExpansions /// The key of the child, must be unique to this data model /// An optional name, if not provided the key will be used in a humanized form /// An optional description - public DataModel AddDynamicChild(DataModel dynamicDataModel, string key, string name = null, string description = null) + public T AddDynamicChild(T dynamicDataModel, string key, string name = null, string description = null) where T : DataModel { if (dynamicDataModel == null) throw new ArgumentNullException(nameof(dynamicDataModel)); diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings new file mode 100644 index 000000000..6cbf8796d --- /dev/null +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertyViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertyViewModel.cs index 24dcd0a6e..10be7eb85 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertyViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertyViewModel.cs @@ -45,7 +45,8 @@ namespace Artemis.UI.Shared } DisplayValue = GetCurrentValue(); - DisplayValueType = DataModelPath.GetPropertyType(); + DisplayValueType = DisplayValue != null ? DisplayValue.GetType() : DataModelPath.GetPropertyType(); + UpdateDisplayParameters(); } diff --git a/src/Artemis.UI.Shared/DefaultTypes/DataModel/Display/DefaultDataModelDisplayViewModel.cs b/src/Artemis.UI.Shared/DefaultTypes/DataModel/Display/DefaultDataModelDisplayViewModel.cs index 07d51249d..15df20112 100644 --- a/src/Artemis.UI.Shared/DefaultTypes/DataModel/Display/DefaultDataModelDisplayViewModel.cs +++ b/src/Artemis.UI.Shared/DefaultTypes/DataModel/Display/DefaultDataModelDisplayViewModel.cs @@ -1,4 +1,6 @@ -namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display +using System; + +namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display { public class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel { @@ -24,6 +26,9 @@ protected override void OnDisplayValueUpdated() { + if (DisplayValue is Enum enumDisplayValue) + DisplayValue = EnumUtilities.HumanizeValue(enumDisplayValue); + ShowToString = DisplayValue != null; ShowNull = DisplayValue == null; } diff --git a/src/Artemis.UI.Shared/Services/DataModelUIService.cs b/src/Artemis.UI.Shared/Services/DataModelUIService.cs index db31a09d4..e5b440c9c 100644 --- a/src/Artemis.UI.Shared/Services/DataModelUIService.cs +++ b/src/Artemis.UI.Shared/Services/DataModelUIService.cs @@ -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); diff --git a/src/Artemis.UI.Shared/Utilities/EnumUtilities.cs b/src/Artemis.UI.Shared/Utilities/EnumUtilities.cs index 728fd7dc6..2c33e4bae 100644 --- a/src/Artemis.UI.Shared/Utilities/EnumUtilities.cs +++ b/src/Artemis.UI.Shared/Utilities/EnumUtilities.cs @@ -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 /// public static class EnumUtilities { - /// - /// Gets a human readable description of the given enum value - /// - /// The value to get a description for - /// A human readable description of the given enum value - 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("_", " "))); - } - /// /// Creates a list containing a for each value in the enum type /// diff --git a/src/Artemis.UI/DefaultTypes/DataModel/Input/BoolDataModelInputView.xaml b/src/Artemis.UI/DefaultTypes/DataModel/Input/BoolDataModelInputView.xaml index 957369e5e..8f83dad09 100644 --- a/src/Artemis.UI/DefaultTypes/DataModel/Input/BoolDataModelInputView.xaml +++ b/src/Artemis.UI/DefaultTypes/DataModel/Input/BoolDataModelInputView.xaml @@ -14,7 +14,8 @@ + HorizontalAlignment="Left" + IsDropDownOpen="True"> diff --git a/src/Artemis.UI/DefaultTypes/DataModel/Input/EnumDataModelInputView.xaml b/src/Artemis.UI/DefaultTypes/DataModel/Input/EnumDataModelInputView.xaml index ed763cb5d..6fd659d69 100644 --- a/src/Artemis.UI/DefaultTypes/DataModel/Input/EnumDataModelInputView.xaml +++ b/src/Artemis.UI/DefaultTypes/DataModel/Input/EnumDataModelInputView.xaml @@ -13,5 +13,6 @@ ItemsSource="{Binding Path=EnumValues}" SelectedValuePath="Value" DisplayMemberPath="Description" - SelectedValue="{Binding Path=InputValue}" /> + SelectedValue="{Binding Path=InputValue}" + IsDropDownOpen="True"/> \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionPredicateViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionPredicateViewModel.cs index fbc90b37b..e7579968f 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionPredicateViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionPredicateViewModel.cs @@ -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); }