Browse Source

fixes(DevTools): Null Annotations

pull/6954/head
Giuseppe Lippolis 5 years ago
parent
commit
69126a7967
  1. 25
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs
  2. 2
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs

25
src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs

@ -17,16 +17,16 @@ namespace Avalonia.Diagnostics.ViewModels
internal class ControlDetailsViewModel : ViewModelBase, IDisposable internal class ControlDetailsViewModel : ViewModelBase, IDisposable
{ {
private readonly IVisual _control; private readonly IVisual _control;
private IDictionary<object, List<PropertyViewModel>> _propertyIndex; private IDictionary<object, List<PropertyViewModel>>? _propertyIndex;
private PropertyViewModel? _selectedProperty; private PropertyViewModel? _selectedProperty;
private DataGridCollectionView _propertiesView; private DataGridCollectionView? _propertiesView;
private bool _snapshotStyles; private bool _snapshotStyles;
private bool _showInactiveStyles; private bool _showInactiveStyles;
private string? _styleStatus; private string? _styleStatus;
private object _selectedEntity; private object? _selectedEntity;
private readonly Stack<(string Name,object Entry)> _selectedEntitiesStack = new(); private readonly Stack<(string Name,object Entry)> _selectedEntitiesStack = new();
private string _selectedEntityName; private string? _selectedEntityName;
private string _selectedEntityType; private string? _selectedEntityType;
public ControlDetailsViewModel(TreePageViewModel treePage, IVisual control) public ControlDetailsViewModel(TreePageViewModel treePage, IVisual control)
{ {
@ -117,7 +117,7 @@ namespace Avalonia.Diagnostics.ViewModels
public TreePageViewModel TreePage { get; } public TreePageViewModel TreePage { get; }
public DataGridCollectionView PropertiesView public DataGridCollectionView? PropertiesView
{ {
get => _propertiesView; get => _propertiesView;
private set => RaiseAndSetIfChanged(ref _propertiesView, value); private set => RaiseAndSetIfChanged(ref _propertiesView, value);
@ -127,7 +127,7 @@ namespace Avalonia.Diagnostics.ViewModels
public ObservableCollection<PseudoClassViewModel> PseudoClasses { get; } public ObservableCollection<PseudoClassViewModel> PseudoClasses { get; }
public object SelectedEntity public object? SelectedEntity
{ {
get => _selectedEntity; get => _selectedEntity;
set set
@ -137,7 +137,7 @@ namespace Avalonia.Diagnostics.ViewModels
} }
} }
public string SelectedEntityName public string? SelectedEntityName
{ {
get => _selectedEntityName; get => _selectedEntityName;
set set
@ -147,7 +147,7 @@ namespace Avalonia.Diagnostics.ViewModels
} }
} }
public string SelectedEntityType public string? SelectedEntityType
{ {
get => _selectedEntityType; get => _selectedEntityType;
set set
@ -270,7 +270,7 @@ namespace Avalonia.Diagnostics.ViewModels
private void ControlPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) private void ControlPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{ {
if (_propertyIndex.TryGetValue(e.Property, out var properties)) if (_propertyIndex is { } && _propertyIndex.TryGetValue(e.Property, out var properties))
{ {
foreach (var property in properties) foreach (var property in properties)
{ {
@ -284,6 +284,7 @@ namespace Avalonia.Diagnostics.ViewModels
private void ControlPropertyChanged(object? sender, PropertyChangedEventArgs e) private void ControlPropertyChanged(object? sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName != null if (e.PropertyName != null
&& _propertyIndex is { }
&& _propertyIndex.TryGetValue(e.PropertyName, out var properties)) && _propertyIndex.TryGetValue(e.PropertyName, out var properties))
{ {
foreach (var property in properties) foreach (var property in properties)
@ -402,7 +403,7 @@ namespace Avalonia.Diagnostics.ViewModels
var selectedProperty = SelectedProperty; var selectedProperty = SelectedProperty;
var selectedEntity = SelectedEntity; var selectedEntity = SelectedEntity;
var selectedEntityName = SelectedEntityName; var selectedEntityName = SelectedEntityName;
if (selectedProperty == null) if (selectedEntity == null || selectedProperty == null)
return; return;
object? property; object? property;
@ -419,7 +420,7 @@ namespace Avalonia.Diagnostics.ViewModels
?.GetValue(selectedEntity); ?.GetValue(selectedEntity);
} }
if (property == null) return; if (property == null) return;
_selectedEntitiesStack.Push((Name:selectedEntityName,Entry:selectedEntity)); _selectedEntitiesStack.Push((Name:selectedEntityName!,Entry:selectedEntity));
NavigateToProperty(property, selectedProperty.Name); NavigateToProperty(property, selectedProperty.Name);
} }

2
src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs

@ -15,7 +15,7 @@ namespace Avalonia.Diagnostics.ViewModels
Nodes = nodes; Nodes = nodes;
PropertiesFilter = new FilterViewModel(); PropertiesFilter = new FilterViewModel();
PropertiesFilter.RefreshFilter += (s, e) => Details?.PropertiesView.Refresh(); PropertiesFilter.RefreshFilter += (s, e) => Details?.PropertiesView?.Refresh();
SettersFilter = new FilterViewModel(); SettersFilter = new FilterViewModel();
SettersFilter.RefreshFilter += (s, e) => Details?.UpdateStyleFilters(); SettersFilter.RefreshFilter += (s, e) => Details?.UpdateStyleFilters();

Loading…
Cancel
Save