From b77a55bf6fcf575219ee2991c76c96514a8b006e Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 13 Dec 2021 06:26:54 -0500 Subject: [PATCH] Merge pull request #7146 from workgroupengineering/fixes/DevTools/DrillDown fixes(DevTools): do not drill down on double click when property type is string or ValueType. # Conflicts: # src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs --- .../ViewModels/AvaloniaPropertyViewModel.cs | 8 ++++---- .../ViewModels/ClrPropertyViewModel.cs | 6 +++--- .../ViewModels/ControlDetailsViewModel.cs | 16 ++++++++++------ .../Diagnostics/ViewModels/PropertyViewModel.cs | 2 +- .../Diagnostics/Views/ControlDetailsView.xaml | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs index 8ce99d5375..04fc038e2b 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/AvaloniaPropertyViewModel.cs @@ -3,7 +3,7 @@ namespace Avalonia.Diagnostics.ViewModels internal class AvaloniaPropertyViewModel : PropertyViewModel { private readonly AvaloniaObject _target; - private string _type; + private System.Type _type; private object? _value; private string _priority; private string _group; @@ -32,7 +32,7 @@ namespace Avalonia.Diagnostics.ViewModels public override string Priority => _priority; - public override string Type => _type; + public override System.Type Type => _type; public override string Value { @@ -58,7 +58,7 @@ namespace Avalonia.Diagnostics.ViewModels if (Property.IsDirect) { RaiseAndSetIfChanged(ref _value, _target.GetValue(Property), nameof(Value)); - RaiseAndSetIfChanged(ref _type, _value?.GetType().Name ?? Property.PropertyType.Name, nameof(Type)); + RaiseAndSetIfChanged(ref _type, _value?.GetType() ?? Property.PropertyType, nameof(Type)); RaiseAndSetIfChanged(ref _priority, "Direct", nameof(Priority)); _group = "Properties"; @@ -68,7 +68,7 @@ namespace Avalonia.Diagnostics.ViewModels var val = _target.GetDiagnostic(Property); RaiseAndSetIfChanged(ref _value, val?.Value, nameof(Value)); - RaiseAndSetIfChanged(ref _type, _value?.GetType().Name ?? Property.PropertyType.Name, nameof(Type)); + RaiseAndSetIfChanged(ref _type, _value?.GetType() ?? Property.PropertyType, nameof(Type)); if (val != null) { diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs index 0a851f4a19..d5748c1d8d 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ClrPropertyViewModel.cs @@ -5,7 +5,7 @@ namespace Avalonia.Diagnostics.ViewModels internal class ClrPropertyViewModel : PropertyViewModel { private readonly object _target; - private string _type; + private System.Type _type; private object? _value; #nullable disable @@ -33,7 +33,7 @@ namespace Avalonia.Diagnostics.ViewModels public override string Name { get; } public override string Group => "CLR Properties"; - public override string Type => _type; + public override System.Type Type => _type; public override string Value { @@ -62,7 +62,7 @@ namespace Avalonia.Diagnostics.ViewModels { var val = Property.GetValue(_target); RaiseAndSetIfChanged(ref _value, val, nameof(Value)); - RaiseAndSetIfChanged(ref _type, _value?.GetType().Name ?? Property.PropertyType.Name, nameof(Type)); + RaiseAndSetIfChanged(ref _type, _value?.GetType() ?? Property.PropertyType, nameof(Type)); } } } diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs index 0b5cca89ba..f18967356d 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs @@ -403,7 +403,11 @@ namespace Avalonia.Diagnostics.ViewModels var selectedProperty = SelectedProperty; var selectedEntity = SelectedEntity; var selectedEntityName = SelectedEntityName; - if (selectedEntity == null || selectedProperty == null) + if (selectedEntity == null + || selectedProperty == null + || selectedProperty.Type == typeof(string) + || selectedProperty.Type.IsValueType + ) return; object? property; @@ -413,11 +417,11 @@ namespace Avalonia.Diagnostics.ViewModels } else { - property = _selectedEntity.GetType().GetProperties() - .FirstOrDefault(pi => pi.Name == _selectedProperty?.Name - && pi.DeclaringType == _selectedProperty.DeclaringType - && pi.PropertyType.Name == _selectedProperty.Type) - ?.GetValue(_selectedEntity); + property = selectedEntity.GetType().GetProperties() + .FirstOrDefault(pi => pi.Name == selectedProperty.Name + && pi.DeclaringType == selectedProperty.DeclaringType + && pi.PropertyType.Name == selectedProperty.Type.Name) + ?.GetValue(selectedEntity); } if (property == null) return; _selectedEntitiesStack.Push(new (SelectedEntityName, SelectedEntity)); diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/PropertyViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/PropertyViewModel.cs index 173dcd165a..557ad64d86 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/PropertyViewModel.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/PropertyViewModel.cs @@ -14,7 +14,7 @@ namespace Avalonia.Diagnostics.ViewModels public abstract object Key { get; } public abstract string Name { get; } public abstract string Group { get; } - public abstract string Type { get; } + public abstract Type Type { get; } public abstract Type? DeclaringType { get; } public abstract string Value { get; set; } public abstract string Priority { get; } diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml index 948152ef44..a7766bebf3 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml @@ -39,7 +39,7 @@ - +