|
@@ -27,8 +27,7 @@ namespace Avalonia.Interactivity
|
|
|
/// <param name="handler">The handler.</param>
|
|
/// <param name="handler">The handler.</param>
|
|
|
/// <param name="routes">The routing strategies to listen to.</param>
|
|
/// <param name="routes">The routing strategies to listen to.</param>
|
|
|
/// <param name="handledEventsToo">Whether handled events should also be listened for.</param>
|
|
/// <param name="handledEventsToo">Whether handled events should also be listened for.</param>
|
|
|
- /// <returns>A disposable that terminates the event subscription.</returns>
|
|
|
|
|
- public IDisposable AddHandler(
|
|
|
|
|
|
|
+ public void AddHandler(
|
|
|
RoutedEvent routedEvent,
|
|
RoutedEvent routedEvent,
|
|
|
Delegate handler,
|
|
Delegate handler,
|
|
|
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
|
|
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
|
|
@@ -38,7 +37,8 @@ namespace Avalonia.Interactivity
|
|
|
handler = handler ?? throw new ArgumentNullException(nameof(handler));
|
|
handler = handler ?? throw new ArgumentNullException(nameof(handler));
|
|
|
|
|
|
|
|
var subscription = new EventSubscription(handler, routes, handledEventsToo);
|
|
var subscription = new EventSubscription(handler, routes, handledEventsToo);
|
|
|
- return AddEventSubscription(routedEvent, subscription);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ AddEventSubscription(routedEvent, subscription);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -49,8 +49,7 @@ namespace Avalonia.Interactivity
|
|
|
/// <param name="handler">The handler.</param>
|
|
/// <param name="handler">The handler.</param>
|
|
|
/// <param name="routes">The routing strategies to listen to.</param>
|
|
/// <param name="routes">The routing strategies to listen to.</param>
|
|
|
/// <param name="handledEventsToo">Whether handled events should also be listened for.</param>
|
|
/// <param name="handledEventsToo">Whether handled events should also be listened for.</param>
|
|
|
- /// <returns>A disposable that terminates the event subscription.</returns>
|
|
|
|
|
- public IDisposable AddHandler<TEventArgs>(
|
|
|
|
|
|
|
+ public void AddHandler<TEventArgs>(
|
|
|
RoutedEvent<TEventArgs> routedEvent,
|
|
RoutedEvent<TEventArgs> routedEvent,
|
|
|
EventHandler<TEventArgs> handler,
|
|
EventHandler<TEventArgs> handler,
|
|
|
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
|
|
RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble,
|
|
@@ -69,7 +68,7 @@ namespace Avalonia.Interactivity
|
|
|
|
|
|
|
|
var subscription = new EventSubscription(handler, routes, handledEventsToo, (baseHandler, sender, args) => InvokeAdapter(baseHandler, sender, args));
|
|
var subscription = new EventSubscription(handler, routes, handledEventsToo, (baseHandler, sender, args) => InvokeAdapter(baseHandler, sender, args));
|
|
|
|
|
|
|
|
- return AddEventSubscription(routedEvent, subscription);
|
|
|
|
|
|
|
+ AddEventSubscription(routedEvent, subscription);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -188,7 +187,7 @@ namespace Avalonia.Interactivity
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private IDisposable AddEventSubscription(RoutedEvent routedEvent, EventSubscription subscription)
|
|
|
|
|
|
|
+ private void AddEventSubscription(RoutedEvent routedEvent, EventSubscription subscription)
|
|
|
{
|
|
{
|
|
|
_eventHandlers ??= new Dictionary<RoutedEvent, List<EventSubscription>>();
|
|
_eventHandlers ??= new Dictionary<RoutedEvent, List<EventSubscription>>();
|
|
|
|
|
|
|
@@ -199,8 +198,6 @@ namespace Avalonia.Interactivity
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
subscriptions.Add(subscription);
|
|
subscriptions.Add(subscription);
|
|
|
-
|
|
|
|
|
- return new UnsubscribeDisposable(subscriptions, subscription);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private readonly struct EventSubscription
|
|
private readonly struct EventSubscription
|
|
@@ -225,22 +222,5 @@ namespace Avalonia.Interactivity
|
|
|
|
|
|
|
|
public bool HandledEventsToo { get; }
|
|
public bool HandledEventsToo { get; }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private sealed class UnsubscribeDisposable : IDisposable
|
|
|
|
|
- {
|
|
|
|
|
- private readonly List<EventSubscription> _subscriptions;
|
|
|
|
|
- private readonly EventSubscription _subscription;
|
|
|
|
|
-
|
|
|
|
|
- public UnsubscribeDisposable(List<EventSubscription> subscriptions, EventSubscription subscription)
|
|
|
|
|
- {
|
|
|
|
|
- _subscriptions = subscriptions;
|
|
|
|
|
- _subscription = subscription;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void Dispose()
|
|
|
|
|
- {
|
|
|
|
|
- _subscriptions.Remove(_subscription);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|