Skip to content
Permalink
Browse files

Use Buttons for clickable suggestions

  • Loading branch information...
lontivero committed Nov 5, 2018
1 parent 297d5ae commit 5ab3d14ae50ae4b8295925dd4d187340ee958a78
@@ -12,10 +12,10 @@ internal class MnemonicSuggestionBehavior : Behavior<TextBox>
{
private CompositeDisposable _disposables;

private static readonly AvaloniaProperty<string> SuggestionItemsProperty =
AvaloniaProperty.Register<MnemonicSuggestionBehavior, string>(nameof(SuggestionItems), defaultBindingMode: Avalonia.Data.BindingMode.TwoWay);
private static readonly AvaloniaProperty<string[]> SuggestionItemsProperty =
AvaloniaProperty.Register<MnemonicSuggestionBehavior, string[]>(nameof(SuggestionItems), defaultBindingMode: Avalonia.Data.BindingMode.TwoWay);

public string SuggestionItems
public string[] SuggestionItems
{
get => GetValue(SuggestionItemsProperty);
set => SetValue(SuggestionItemsProperty, value);
@@ -50,11 +50,10 @@ private void HandleAutoUpdate()
var text = textBox.Text;
var enteredWordList = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var lastWorld = enteredWordList.LastOrDefault();
var suggestions = SuggestionItems.Split(" ", StringSplitOptions.RemoveEmptyEntries);
var suggestions = SuggestionItems;
if(suggestions.Length == 1)
{
textBox.Text = text.Substring(0, text.Length - lastWorld.Length) + suggestions[0] + " ";
textBox.CaretIndex = textBox.Text.Length;
}
}
}
@@ -17,7 +17,18 @@
<behaviors:MnemonicSuggestionBehavior SuggestionItems="{Binding Suggestions}" />
</i:Interaction.Behaviors>
</controls:ExtendedTextBox>
<TextBlock Text="{Binding Suggestions}" FontWeight="Bold" />
<ItemsControl Items="{Binding Suggestions}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation ="Horizontal" Spacing="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Focusable="False" Content="{Binding}" Command="{Binding $parent[ItemsControl].DataContext.OnAddWord}" CommandParameter="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</controls:GroupBox>
@@ -20,7 +20,7 @@ internal class RecoverWalletViewModel : CategoryViewModel
private string _walletName;
private bool _termsAccepted;
private string _validationMessage;
private string _suggestions;
private string[] _suggestions;

public RecoverWalletViewModel(WalletManagerViewModel owner) : base("Recover Wallet")
{
@@ -91,7 +91,7 @@ public string MnemonicWords
set { this.RaiseAndSetIfChanged(ref _mnemonicWords, value); }
}

public string Suggestions
public string[] Suggestions
{
get { return _suggestions; }
set { this.RaiseAndSetIfChanged(ref _suggestions, value); }
@@ -153,12 +153,21 @@ private void UpdateSuggestions(string words)

if (lastWorld.Length < 1)
{
Suggestions = string.Empty;
Suggestions = new string[0];
return;
}

var suggestedWords = EnglishWords.Where(w => w.StartsWith(lastWorld));
Suggestions = string.Join(" ", suggestedWords.ToArray());
Suggestions = suggestedWords.ToArray();
}

public void OnAddWord(string word)
{
string[] words = MnemonicWords.Split(' ', StringSplitOptions.RemoveEmptyEntries);
words[words.Length-1] = word;

Suggestions = new string[0];
MnemonicWords = string.Join(' ', words) + " ";
}

private static IEnumerable<string> EnglishWords = Wordlist.English.GetWords();

0 comments on commit 5ab3d14

Please sign in to comment.
You can’t perform that action at this time.