forked from WalletWasabi/WalletWasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Downgrade to Avalonia 11.0.999-cibuild0044755-beta (WalletWasabi#13342)
- Loading branch information
Showing
32 changed files
with
5,215 additions
and
869 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Data; | ||
using Avalonia.Input; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class BindPointerOverBehavior : DisposingBehavior<Control> | ||
{ | ||
public static readonly StyledProperty<bool> IsPointerOverProperty = | ||
AvaloniaProperty.Register<BindPointerOverBehavior, bool>(nameof(IsPointerOver), defaultBindingMode: BindingMode.TwoWay); | ||
|
||
public bool IsPointerOver | ||
{ | ||
get => GetValue(IsPointerOverProperty); | ||
set => SetValue(IsPointerOverProperty, value); | ||
} | ||
|
||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
if (AssociatedObject is null) | ||
{ | ||
return; | ||
} | ||
|
||
Observable | ||
.FromEventPattern<AvaloniaPropertyChangedEventArgs>(AssociatedObject, nameof(PropertyChanged)) | ||
.Select(x => x.EventArgs) | ||
.Subscribe(e => | ||
{ | ||
if (e.Property == InputElement.IsPointerOverProperty) | ||
{ | ||
IsPointerOver = e.NewValue is true; | ||
} | ||
}) | ||
.DisposeWith(disposables); | ||
|
||
disposables.Add(Disposable.Create(() => IsPointerOver = false)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Reactive.Disposables; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Data; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
internal class BoundsObserverBehavior : DisposingBehavior<Control> | ||
{ | ||
public static readonly StyledProperty<Rect> BoundsProperty = | ||
AvaloniaProperty.Register<BoundsObserverBehavior, Rect>(nameof(Bounds), defaultBindingMode: BindingMode.OneWay); | ||
|
||
public static readonly StyledProperty<double> WidthProperty = | ||
AvaloniaProperty.Register<BoundsObserverBehavior, double>(nameof(Width), defaultBindingMode: BindingMode.TwoWay); | ||
|
||
public static readonly StyledProperty<double> HeightProperty = | ||
AvaloniaProperty.Register<BoundsObserverBehavior, double>(nameof(Height), defaultBindingMode: BindingMode.TwoWay); | ||
|
||
public Rect Bounds | ||
{ | ||
get => GetValue(BoundsProperty); | ||
set => SetValue(BoundsProperty, value); | ||
} | ||
|
||
public double Width | ||
{ | ||
get => GetValue(WidthProperty); | ||
set => SetValue(WidthProperty, value); | ||
} | ||
|
||
public double Height | ||
{ | ||
get => GetValue(HeightProperty); | ||
set => SetValue(HeightProperty, value); | ||
} | ||
|
||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
if (AssociatedObject is not null) | ||
{ | ||
disposables.Add(this.GetObservable(BoundsProperty) | ||
.Subscribe(bounds => | ||
{ | ||
Width = bounds.Width; | ||
Height = bounds.Height; | ||
})); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
WalletWasabi.Fluent/Behaviors/ButtonExecuteCommandOnKeyDownBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Reactive.Disposables; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Avalonia.Interactivity; | ||
using Avalonia.VisualTree; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class ButtonExecuteCommandOnKeyDownBehavior : AttachedToVisualTreeBehavior<Button> | ||
{ | ||
public static readonly StyledProperty<Key?> KeyProperty = | ||
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, Key?>(nameof(Key)); | ||
|
||
public static readonly StyledProperty<bool> IsEnabledProperty = | ||
AvaloniaProperty.Register<ButtonExecuteCommandOnKeyDownBehavior, bool>(nameof(IsEnabled)); | ||
|
||
public Key? Key | ||
{ | ||
get => GetValue(KeyProperty); | ||
set => SetValue(KeyProperty, value); | ||
} | ||
|
||
public bool IsEnabled | ||
{ | ||
get => GetValue(IsEnabledProperty); | ||
set => SetValue(IsEnabledProperty, value); | ||
} | ||
|
||
protected override void OnAttachedToVisualTree(CompositeDisposable disposable) | ||
{ | ||
var button = AssociatedObject; | ||
if (button is null) | ||
{ | ||
return; | ||
} | ||
|
||
if (button.GetVisualRoot() is InputElement inputRoot) | ||
{ | ||
inputRoot | ||
.AddDisposableHandler(InputElement.KeyDownEvent, RootDefaultKeyDown) | ||
.DisposeWith(disposable); | ||
} | ||
} | ||
|
||
private void RootDefaultKeyDown(object? sender, KeyEventArgs e) | ||
{ | ||
var button = AssociatedObject; | ||
if (button is null) | ||
{ | ||
return; | ||
} | ||
|
||
if (Key is { } && e.Key == Key && button.IsVisible && button.IsEnabled && IsEnabled) | ||
{ | ||
if (!e.Handled && button.Command?.CanExecute(button.CommandParameter) == true) | ||
{ | ||
button.Command.Execute(button.CommandParameter); | ||
e.Handled = true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Reactive.Disposables; | ||
using Avalonia.Xaml.Interactivity; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public abstract class DisposingTrigger : Trigger | ||
{ | ||
private readonly CompositeDisposable _disposables = new(); | ||
|
||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
|
||
OnAttached(_disposables); | ||
} | ||
|
||
protected abstract void OnAttached(CompositeDisposable disposables); | ||
|
||
protected override void OnDetaching() | ||
{ | ||
base.OnDetaching(); | ||
|
||
_disposables.Dispose(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnActivatedBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using System.Windows.Input; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class ExecuteCommandOnActivatedBehavior : DisposingBehavior<Control> | ||
{ | ||
public static readonly StyledProperty<ICommand?> CommandProperty = | ||
AvaloniaProperty.Register<ExecuteCommandOnActivatedBehavior, ICommand?>(nameof(Command)); | ||
|
||
public ICommand? Command | ||
{ | ||
get => GetValue(CommandProperty); | ||
set => SetValue(CommandProperty, value); | ||
} | ||
|
||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) | ||
{ | ||
var mainWindow = lifetime.MainWindow; | ||
|
||
Observable | ||
.FromEventPattern(mainWindow, nameof(mainWindow.Activated)) | ||
.Subscribe(_ => | ||
{ | ||
if (Command is { } cmd && cmd.CanExecute(default)) | ||
{ | ||
cmd.Execute(default); | ||
} | ||
}) | ||
.DisposeWith(disposables); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
WalletWasabi.Fluent/Behaviors/ExecuteCommandOnDoubleTappedBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Reactive.Disposables; | ||
using System.Windows.Input; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class ExecuteCommandOnDoubleTappedBehavior : DisposingBehavior<Control> | ||
{ | ||
public static readonly StyledProperty<ICommand?> CommandProperty = | ||
AvaloniaProperty.Register<ExecuteCommandOnDoubleTappedBehavior, ICommand?>(nameof(Command)); | ||
|
||
public ICommand? Command | ||
{ | ||
get => GetValue(CommandProperty); | ||
set => SetValue(CommandProperty, value); | ||
} | ||
|
||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
Gestures.DoubleTappedEvent.AddClassHandler<InputElement>( | ||
(x, _) => | ||
{ | ||
if (Equals(x, AssociatedObject)) | ||
{ | ||
if (Command is { } cmd && cmd.CanExecute(default)) | ||
{ | ||
cmd.Execute(default); | ||
} | ||
} | ||
}, | ||
RoutingStrategies.Tunnel | RoutingStrategies.Bubble) | ||
.DisposeWith(disposables); | ||
} | ||
} |
Oops, something went wrong.