Skip to content

Commit

Permalink
Add SourceControl property
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Sep 9, 2024
1 parent 697cbe0 commit 4b6976d
Show file tree
Hide file tree
Showing 28 changed files with 70 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;

namespace Avalonia.Xaml.Interactions.Custom;
Expand All @@ -18,7 +19,7 @@ protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{
var mainWindow = lifetime.MainWindow;
var mainWindow = SourceControl as Window ?? lifetime.MainWindow;

if (mainWindow is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnDoubleTappedBehavior : ExecuteCommandRoutedEventBeh
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.DoubleTappedEvent,
OnDoubleTapped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// </summary>
public class ExecuteCommandOnGotFocusBehavior : ExecuteCommandRoutedEventBehaviorBase
{
static ExecuteCommandOnGotFocusBehavior()
{
EventRoutingStrategyProperty.OverrideMetadata<ExecuteCommandOnGotFocusBehavior>(
new StyledPropertyMetadata<RoutingStrategies>(
defaultValue: RoutingStrategies.Tunnel | RoutingStrategies.Bubble));
}

/// <summary>
///
/// </summary>
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.GotFocusEvent,
OnGotFocus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnHoldingBehavior : ExecuteCommandRoutedEventBehavior
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.HoldingEvent,
OnHolding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnKeyDownBehavior : ExecuteCommandOnKeyBehaviorBase
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.KeyDownEvent,
OnKeyDown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnKeyUpBehavior : ExecuteCommandOnKeyBehaviorBase
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.KeyUpEvent,
OnKeyUp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ namespace Avalonia.Xaml.Interactions.Custom;
/// </summary>
public class ExecuteCommandOnLostFocusBehavior : ExecuteCommandRoutedEventBehaviorBase
{
static ExecuteCommandOnLostFocusBehavior()
{
EventRoutingStrategyProperty.OverrideMetadata<ExecuteCommandOnLostFocusBehavior>(
new StyledPropertyMetadata<RoutingStrategies>(
defaultValue: RoutingStrategies.Tunnel | RoutingStrategies.Bubble));
}

/// <summary>
///
/// </summary>
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.LostFocusEvent,
OnLostFocus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPinchBehavior : ExecuteCommandRoutedEventBehaviorBa
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PinchEvent,
OnPinch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPinchEndedBehavior : ExecuteCommandRoutedEventBehav
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PinchEndedEvent,
OnPinchEnded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerCaptureLostBehavior : ExecuteCommandRoutedEv
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerCaptureLostEvent,
OnPointerCaptureLost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerEnteredBehavior : ExecuteCommandRoutedEventB
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerEnteredEvent,
OnPointerEntered,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerExitedBehavior : ExecuteCommandRoutedEventBe
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerExitedEvent,
OnPointerExited,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerMovedBehavior : ExecuteCommandRoutedEventBeh
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerMovedEvent,
OnPointerMoved,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerPressedBehavior : ExecuteCommandRoutedEventB
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerPressedEvent,
OnPointerPressed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerReleasedBehavior : ExecuteCommandRoutedEvent
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerReleasedEvent,
OnPointerReleased,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerTouchPadGestureMagnifyBehavior : ExecuteComm
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PointerTouchPadGestureMagnifyEvent,
OnPointerTouchPadGestureMagnify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerTouchPadGestureRotateBehavior : ExecuteComma
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PointerTouchPadGestureRotateEvent,
OnPointerTouchPadGestureRotate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerTouchPadGestureSwipeBehavior : ExecuteComman
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PointerTouchPadGestureSwipeEvent,
OnPointerTouchPadGestureSwipe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPointerWheelChangedBehavior : ExecuteCommandRoutedE
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.PointerWheelChangedEvent,
OnPointerWheelChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPullGestureBehavior : ExecuteCommandRoutedEventBeha
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PullGestureEvent,
OnPullGesture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnPullGestureEndedBehavior : ExecuteCommandRoutedEven
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.PullGestureEndedEvent,
OnPullGestureEnded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnRightTappedBehavior : ExecuteCommandRoutedEventBeha
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.RightTappedEvent,
OnRightTapped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnScrollGestureBehavior : ExecuteCommandRoutedEventBe
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.ScrollGestureEvent,
OnScrollGesture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnScrollGestureEndedBehavior : ExecuteCommandRoutedEv
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.ScrollGestureEndedEvent,
OnScrollGestureEnded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnScrollGestureInertiaStartingBehavior : ExecuteComma
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.ScrollGestureInertiaStartingEvent,
OnScrollGestureInertiaStarting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnTappedBehavior : ExecuteCommandRoutedEventBehaviorB
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
Gestures.TappedEvent,
OnTapped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnTextInputBehavior : ExecuteCommandRoutedEventBehavi
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.TextInputEvent,
OnTextInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class ExecuteCommandOnTextInputMethodClientRequestedBehavior : ExecuteCom
/// <param name="disposable"></param>
protected override void OnAttachedToVisualTree(CompositeDisposable disposable)
{
var dispose = AssociatedObject?
var control = SourceControl ?? AssociatedObject;
var dispose = control?
.AddDisposableHandler(
InputElement.TextInputMethodClientRequestedEvent,
OnTextInputMethodClientRequested,
Expand Down

0 comments on commit 4b6976d

Please sign in to comment.