Browse Source

Merge pull request #7860 from MarchingCube/devtools-property-nav

Style setter property navigation
pull/7882/head
Dariusz Komosiński 5 years ago
committed by GitHub
parent
commit
7dea60819e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/Avalonia.Base/StyledPropertyBase.cs
  2. 5
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/BindingSetterViewModel.cs
  3. 43
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlDetailsViewModel.cs
  4. 3
      src/Avalonia.Diagnostics/Diagnostics/ViewModels/ResourceSetterViewModel.cs
  5. 62
      src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml
  6. 24
      src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml.cs

10
src/Avalonia.Base/StyledPropertyBase.cs

@ -159,9 +159,9 @@ namespace Avalonia
}
/// <inheritdoc/>
public override void Accept<TData>(IAvaloniaPropertyVisitor<TData> vistor, ref TData data)
public override void Accept<TData>(IAvaloniaPropertyVisitor<TData> visitor, ref TData data)
{
vistor.Visit(this, ref data);
visitor.Visit(this, ref data);
}
/// <summary>
@ -242,11 +242,5 @@ namespace Avalonia
_ = type ?? throw new ArgumentNullException(nameof(type));
return GetMetadata(type).DefaultValue;
}
[DebuggerHidden]
private Func<IAvaloniaObject, TValue, TValue> Cast<THost>(Func<THost, TValue, TValue> validate)
{
return (o, v) => validate((THost)o, v);
}
}
}

5
src/Avalonia.Diagnostics/Diagnostics/ViewModels/BindingSetterViewModel.cs

@ -14,11 +14,13 @@ namespace Avalonia.Diagnostics.ViewModels
case Binding binding:
Path = binding.Path;
Tint = Brushes.CornflowerBlue;
ValueTypeTooltip = "Reflection Binding";
break;
case CompiledBindingExtension binding:
Path = binding.Path.ToString();
Tint = Brushes.DarkGreen;
ValueTypeTooltip = "Compiled Binding";
break;
case TemplateBinding binding:
@ -32,6 +34,7 @@ namespace Avalonia.Diagnostics.ViewModels
}
Tint = Brushes.OrangeRed;
ValueTypeTooltip = "Template Binding";
break;
default:
@ -40,6 +43,8 @@ namespace Avalonia.Diagnostics.ViewModels
}
public IBrush Tint { get; }
public string ValueTypeTooltip { get; }
public string Path { get; }

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

@ -155,31 +155,19 @@ namespace Avalonia.Diagnostics.ViewModels
public object? SelectedEntity
{
get => _selectedEntity;
set
{
RaiseAndSetIfChanged(ref _selectedEntity, value);
}
set => RaiseAndSetIfChanged(ref _selectedEntity, value);
}
public string? SelectedEntityName
{
get => _selectedEntityName;
set
{
RaiseAndSetIfChanged(ref _selectedEntityName, value);
}
set => RaiseAndSetIfChanged(ref _selectedEntityName, value);
}
public string? SelectedEntityType
{
get => _selectedEntityType;
set
{
RaiseAndSetIfChanged(ref _selectedEntityType, value);
}
set => RaiseAndSetIfChanged(ref _selectedEntityType, value);
}
public PropertyViewModel? SelectedProperty
@ -502,6 +490,31 @@ namespace Avalonia.Diagnostics.ViewModels
inpc2.PropertyChanged += ControlPropertyChanged;
}
}
internal void SelectProperty(AvaloniaProperty property)
{
SelectedProperty = null;
if (SelectedEntity != _avaloniaObject)
{
NavigateToProperty(_avaloniaObject, (_avaloniaObject as IControl)?.Name ?? _avaloniaObject.ToString());
}
if (PropertiesView is null)
{
return;
}
foreach (object o in PropertiesView)
{
if (o is AvaloniaPropertyViewModel propertyVm && propertyVm.Property == property)
{
SelectedProperty = propertyVm;
break;
}
}
}
internal void UpdatePropertiesView(bool showImplementedInterfaces)
{

3
src/Avalonia.Diagnostics/Diagnostics/ViewModels/ResourceSetterViewModel.cs

@ -7,11 +7,14 @@ namespace Avalonia.Diagnostics.ViewModels
public object Key { get; }
public IBrush Tint { get; }
public string ValueTypeTooltip { get; }
public ResourceSetterViewModel(AvaloniaProperty property, object resourceKey, object? resourceValue, bool isDynamic) : base(property, resourceValue)
{
Key = resourceKey;
Tint = isDynamic ? Brushes.Orange : Brushes.Brown;
ValueTypeTooltip = isDynamic ? "Dynamic Resource" : "Static Resource";
}
public void CopyResourceKey()

62
src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml

@ -44,7 +44,9 @@
UseWholeWordFilter="{Binding UseWholeWordFilter}"
UseRegexFilter="{Binding UseRegexFilter}"/>
<DataGrid Items="{Binding PropertiesView}"
<DataGrid
x:Name="DataGrid"
Items="{Binding PropertiesView}"
Grid.Row="2"
BorderThickness="0"
RowBackground="Transparent"
@ -129,6 +131,26 @@
</Expander.Header>
<ItemsControl Margin="20,0,0,0" Grid.Row="1" Items="{Binding Setters}">
<ItemsControl.Styles>
<Style Selector="TextBlock.property-name">
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Background" Value="Transparent" />
</Style>
<Style Selector="TextBlock.property-name:pointerover">
<Setter Property="TextDecorations" Value="Underline" />
</Style>
<Style Selector="Rectangle.property-inactive">
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="Height" Value="1" />
<Setter Property="Fill" Value="#6C6C6C" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</ItemsControl.Styles>
<ItemsControl.DataTemplates>
<DataTemplate DataType="IBrush">
@ -138,6 +160,17 @@
</StackPanel>
</DataTemplate>
<DataTemplate DataType="Color">
<StackPanel Orientation="Horizontal" Spacing="2">
<Border BorderThickness="1" BorderBrush="Black" Width="8" Height="8">
<Border.Background>
<SolidColorBrush Color="{Binding}" />
</Border.Background>
</Border>
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="vm:BindingSetterViewModel">
<Panel Opacity="{Binding IsActive, Converter={StaticResource BoolToOpacity}}" IsVisible="{Binding IsVisible}" HorizontalAlignment="Left">
<Panel.ContextMenu>
@ -147,28 +180,17 @@
</ContextMenu>
</Panel.ContextMenu>
<StackPanel Orientation="Horizontal" Spacing="2">
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
<TextBlock Classes="property-name" PointerPressed="PropertyNamePressed" Text="{Binding Name}" />
<TextBlock Text=":" />
<TextBlock>{</TextBlock>
<Rectangle Height="8" Width="8" VerticalAlignment="Center" Fill="{Binding Tint}"/>
<Rectangle Height="8" Width="8" VerticalAlignment="Center" Fill="{Binding Tint}" ToolTip.Tip="{Binding ValueTypeTooltip}"/>
<TextBlock Text="{Binding Path}" />
<TextBlock>}</TextBlock>
</StackPanel>
<Rectangle Height="1" Fill="#6C6C6C" VerticalAlignment="Center" IsVisible="{Binding !IsActive}" />
<Rectangle Classes="property-inactive" IsVisible="{Binding !IsActive}" />
</Panel>
</DataTemplate>
<DataTemplate DataType="Color">
<StackPanel Orientation="Horizontal" Spacing="2">
<Border BorderThickness="1" BorderBrush="Black" Width="8" Height="8">
<Border.Background>
<SolidColorBrush Color="{Binding}" />
</Border.Background>
</Border>
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="vm:ResourceSetterViewModel">
<Panel Opacity="{Binding IsActive, Converter={StaticResource BoolToOpacity}}" IsVisible="{Binding IsVisible}" HorizontalAlignment="Left">
<Panel.ContextMenu>
@ -179,15 +201,15 @@
</ContextMenu>
</Panel.ContextMenu>
<StackPanel Orientation="Horizontal" Spacing="2" HorizontalAlignment="Left">
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
<TextBlock Classes="property-name" PointerPressed="PropertyNamePressed" Text="{Binding Name}" />
<TextBlock Text=":" />
<ContentControl Content="{Binding Value}"/>
<TextBlock>(</TextBlock>
<Ellipse Height="8" Width="8" VerticalAlignment="Center" Fill="{Binding Tint}"/>
<Ellipse Height="8" Width="8" VerticalAlignment="Center" Fill="{Binding Tint}" ToolTip.Tip="{Binding ValueTypeTooltip}"/>
<TextBlock FontStyle="Italic" Text="{Binding Key}" />
<TextBlock>)</TextBlock>
</StackPanel>
<Rectangle Height="1" Fill="#6C6C6C" IsVisible="{Binding !IsActive}" />
<Rectangle Classes="property-inactive" IsVisible="{Binding !IsActive}" />
</Panel>
</DataTemplate>
@ -200,11 +222,11 @@
</ContextMenu>
</Panel.ContextMenu>
<StackPanel Orientation="Horizontal" Spacing="2">
<TextBlock Text="{Binding Name}" FontWeight="SemiBold" />
<TextBlock Classes="property-name" PointerPressed="PropertyNamePressed" Text="{Binding Name}" />
<TextBlock Text=":" />
<ContentControl Content="{Binding Value}"/>
</StackPanel>
<Rectangle Height="1" Fill="#6C6C6C" VerticalAlignment="Center" IsVisible="{Binding !IsActive}" />
<Rectangle Classes="property-inactive" IsVisible="{Binding !IsActive}" />
</Panel>
</DataTemplate>

24
src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml.cs

@ -7,9 +7,13 @@ namespace Avalonia.Diagnostics.Views
{
internal class ControlDetailsView : UserControl
{
private DataGrid _dataGrid;
public ControlDetailsView()
{
InitializeComponent();
_dataGrid = this.GetControl<DataGrid>("DataGrid");
}
private void InitializeComponent()
@ -25,5 +29,25 @@ namespace Avalonia.Diagnostics.Views
}
}
private void PropertyNamePressed(object sender, PointerPressedEventArgs e)
{
var mainVm = (ControlDetailsViewModel?) DataContext;
if (mainVm is null)
{
return;
}
if (sender is Control control && control.DataContext is SetterViewModel setterVm)
{
mainVm.SelectProperty(setterVm.Property);
if (mainVm.SelectedProperty is not null)
{
_dataGrid.ScrollIntoView(mainVm.SelectedProperty, null);
}
}
}
}
}

Loading…
Cancel
Save