Browse Source

Reformat Avalonia.Diagnostics.

pull/2757/head
Dariusz Komosinski 7 years ago
parent
commit
4f83c4e8c7
  1. 3
      .editorconfig
  2. 36
      src/Avalonia.Diagnostics/DevTools.xaml
  3. 33
      src/Avalonia.Diagnostics/DevTools.xaml.cs
  4. 7
      src/Avalonia.Diagnostics/Models/EventChainLink.cs
  5. 12
      src/Avalonia.Diagnostics/ViewModels/ControlDetailsViewModel.cs
  6. 1
      src/Avalonia.Diagnostics/ViewModels/DevToolsViewModel.cs
  7. 15
      src/Avalonia.Diagnostics/ViewModels/EventOwnerTreeNode.cs
  8. 9
      src/Avalonia.Diagnostics/ViewModels/EventTreeNode.cs
  9. 17
      src/Avalonia.Diagnostics/ViewModels/EventTreeNodeBase.cs
  10. 12
      src/Avalonia.Diagnostics/ViewModels/FiredEvent.cs
  11. 3
      src/Avalonia.Diagnostics/ViewModels/LogicalTreeNode.cs
  12. 16
      src/Avalonia.Diagnostics/ViewModels/PropertyDetails.cs
  13. 15
      src/Avalonia.Diagnostics/ViewModels/TreeNode.cs
  14. 22
      src/Avalonia.Diagnostics/ViewModels/TreePageViewModel.cs
  15. 5
      src/Avalonia.Diagnostics/ViewModels/VisualTreeNode.cs
  16. 17
      src/Avalonia.Diagnostics/Views/ControlDetailsView.cs
  17. 100
      src/Avalonia.Diagnostics/Views/EventsView.xaml
  18. 8
      src/Avalonia.Diagnostics/Views/EventsView.xaml.cs
  19. 3
      src/Avalonia.Diagnostics/Views/GridRepeater.cs
  20. 10
      src/Avalonia.Diagnostics/Views/PropertyChangedExtensions.cs
  21. 8
      src/Avalonia.Diagnostics/Views/SimpleGrid.cs
  22. 12
      src/Avalonia.Diagnostics/Views/TreePageView.xaml
  23. 4
      src/Avalonia.Diagnostics/Views/TreePageView.xaml.cs

3
.editorconfig

@ -131,13 +131,14 @@ csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false csharp_space_between_square_brackets = false
space_within_single_line_array_initializer_braces = true
# Wrapping preferences # Wrapping preferences
csharp_wrap_before_ternary_opsigns = false csharp_wrap_before_ternary_opsigns = false
# Xaml files # Xaml files
[*.xaml] [*.xaml]
indent_size = 4 indent_size = 2
# Xml project files # Xml project files
[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]

36
src/Avalonia.Diagnostics/DevTools.xaml

@ -1,24 +1,24 @@
<UserControl xmlns="https://github.com/avaloniaui" <UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Avalonia.Diagnostics.DevTools"> x:Class="Avalonia.Diagnostics.DevTools">
<Grid RowDefinitions="*,Auto" Margin="4"> <Grid RowDefinitions="*,Auto" Margin="4">
<TabControl Grid.Row="0" Items="{Binding Tools}" SelectedItem="{Binding SelectedTool}"> <TabControl Grid.Row="0" Items="{Binding Tools}" SelectedItem="{Binding SelectedTool}">
<TabControl.ItemTemplate> <TabControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Name}" />
</DataTemplate> </DataTemplate>
</TabControl.ItemTemplate> </TabControl.ItemTemplate>
</TabControl> </TabControl>
<StackPanel Grid.Row="1" Spacing="4" Orientation="Horizontal"> <StackPanel Grid.Row="1" Spacing="4" Orientation="Horizontal">
<TextBlock>Hold Ctrl+Shift over a control to inspect.</TextBlock> <TextBlock>Hold Ctrl+Shift over a control to inspect.</TextBlock>
<Separator Width="8" /> <Separator Width="8" />
<TextBlock>Focused:</TextBlock> <TextBlock>Focused:</TextBlock>
<TextBlock Text="{Binding FocusedControl}" /> <TextBlock Text="{Binding FocusedControl}" />
<Separator Width="8" /> <Separator Width="8" />
<TextBlock>Pointer Over:</TextBlock> <TextBlock>Pointer Over:</TextBlock>
<TextBlock Text="{Binding PointerOverElement}" /> <TextBlock Text="{Binding PointerOverElement}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

33
src/Avalonia.Diagnostics/DevTools.xaml.cs

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
@ -18,22 +17,22 @@ using Avalonia.VisualTree;
namespace Avalonia namespace Avalonia
{ {
public static class DevToolsExtensions public static class DevToolsExtensions
{ {
public static void AttachDevTools(this TopLevel control) public static void AttachDevTools(this TopLevel control)
{ {
Avalonia.Diagnostics.DevTools.Attach(control); Diagnostics.DevTools.Attach(control);
} }
} }
} }
namespace Avalonia.Diagnostics namespace Avalonia.Diagnostics
{ {
public class DevTools : UserControl public class DevTools : UserControl
{ {
private static Dictionary<TopLevel, Window> s_open = new Dictionary<TopLevel, Window>(); private static readonly Dictionary<TopLevel, Window> s_open = new Dictionary<TopLevel, Window>();
private static HashSet<IRenderRoot> s_visualTreeRoots = new HashSet<IRenderRoot>(); private static readonly HashSet<IRenderRoot> s_visualTreeRoots = new HashSet<IRenderRoot>();
private IDisposable _keySubscription; private readonly IDisposable _keySubscription;
public DevTools(IControl root) public DevTools(IControl root)
{ {
@ -49,7 +48,6 @@ namespace Avalonia.Diagnostics
// HACK: needed for XAMLIL, will fix that later // HACK: needed for XAMLIL, will fix that later
public DevTools() public DevTools()
{ {
} }
public IControl Root { get; } public IControl Root { get; }
@ -67,9 +65,8 @@ namespace Avalonia.Diagnostics
if (e.Key == Key.F12) if (e.Key == Key.F12)
{ {
var control = (TopLevel)sender; var control = (TopLevel)sender;
var devToolsWindow = default(Window);
if (s_open.TryGetValue(control, out devToolsWindow)) if (s_open.TryGetValue(control, out var devToolsWindow))
{ {
devToolsWindow.Activate(); devToolsWindow.Activate();
} }
@ -82,10 +79,7 @@ namespace Avalonia.Diagnostics
Width = 1024, Width = 1024,
Height = 512, Height = 512,
Content = devTools, Content = devTools,
DataTemplates = DataTemplates = { new ViewLocator<ViewModelBase>() },
{
new ViewLocator<ViewModelBase>(),
},
Title = "Avalonia DevTools" Title = "Avalonia DevTools"
}; };
@ -118,7 +112,6 @@ namespace Avalonia.Diagnostics
if ((e.Modifiers) == modifiers) if ((e.Modifiers) == modifiers)
{ {
var point = (Root.VisualRoot as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default(Point); var point = (Root.VisualRoot as IInputRoot)?.MouseDevice?.GetPosition(Root) ?? default(Point);
var control = Root.GetVisualsAt(point, x => (!(x is AdornerLayer) && x.IsVisible)) var control = Root.GetVisualsAt(point, x => (!(x is AdornerLayer) && x.IsVisible))
.FirstOrDefault(); .FirstOrDefault();

7
src/Avalonia.Diagnostics/Models/EventChainLink.cs

@ -12,9 +12,9 @@ namespace Avalonia.Diagnostics.Models
{ {
Contract.Requires<ArgumentNullException>(handler != null); Contract.Requires<ArgumentNullException>(handler != null);
this.Handler = handler; Handler = handler;
this.Handled = handled; Handled = handled;
this.Route = route; Route = route;
} }
public object Handler { get; } public object Handler { get; }
@ -27,6 +27,7 @@ namespace Avalonia.Diagnostics.Models
{ {
return named.Name + " (" + Handler.GetType().Name + ")"; return named.Name + " (" + Handler.GetType().Name + ")";
} }
return Handler.GetType().Name; return Handler.GetType().Name;
} }
} }

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

@ -20,16 +20,6 @@ namespace Avalonia.Diagnostics.ViewModels
} }
} }
public IEnumerable<string> Classes public IEnumerable<PropertyDetails> Properties { get; }
{
get;
private set;
}
public IEnumerable<PropertyDetails> Properties
{
get;
private set;
}
} }
} }

1
src/Avalonia.Diagnostics/ViewModels/DevToolsViewModel.cs

@ -2,7 +2,6 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Avalonia.Controls; using Avalonia.Controls;

15
src/Avalonia.Diagnostics/ViewModels/EventOwnerTreeNode.cs

@ -13,22 +13,18 @@ namespace Avalonia.Diagnostics.ViewModels
{ {
internal class EventOwnerTreeNode : EventTreeNodeBase internal class EventOwnerTreeNode : EventTreeNodeBase
{ {
private static readonly RoutedEvent[] s_defaultEvents = new RoutedEvent[] private static readonly RoutedEvent[] s_defaultEvents =
{ {
Button.ClickEvent, Button.ClickEvent, InputElement.KeyDownEvent, InputElement.KeyUpEvent, InputElement.TextInputEvent,
InputElement.KeyDownEvent, InputElement.PointerReleasedEvent, InputElement.PointerPressedEvent
InputElement.KeyUpEvent,
InputElement.TextInputEvent,
InputElement.PointerReleasedEvent,
InputElement.PointerPressedEvent,
}; };
public EventOwnerTreeNode(Type type, IEnumerable<RoutedEvent> events, EventsViewModel vm) public EventOwnerTreeNode(Type type, IEnumerable<RoutedEvent> events, EventsViewModel vm)
: base(null, type.Name) : base(null, type.Name)
{ {
this.Children = new AvaloniaList<EventTreeNodeBase>(events.OrderBy(e => e.Name) Children = new AvaloniaList<EventTreeNodeBase>(events.OrderBy(e => e.Name)
.Select(e => new EventTreeNode(this, e, vm) { IsEnabled = s_defaultEvents.Contains(e) })); .Select(e => new EventTreeNode(this, e, vm) { IsEnabled = s_defaultEvents.Contains(e) }));
this.IsExpanded = true; IsExpanded = true;
} }
public override bool? IsEnabled public override bool? IsEnabled
@ -39,6 +35,7 @@ namespace Avalonia.Diagnostics.ViewModels
if (base.IsEnabled != value) if (base.IsEnabled != value)
{ {
base.IsEnabled = value; base.IsEnabled = value;
if (_updateChildren && value != null) if (_updateChildren && value != null)
{ {
foreach (var child in Children) foreach (var child in Children)

9
src/Avalonia.Diagnostics/ViewModels/EventTreeNode.cs

@ -2,7 +2,6 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using Avalonia.Diagnostics.Models; using Avalonia.Diagnostics.Models;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading; using Avalonia.Threading;
@ -12,8 +11,8 @@ namespace Avalonia.Diagnostics.ViewModels
{ {
internal class EventTreeNode : EventTreeNodeBase internal class EventTreeNode : EventTreeNodeBase
{ {
private RoutedEvent _event; private readonly RoutedEvent _event;
private EventsViewModel _parentViewModel; private readonly EventsViewModel _parentViewModel;
private bool _isRegistered; private bool _isRegistered;
private FiredEvent _currentEvent; private FiredEvent _currentEvent;
@ -23,8 +22,8 @@ namespace Avalonia.Diagnostics.ViewModels
Contract.Requires<ArgumentNullException>(@event != null); Contract.Requires<ArgumentNullException>(@event != null);
Contract.Requires<ArgumentNullException>(vm != null); Contract.Requires<ArgumentNullException>(vm != null);
this._event = @event; _event = @event;
this._parentViewModel = vm; _parentViewModel = vm;
} }
public override bool? IsEnabled public override bool? IsEnabled

17
src/Avalonia.Diagnostics/ViewModels/EventTreeNodeBase.cs

@ -12,10 +12,10 @@ namespace Avalonia.Diagnostics.ViewModels
private bool _isExpanded; private bool _isExpanded;
private bool? _isEnabled = false; private bool? _isEnabled = false;
public EventTreeNodeBase(EventTreeNodeBase parent, string text) protected EventTreeNodeBase(EventTreeNodeBase parent, string text)
{ {
this.Parent = parent; Parent = parent;
this.Text = text; Text = text;
} }
public IAvaloniaReadOnlyList<EventTreeNodeBase> Children public IAvaloniaReadOnlyList<EventTreeNodeBase> Children
@ -26,14 +26,14 @@ namespace Avalonia.Diagnostics.ViewModels
public bool IsExpanded public bool IsExpanded
{ {
get { return _isExpanded; } get => _isExpanded;
set { RaiseAndSetIfChanged(ref _isExpanded, value); } set => RaiseAndSetIfChanged(ref _isExpanded, value);
} }
public virtual bool? IsEnabled public virtual bool? IsEnabled
{ {
get { return _isEnabled; } get => _isEnabled;
set { RaiseAndSetIfChanged(ref _isEnabled, value); } set => RaiseAndSetIfChanged(ref _isEnabled, value);
} }
public EventTreeNodeBase Parent public EventTreeNodeBase Parent
@ -44,7 +44,6 @@ namespace Avalonia.Diagnostics.ViewModels
public string Text public string Text
{ {
get; get;
private set;
} }
internal void UpdateChecked() internal void UpdateChecked()
@ -55,7 +54,9 @@ namespace Avalonia.Diagnostics.ViewModels
{ {
if (Children == null) if (Children == null)
return false; return false;
bool? value = false; bool? value = false;
for (int i = 0; i < Children.Count; i++) for (int i = 0; i < Children.Count; i++)
{ {
if (i == 0) if (i == 0)

12
src/Avalonia.Diagnostics/ViewModels/FiredEvent.cs

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Avalonia.Diagnostics.Models; using Avalonia.Diagnostics.Models;
using Avalonia.Interactivity; using Avalonia.Interactivity;
@ -11,7 +10,7 @@ namespace Avalonia.Diagnostics.ViewModels
{ {
internal class FiredEvent : ViewModelBase internal class FiredEvent : ViewModelBase
{ {
private RoutedEventArgs _eventArgs; private readonly RoutedEventArgs _eventArgs;
private EventChainLink _handledBy; private EventChainLink _handledBy;
public FiredEvent(RoutedEventArgs eventArgs, EventChainLink originator) public FiredEvent(RoutedEventArgs eventArgs, EventChainLink originator)
@ -19,8 +18,8 @@ namespace Avalonia.Diagnostics.ViewModels
Contract.Requires<ArgumentNullException>(eventArgs != null); Contract.Requires<ArgumentNullException>(eventArgs != null);
Contract.Requires<ArgumentNullException>(originator != null); Contract.Requires<ArgumentNullException>(originator != null);
this._eventArgs = eventArgs; _eventArgs = eventArgs;
this.Originator = originator; Originator = originator;
AddToChain(originator); AddToChain(originator);
} }
@ -42,8 +41,9 @@ namespace Avalonia.Diagnostics.ViewModels
if (IsHandled) if (IsHandled)
{ {
return $"{Event.Name} on {Originator.HandlerName};" + Environment.NewLine + return $"{Event.Name} on {Originator.HandlerName};" + Environment.NewLine +
$"strategies: {Event.RoutingStrategies}; handled by: {HandledBy.HandlerName}"; $"strategies: {Event.RoutingStrategies}; handled by: {HandledBy.HandlerName}";
} }
return $"{Event.Name} on {Originator.HandlerName}; strategies: {Event.RoutingStrategies}"; return $"{Event.Name} on {Originator.HandlerName}; strategies: {Event.RoutingStrategies}";
} }
} }
@ -52,7 +52,7 @@ namespace Avalonia.Diagnostics.ViewModels
public EventChainLink HandledBy public EventChainLink HandledBy
{ {
get { return _handledBy; } get => _handledBy;
set set
{ {
if (_handledBy != value) if (_handledBy != value)

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

@ -17,8 +17,7 @@ namespace Avalonia.Diagnostics.ViewModels
public static LogicalTreeNode[] Create(object control) public static LogicalTreeNode[] Create(object control)
{ {
var logical = control as ILogical; return control is ILogical logical ? new[] { new LogicalTreeNode(logical, null) } : null;
return logical != null ? new[] { new LogicalTreeNode(logical, null) } : null;
} }
} }
} }

16
src/Avalonia.Diagnostics/ViewModels/PropertyDetails.cs

@ -26,7 +26,9 @@ namespace Avalonia.Diagnostics.ViewModels
Value = diagnostic.Value ?? "(null)"; Value = diagnostic.Value ?? "(null)";
Priority = (diagnostic.Priority != BindingPriority.Unset) ? Priority = (diagnostic.Priority != BindingPriority.Unset) ?
diagnostic.Priority.ToString() : diagnostic.Priority.ToString() :
diagnostic.Property.Inherits ? "Inherited" : "Unset"; diagnostic.Property.Inherits ?
"Inherited" :
"Unset";
Diagnostic = diagnostic.Diagnostic; Diagnostic = diagnostic.Diagnostic;
}); });
} }
@ -37,20 +39,20 @@ namespace Avalonia.Diagnostics.ViewModels
public string Priority public string Priority
{ {
get { return _priority; } get => _priority;
private set { RaiseAndSetIfChanged(ref _priority, value); } private set => RaiseAndSetIfChanged(ref _priority, value);
} }
public string Diagnostic public string Diagnostic
{ {
get { return _diagnostic; } get => _diagnostic;
private set { RaiseAndSetIfChanged(ref _diagnostic, value); } private set => RaiseAndSetIfChanged(ref _diagnostic, value);
} }
public object Value public object Value
{ {
get { return _value; } get => _value;
private set { RaiseAndSetIfChanged(ref _value, value); } private set => RaiseAndSetIfChanged(ref _value, value);
} }
} }
} }

15
src/Avalonia.Diagnostics/ViewModels/TreeNode.cs

@ -27,9 +27,9 @@ namespace Avalonia.Diagnostics.ViewModels
var classesChanged = Observable.FromEventPattern< var classesChanged = Observable.FromEventPattern<
NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventHandler,
NotifyCollectionChangedEventArgs>( NotifyCollectionChangedEventArgs>(
x => styleable.Classes.CollectionChanged += x, x => styleable.Classes.CollectionChanged += x,
x => styleable.Classes.CollectionChanged -= x) x => styleable.Classes.CollectionChanged -= x)
.TakeUntil(((IStyleable)styleable).StyleDetach); .TakeUntil(styleable.StyleDetach);
classesChanged.Select(_ => Unit.Default) classesChanged.Select(_ => Unit.Default)
.StartWith(Unit.Default) .StartWith(Unit.Default)
@ -55,8 +55,8 @@ namespace Avalonia.Diagnostics.ViewModels
public string Classes public string Classes
{ {
get { return _classes; } get => _classes;
private set { RaiseAndSetIfChanged(ref _classes, value); } private set => RaiseAndSetIfChanged(ref _classes, value);
} }
public IVisual Visual public IVisual Visual
@ -66,8 +66,8 @@ namespace Avalonia.Diagnostics.ViewModels
public bool IsExpanded public bool IsExpanded
{ {
get { return _isExpanded; } get => _isExpanded;
set { RaiseAndSetIfChanged(ref _isExpanded, value); } set => RaiseAndSetIfChanged(ref _isExpanded, value);
} }
public TreeNode Parent public TreeNode Parent
@ -78,7 +78,6 @@ namespace Avalonia.Diagnostics.ViewModels
public string Type public string Type
{ {
get; get;
private set;
} }
} }
} }

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

@ -23,7 +23,7 @@ namespace Avalonia.Diagnostics.ViewModels
public TreeNode SelectedNode public TreeNode SelectedNode
{ {
get { return _selected; } get => _selected;
set set
{ {
if (RaiseAndSetIfChanged(ref _selected, value)) if (RaiseAndSetIfChanged(ref _selected, value))
@ -35,8 +35,8 @@ namespace Avalonia.Diagnostics.ViewModels
public ControlDetailsViewModel Details public ControlDetailsViewModel Details
{ {
get { return _details; } get => _details;
private set { RaiseAndSetIfChanged(ref _details, value); } private set => RaiseAndSetIfChanged(ref _details, value);
} }
public TreeNode FindNode(IControl control) public TreeNode FindNode(IControl control)
@ -66,7 +66,7 @@ namespace Avalonia.Diagnostics.ViewModels
{ {
control = control.GetVisualParent<IControl>(); control = control.GetVisualParent<IControl>();
} }
} }
if (node != null) if (node != null)
{ {
@ -90,16 +90,14 @@ namespace Avalonia.Diagnostics.ViewModels
{ {
return node; return node;
} }
else
foreach (var child in node.Children)
{ {
foreach (var child in node.Children) var result = FindNode(child, control);
{
var result = FindNode(child, control);
if (result != null) if (result != null)
{ {
return result; return result;
}
} }
} }

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

@ -29,12 +29,11 @@ namespace Avalonia.Diagnostics.ViewModels
} }
} }
public bool IsInTemplate { get; private set; } public bool IsInTemplate { get; }
public static VisualTreeNode[] Create(object control) public static VisualTreeNode[] Create(object control)
{ {
var visual = control as IVisual; return control is IVisual visual ? new[] { new VisualTreeNode(visual, null) } : null;
return visual != null ? new[] { new VisualTreeNode(visual, null) } : null;
} }
} }
} }

17
src/Avalonia.Diagnostics/Views/ControlDetailsView.cs

@ -14,6 +14,7 @@ namespace Avalonia.Diagnostics.Views
{ {
private static readonly StyledProperty<ControlDetailsViewModel> ViewModelProperty = private static readonly StyledProperty<ControlDetailsViewModel> ViewModelProperty =
AvaloniaProperty.Register<ControlDetailsView, ControlDetailsViewModel>(nameof(ViewModel)); AvaloniaProperty.Register<ControlDetailsView, ControlDetailsViewModel>(nameof(ViewModel));
private SimpleGrid _grid; private SimpleGrid _grid;
public ControlDetailsView() public ControlDetailsView()
@ -25,7 +26,7 @@ namespace Avalonia.Diagnostics.Views
public ControlDetailsViewModel ViewModel public ControlDetailsViewModel ViewModel
{ {
get { return GetValue(ViewModelProperty); } get => GetValue(ViewModelProperty);
private set private set
{ {
SetValue(ViewModelProperty, value); SetValue(ViewModelProperty, value);
@ -37,13 +38,7 @@ namespace Avalonia.Diagnostics.Views
{ {
Func<object, IEnumerable<Control>> pt = PropertyTemplate; Func<object, IEnumerable<Control>> pt = PropertyTemplate;
Content = new ScrollViewer Content = new ScrollViewer { Content = _grid = new SimpleGrid { [GridRepeater.TemplateProperty] = pt } };
{
Content = _grid = new SimpleGrid
{
[GridRepeater.TemplateProperty] = pt,
}
};
} }
private IEnumerable<Control> PropertyTemplate(object i) private IEnumerable<Control> PropertyTemplate(object i)
@ -57,7 +52,7 @@ namespace Avalonia.Diagnostics.Views
Margin = margin, Margin = margin,
Text = property.Name, Text = property.Name,
TextWrapping = TextWrapping.NoWrap, TextWrapping = TextWrapping.NoWrap,
[!ToolTip.TipProperty] = property.GetObservable<string>(nameof(property.Diagnostic)).ToBinding(), [!ToolTip.TipProperty] = property.GetObservable<string>(nameof(property.Diagnostic)).ToBinding()
}; };
yield return new TextBlock yield return new TextBlock
@ -66,14 +61,14 @@ namespace Avalonia.Diagnostics.Views
TextWrapping = TextWrapping.NoWrap, TextWrapping = TextWrapping.NoWrap,
[!TextBlock.TextProperty] = property.GetObservable<object>(nameof(property.Value)) [!TextBlock.TextProperty] = property.GetObservable<object>(nameof(property.Value))
.Select(v => v?.ToString()) .Select(v => v?.ToString())
.ToBinding(), .ToBinding()
}; };
yield return new TextBlock yield return new TextBlock
{ {
Margin = margin, Margin = margin,
TextWrapping = TextWrapping.NoWrap, TextWrapping = TextWrapping.NoWrap,
[!TextBlock.TextProperty] = property.GetObservable<string>((nameof(property.Priority))).ToBinding(), [!TextBlock.TextProperty] = property.GetObservable<string>((nameof(property.Priority))).ToBinding()
}; };
} }
} }

100
src/Avalonia.Diagnostics/Views/EventsView.xaml

@ -2,53 +2,57 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Avalonia.Diagnostics.ViewModels" xmlns:vm="clr-namespace:Avalonia.Diagnostics.ViewModels"
x:Class="Avalonia.Diagnostics.Views.EventsView"> x:Class="Avalonia.Diagnostics.Views.EventsView">
<UserControl.Resources> <UserControl.Resources>
<vm:BoolToBrushConverter x:Key="boolToBrush" /> <vm:BoolToBrushConverter x:Key="boolToBrush" />
</UserControl.Resources> </UserControl.Resources>
<Grid ColumnDefinitions="*,4,3*"> <Grid ColumnDefinitions="*,4,3*">
<TreeView Name="tree" Items="{Binding Nodes}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}" Grid.RowSpan="2"> <TreeView Name="tree" Items="{Binding Nodes}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}"
<TreeView.DataTemplates> Grid.RowSpan="2">
<TreeDataTemplate DataType="vm:EventTreeNodeBase" <TreeView.DataTemplates>
ItemsSource="{Binding Children}"> <TreeDataTemplate DataType="vm:EventTreeNodeBase"
<CheckBox Content="{Binding Text}" IsChecked="{Binding IsEnabled, Mode=TwoWay}" /> ItemsSource="{Binding Children}">
</TreeDataTemplate> <CheckBox Content="{Binding Text}" IsChecked="{Binding IsEnabled, Mode=TwoWay}" />
</TreeView.DataTemplates> </TreeDataTemplate>
<TreeView.Styles> </TreeView.DataTemplates>
<Style Selector="TreeViewItem"> <TreeView.Styles>
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/> <Style Selector="TreeViewItem">
</Style> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</TreeView.Styles> </Style>
</TreeView> </TreeView.Styles>
</TreeView>
<GridSplitter Width="4" Grid.Column="1" />
<Grid RowDefinitions="*,4,2*,Auto" Grid.Column="2"> <GridSplitter Width="4" Grid.Column="1" />
<ListBox Name="eventsList" Items="{Binding RecordedEvents}" SelectedItem="{Binding SelectedEvent, Mode=TwoWay}"> <Grid RowDefinitions="*,4,2*,Auto" Grid.Column="2">
<ListBox.ItemTemplate> <ListBox Name="eventsList" Items="{Binding RecordedEvents}"
<DataTemplate> SelectedItem="{Binding SelectedEvent, Mode=TwoWay}">
<TextBlock Background="{Binding IsHandled, Converter={StaticResource boolToBrush}}" Text="{Binding DisplayText}" /> <ListBox.ItemTemplate>
</DataTemplate> <DataTemplate>
</ListBox.ItemTemplate> <TextBlock Background="{Binding IsHandled, Converter={StaticResource boolToBrush}}"
</ListBox> Text="{Binding DisplayText}" />
<GridSplitter Height="4" Grid.Row="1" /> </DataTemplate>
<DockPanel Grid.Row="2" LastChildFill="True"> </ListBox.ItemTemplate>
<TextBlock DockPanel.Dock="Top" FontSize="16" Text="Event chain:" /> </ListBox>
<ListBox Items="{Binding SelectedEvent.EventChain}"> <GridSplitter Height="4" Grid.Row="1" />
<ListBox.ItemTemplate> <DockPanel Grid.Row="2" LastChildFill="True">
<DataTemplate> <TextBlock DockPanel.Dock="Top" FontSize="16" Text="Event chain:" />
<StackPanel Orientation="Horizontal" Background="{Binding Handled, Converter={StaticResource boolToBrush}}"> <ListBox Items="{Binding SelectedEvent.EventChain}">
<TextBlock Text="{Binding Route}" /> <ListBox.ItemTemplate>
<TextBlock Text=": " /> <DataTemplate>
<TextBlock Text="{Binding HandlerName}" /> <StackPanel Orientation="Horizontal"
<TextBlock Text=" handled: " /> Background="{Binding Handled, Converter={StaticResource boolToBrush}}">
<TextBlock Text="{Binding Handled}" /> <TextBlock Text="{Binding Route}" />
</StackPanel> <TextBlock Text=": " />
</DataTemplate> <TextBlock Text="{Binding HandlerName}" />
</ListBox.ItemTemplate> <TextBlock Text=" handled: " />
</ListBox> <TextBlock Text="{Binding Handled}" />
</DockPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3"> </DataTemplate>
<Button Content="Clear" Margin="3" Command="{Binding Clear}" /> </ListBox.ItemTemplate>
</StackPanel> </ListBox>
</Grid> </DockPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<Button Content="Clear" Margin="3" Command="{Binding Clear}" />
</StackPanel>
</Grid> </Grid>
</Grid>
</UserControl> </UserControl>

8
src/Avalonia.Diagnostics/Views/EventsView.xaml.cs

@ -2,7 +2,6 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Linq; using System.Linq;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Diagnostics.ViewModels; using Avalonia.Diagnostics.ViewModels;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
@ -11,15 +10,16 @@ namespace Avalonia.Diagnostics.Views
{ {
public class EventsView : UserControl public class EventsView : UserControl
{ {
private ListBox _events; private readonly ListBox _events;
public EventsView() public EventsView()
{ {
this.InitializeComponent(); InitializeComponent();
_events = this.FindControl<ListBox>("events"); _events = this.FindControl<ListBox>("events");
} }
private void RecordedEvents_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) private void RecordedEvents_CollectionChanged(object sender,
System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{ {
_events.ScrollIntoView(_events.Items.OfType<FiredEvent>().LastOrDefault()); _events.ScrollIntoView(_events.Items.OfType<FiredEvent>().LastOrDefault());
} }

3
src/Avalonia.Diagnostics/Views/GridRepeater.cs

@ -14,7 +14,8 @@ namespace Avalonia.Diagnostics.Views
AvaloniaProperty.RegisterAttached<SimpleGrid, IEnumerable>("Items", typeof(GridRepeater)); AvaloniaProperty.RegisterAttached<SimpleGrid, IEnumerable>("Items", typeof(GridRepeater));
public static readonly AttachedProperty<Func<object, IEnumerable<Control>>> TemplateProperty = public static readonly AttachedProperty<Func<object, IEnumerable<Control>>> TemplateProperty =
AvaloniaProperty.RegisterAttached<SimpleGrid, Func<object, IEnumerable<Control>>>("Template", typeof(GridRepeater)); AvaloniaProperty.RegisterAttached<SimpleGrid, Func<object, IEnumerable<Control>>>("Template",
typeof(GridRepeater));
static GridRepeater() static GridRepeater()
{ {

10
src/Avalonia.Diagnostics/Views/PropertyChangedExtensions.cs

@ -23,11 +23,11 @@ namespace Avalonia.Diagnostics.Views
} }
return Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>( return Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
e => source.PropertyChanged += e, e => source.PropertyChanged += e,
e => source.PropertyChanged -= e) e => source.PropertyChanged -= e)
.Where(e => e.EventArgs.PropertyName == propertyName) .Where(e => e.EventArgs.PropertyName == propertyName)
.Select(_ => (T)property.GetValue(source)) .Select(_ => (T)property.GetValue(source))
.StartWith((T)property.GetValue(source)); .StartWith((T)property.GetValue(source));
} }
} }
} }

8
src/Avalonia.Diagnostics/Views/SimpleGrid.cs

@ -15,8 +15,8 @@ namespace Avalonia.Diagnostics.Views
/// </remarks> /// </remarks>
public class SimpleGrid : Panel public class SimpleGrid : Panel
{ {
private List<double> _columnWidths = new List<double>(); private readonly List<double> _columnWidths = new List<double>();
private List<double> _rowHeights = new List<double>(); private readonly List<double> _rowHeights = new List<double>();
private double _totalWidth; private double _totalWidth;
private double _totalHeight; private double _totalHeight;
@ -31,7 +31,7 @@ namespace Avalonia.Diagnostics.Views
/// </summary> /// </summary>
public static readonly AttachedProperty<int> RowProperty = public static readonly AttachedProperty<int> RowProperty =
AvaloniaProperty.RegisterAttached<SimpleGrid, Control, int>("Row"); AvaloniaProperty.RegisterAttached<SimpleGrid, Control, int>("Row");
/// <summary> /// <summary>
/// Gets the value of the Column attached property for a control. /// Gets the value of the Column attached property for a control.
/// </summary> /// </summary>
@ -62,7 +62,7 @@ namespace Avalonia.Diagnostics.Views
control.SetValue(ColumnProperty, value); control.SetValue(ColumnProperty, value);
} }
/// <summary> /// <summary>
/// Sets the value of the Row attached property for a control. /// Sets the value of the Row attached property for a control.
/// </summary> /// </summary>

12
src/Avalonia.Diagnostics/Views/TreePageView.xaml

@ -2,25 +2,25 @@
xmlns:vm="clr-namespace:Avalonia.Diagnostics.ViewModels" xmlns:vm="clr-namespace:Avalonia.Diagnostics.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Avalonia.Diagnostics.Views.TreePageView"> x:Class="Avalonia.Diagnostics.Views.TreePageView">
<Grid ColumnDefinitions="*,4,3*"> <Grid ColumnDefinitions="*,4,3*">
<TreeView Name="tree" Items="{Binding Nodes}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}"> <TreeView Name="tree" Items="{Binding Nodes}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
<TreeView.DataTemplates> <TreeView.DataTemplates>
<TreeDataTemplate DataType="vm:TreeNode" <TreeDataTemplate DataType="vm:TreeNode"
ItemsSource="{Binding Children}"> ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal" Spacing="8"> <StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="{Binding Type}"/> <TextBlock Text="{Binding Type}" />
<TextBlock Text="{Binding Classes}"/> <TextBlock Text="{Binding Classes}" />
</StackPanel> </StackPanel>
</TreeDataTemplate> </TreeDataTemplate>
</TreeView.DataTemplates> </TreeView.DataTemplates>
<TreeView.Styles> <TreeView.Styles>
<Style Selector="TreeViewItem"> <Style Selector="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/> <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</Style> </Style>
</TreeView.Styles> </TreeView.Styles>
</TreeView> </TreeView>
<GridSplitter Width="4" Grid.Column="1"/> <GridSplitter Width="4" Grid.Column="1" />
<ContentControl Content="{Binding Details}" Grid.Column="2"/> <ContentControl Content="{Binding Details}" Grid.Column="2" />
</Grid> </Grid>
</UserControl> </UserControl>

4
src/Avalonia.Diagnostics/Views/TreePageView.xaml.cs

@ -19,7 +19,7 @@ namespace Avalonia.Diagnostics.Views
public TreePageView() public TreePageView()
{ {
this.InitializeComponent(); InitializeComponent();
_tree.ItemContainerGenerator.Index.Materialized += TreeViewItemMaterialized; _tree.ItemContainerGenerator.Index.Materialized += TreeViewItemMaterialized;
} }
@ -39,7 +39,7 @@ namespace Avalonia.Diagnostics.Views
_adorner = new Rectangle _adorner = new Rectangle
{ {
Fill = new SolidColorBrush(0x80a0c5e8), Fill = new SolidColorBrush(0x80a0c5e8),
[AdornerLayer.AdornedElementProperty] = node.Visual, [AdornerLayer.AdornedElementProperty] = node.Visual
}; };
layer.Children.Add(_adorner); layer.Children.Add(_adorner);

Loading…
Cancel
Save