Skip to content

Commit

Permalink
Merge pull request #6702 from YohDeadfall/fix-dev-tools-events
Browse files Browse the repository at this point in the history
Fixed handled event misses in dev tools
  • Loading branch information
Takoooooo authored and danwalmsley committed Oct 26, 2021
1 parent 3bc719f commit df77f18
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public string HandlerName
}
}

public bool Handled { get; }
public bool Handled { get; set; }

public RoutingStrategies Route { get; }
}
Expand Down
26 changes: 26 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/ViewModels/EventTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private void UpdateTracker()

// FIXME: This leaks event handlers.
Event.AddClassHandler(typeof(object), HandleEvent, allRoutes, handledEventsToo: true);
Event.RouteFinished.Subscribe(HandleRouteFinished);

_isRegistered = true;
}
}
Expand Down Expand Up @@ -92,6 +94,30 @@ void handler()
else
handler();
}

private void HandleRouteFinished(RoutedEventArgs e)
{
if (!_isRegistered || IsEnabled == false)
return;
if (e.Source is IVisual v && BelongsToDevTool(v))
return;

var s = e.Source;
var handled = e.Handled;
var route = e.Route;

void handler()
{
if (_currentEvent != null && handled)
{
var linkIndex = _currentEvent.EventChain.Count - 1;
var link = _currentEvent.EventChain[linkIndex];

link.Handled = true;
_currentEvent.HandledBy = link;
}
}
}

private static bool BelongsToDevTool(IVisual v)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Avalonia.Diagnostics/Diagnostics/ViewModels/FiredEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ public void AddToChain(EventChainLink link)
{
if (EventChain.Count > 0)
{
var prevLink = EventChain[EventChain.Count-1];

var prevLink = EventChain[EventChain.Count - 1];
if (prevLink.Route != link.Route)
{
link.BeginsNewRoute = true;
}
}

EventChain.Add(link);

if (HandledBy == null && link.Handled)
HandledBy = link;
}
Expand Down

0 comments on commit df77f18

Please sign in to comment.