Skip to content

Commit

Permalink
Edit the previously filled words by clicking on them
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed May 7, 2024
1 parent 27f2770 commit 5257a80
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,32 @@ public class ExecuteCommandOnDoubleTappedBehavior : DisposingBehavior<Control>
public static readonly StyledProperty<ICommand?> CommandProperty =
AvaloniaProperty.Register<ExecuteCommandOnDoubleTappedBehavior, ICommand?>(nameof(Command));

public static readonly StyledProperty<object?> CommandParameterProperty =
AvaloniaProperty.Register<ExecuteCommandOnDoubleTappedBehavior, object?>(nameof(CommandParameter));

public ICommand? Command
{
get => GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

public object? CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}

protected override void OnAttached(CompositeDisposable disposables)
{
Gestures.DoubleTappedEvent.AddClassHandler<InputElement>(
(x, _) =>
{
if (Equals(x, AssociatedObject))
{
if (Command is { } cmd && cmd.CanExecute(default))
var parameter = CommandParameter;
if (Command is { } cmd && cmd.CanExecute(parameter))
{
cmd.Execute(default);
cmd.Execute(parameter);
}
}
},
Expand Down
48 changes: 48 additions & 0 deletions WalletWasabi.Fluent/Behaviors/ExecuteCommandOnTappedBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 ExecuteCommandOnTappedBehavior : DisposingBehavior<Control>
{
public static readonly StyledProperty<ICommand?> CommandProperty =
AvaloniaProperty.Register<ExecuteCommandOnTappedBehavior, ICommand?>(nameof(Command));

public static readonly StyledProperty<object?> CommandParameterProperty =
AvaloniaProperty.Register<ExecuteCommandOnTappedBehavior, object?>(nameof(CommandParameter));

public ICommand? Command
{
get => GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}

public object? CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}

protected override void OnAttached(CompositeDisposable disposables)
{
Gestures.TappedEvent.AddClassHandler<InputElement>(
(x, _) =>
{
if (Equals(x, AssociatedObject))
{
var parameter = CommandParameter;
if (Command is { } cmd && cmd.CanExecute(parameter))
{
cmd.Execute(parameter);
}
}
},
RoutingStrategies.Tunnel | RoutingStrategies.Bubble)
.DisposeWith(disposables);
}
}
11 changes: 11 additions & 0 deletions WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ private RecoverWalletViewModel(WalletCreationOptions.RecoverWallet options)
NextWordCommand = ReactiveCommand.Create(NextWord, canExecuteNextWord);

PreviousWordCommand = ReactiveCommand.Create(PreviousWord);

SelectWordCommand = ReactiveCommand.Create<RecoverWordViewModel>(SelectWord);
}

public ObservableCollectionExtended<RecoverWordViewModel> RecoveryWords { get; } = new();
Expand All @@ -72,6 +74,8 @@ private RecoverWalletViewModel(WalletCreationOptions.RecoverWallet options)

public ICommand PreviousWordCommand { get; }

public ICommand SelectWordCommand { get; }

private int MinGapLimit { get; set; } = 114;

private async Task OnNextAsync(WalletCreationOptions.RecoverWallet options)
Expand Down Expand Up @@ -156,6 +160,13 @@ private void PreviousWord()
}
}

private void SelectWord(RecoverWordViewModel word)
{
_currentWord.IsSelected = false;
_currentWord = word;
_currentWord.IsSelected = true;
}

private void ValidateCurrentMnemonics(IValidationErrors errors)
{
if (CurrentMnemonics is null)
Expand Down
4 changes: 4 additions & 0 deletions WalletWasabi.Fluent/Views/AddWallet/RecoverWalletView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<DataTemplate>
<DockPanel Margin="15 0 15 5"
Width="200">
<Interaction.Behaviors>
<ExecuteCommandOnTappedBehavior Command="{Binding #ItemsControl.((recoverWallet:RecoverWalletViewModel)DataContext).SelectWordCommand, Mode=OneWay}"
CommandParameter="{Binding .}"/>
</Interaction.Behaviors>
<PathIcon Name="IconCheckmark"
Margin="0 0 15 0"
Classes="checkMark"
Expand Down

0 comments on commit 5257a80

Please sign in to comment.