Skip to content

Commit

Permalink
Merge pull request #12036 from yll690/feature/devtools-event-time
Browse files Browse the repository at this point in the history
Add event trigger time in DevTools. #11338
  • Loading branch information
maxkatz6 authored Jul 5, 2023
2 parents c444b4b + b513416 commit 605c880
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ private void HandleEvent(object? sender, RoutedEventArgs e)
var s = sender!;
var handled = e.Handled;
var route = e.Route;
var triggerTime = DateTime.Now;

void handler()
{
if (_currentEvent == null || !_currentEvent.IsPartOfSameEventChain(e))
{
_currentEvent = new FiredEvent(e, new EventChainLink(s, handled, route));
_currentEvent = new FiredEvent(e, new EventChainLink(s, handled, route), triggerTime);

_parentViewModel.RecordedEvents.Add(_currentEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ internal class FiredEvent : ViewModelBase
private readonly RoutedEventArgs _eventArgs;
private EventChainLink? _handledBy;

public FiredEvent(RoutedEventArgs eventArgs, EventChainLink originator)
public FiredEvent(RoutedEventArgs eventArgs, EventChainLink originator, DateTime triggerTime)
{
_eventArgs = eventArgs ?? throw new ArgumentNullException(nameof(eventArgs));
Originator = originator ?? throw new ArgumentNullException(nameof(originator));
AddToChain(originator);
TriggerTime = triggerTime;
}

public bool IsPartOfSameEventChain(RoutedEventArgs e)
{
return e == _eventArgs;
}

public DateTime TriggerTime { get; }

public RoutedEvent Event => _eventArgs.RoutedEvent!;

public bool IsHandled => HandledBy?.Handled == true;
Expand Down
10 changes: 6 additions & 4 deletions src/Avalonia.Diagnostics/Diagnostics/Views/EventsPageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,23 @@
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem Classes.handled="{Binding IsHandled}">
<Grid ColumnDefinitions="Auto,Auto,*,Auto">
<Grid ColumnDefinitions="Auto,Auto,Auto,*,Auto">

<StackPanel Grid.Column="0" Spacing="2" Orientation="Horizontal" >
<TextBlock Grid.Column="0" Text="{Binding TriggerTime, StringFormat={}{0:HH:mm:ss.fff}}"/>

<StackPanel Margin="10,0,0,0" Grid.Column="1" Spacing="2" Orientation="Horizontal" >
<TextBlock Tag="{Binding Event}" DoubleTapped="NavigateTo" Text="{Binding Event.Name}" FontWeight="Bold" Classes="nav" />
<TextBlock Text="on" />
<TextBlock Tag="{Binding Originator}" DoubleTapped="NavigateTo" Text="{Binding Originator.HandlerName}" Classes="nav" />
</StackPanel>

<StackPanel Margin="2,0,0,0" Grid.Column="1" Spacing="2" Orientation="Horizontal" IsVisible="{Binding IsHandled}" >
<StackPanel Margin="2,0,0,0" Grid.Column="2" Spacing="2" Orientation="Horizontal" IsVisible="{Binding IsHandled}" >
<TextBlock Text="::" />
<TextBlock Text="Handled by" />
<TextBlock Tag="{Binding HandledBy}" DoubleTapped="NavigateTo" Text="{Binding HandledBy.HandlerName}" Classes="nav" />
</StackPanel>

<StackPanel Grid.Column="3" Orientation="Horizontal" HorizontalAlignment="Right">
<StackPanel Grid.Column="4" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Text="Routing (" />
<TextBlock Text="{Binding Event.RoutingStrategies}"/>
<TextBlock Text=")"/>
Expand Down

0 comments on commit 605c880

Please sign in to comment.