From a3906e3fe3dc4bf20b1d11c56f4f769e5df45c6d Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 21 Oct 2020 19:33:05 +0200 Subject: [PATCH] Data model debugger - Display ToString of object if overridden --- .../Shared/DataModelPropertiesViewModel.cs | 19 ++++++++++++++++++- .../DataModelConditions.xaml | 13 ++++++++++++- .../Debug/Tabs/DataModelDebugView.xaml | 5 +++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertiesViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertiesViewModel.cs index 57623d7b4..0f02e7d16 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertiesViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Shared/DataModelPropertiesViewModel.cs @@ -8,20 +8,35 @@ namespace Artemis.UI.Shared public class DataModelPropertiesViewModel : DataModelVisualizationViewModel { private Type _displayValueType; + private object _displayValue; internal DataModelPropertiesViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath) { } - + public Type DisplayValueType { get => _displayValueType; set => SetAndNotify(ref _displayValueType, value); } + public object DisplayValue + { + get => _displayValue; + set => SetAndNotify(ref _displayValue, value); + } + public override void Update(IDataModelUIService dataModelUIService) { DisplayValueType = DataModelPath?.GetPropertyType(); + + // Only set a display value if ToString returns useful information and not just the type name + object currentValue = GetCurrentValue(); + if (currentValue != null && currentValue.ToString() != currentValue.GetType().ToString()) + DisplayValue = currentValue.ToString(); + else + DisplayValue = null; + // Always populate properties PopulateProperties(dataModelUIService); @@ -35,6 +50,8 @@ namespace Artemis.UI.Shared public override object GetCurrentValue() { + if (Parent == null) + return null; return Parent.IsRootViewModel ? DataModel : base.GetCurrentValue(); } diff --git a/src/Artemis.UI.Shared/ResourceDictionaries/DataModelConditions.xaml b/src/Artemis.UI.Shared/ResourceDictionaries/DataModelConditions.xaml index a203f4403..0bd2eb41a 100644 --- a/src/Artemis.UI.Shared/ResourceDictionaries/DataModelConditions.xaml +++ b/src/Artemis.UI.Shared/ResourceDictionaries/DataModelConditions.xaml @@ -54,7 +54,18 @@ - + + + + + + + + + + + + diff --git a/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugView.xaml b/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugView.xaml index 429cf4e16..2b211033c 100644 --- a/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugView.xaml +++ b/src/Artemis.UI/Screens/Settings/Debug/Tabs/DataModelDebugView.xaml @@ -65,6 +65,7 @@ + @@ -72,6 +73,10 @@ [] +