Skip to content
Permalink
Browse files

[WIP] receive label autocomplate

  • Loading branch information...
molnard committed Nov 12, 2018
1 parent cbdf72d commit 2db7a7ccca501f71f9560c3cd03f38bb4fb1d6f6
@@ -14,18 +14,33 @@
<DockPanel LastChildFill="True">

<Grid ColumnDefinitions="*,300" DockPanel.Dock="Top" Margin="0 0 0 10">
<controls:ExtendedTextBox Text="{Binding Label, Mode=TwoWay}" Watermark="Label (Required)" UseFloatingWatermark="True" Grid.Column="0" Margin="0 0 10 0">
<i:Interaction.Behaviors>
<behaviors:SuggestionBehavior SuggestionItems="{Binding Suggestions}" />
<behaviors:CommandOnEnterBehavior Command="{Binding GenerateCommand}" />
<behaviors:FocusBehavior IsFocused="{Binding IsSelected}" />
<iac:FocusOnAttachedToVisualTreeBehavior />
</i:Interaction.Behaviors>
<StackPanel Spacing="8">
<controls:ExtendedTextBox Text="{Binding Label, Mode=TwoWay}" Watermark="Label (Required)" CaretIndex="{Binding CaretIndex, Mode=TwoWay}" UseFloatingWatermark="True" Grid.Column="0" Margin="0 0 10 0">
<i:Interaction.Behaviors>
<behaviors:SuggestionBehavior SuggestionItems="{Binding Suggestions}" />
<behaviors:CommandOnEnterBehavior Command="{Binding GenerateCommand}" />
<behaviors:FocusBehavior IsFocused="{Binding IsSelected}" />
<iac:FocusOnAttachedToVisualTreeBehavior />
</i:Interaction.Behaviors>

<ToolTip.Tip>
Start labelling today and your privacy will thank you tomorrow!
</ToolTip.Tip>
</controls:ExtendedTextBox>
<ToolTip.Tip>
Start labelling today and your privacy will thank you tomorrow!
</ToolTip.Tip>
</controls:ExtendedTextBox>
<ItemsControl Items="{Binding Suggestions}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation ="Horizontal" Spacing="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Focusable="False" Content="{Binding Word}" Command="{Binding OnSelected}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>

<Button Content="Generate Receive Address" Command="{Binding GenerateCommand}" VerticalAlignment="Top" Grid.Column="1" />
</Grid>

@@ -26,10 +26,11 @@ public class ReceiveTabViewModel : WalletActionViewModel
private int _caretIndex;
private ObservableCollection<SuggestionViewModel> _suggestions;

private ReceiveTabViewModel(WalletViewModel walletViewModel)
public ReceiveTabViewModel(WalletViewModel walletViewModel)
: base("Receive", walletViewModel)
{
_addresses = new ObservableCollection<AddressViewModel>();
Label = String.Empty;

Observable.FromEventPattern(Global.WalletService.Coins, nameof(Global.WalletService.Coins.HashSetChanged))
.ObserveOn(RxApp.MainThreadScheduler)
@@ -91,6 +92,15 @@ private ReceiveTabViewModel(WalletViewModel walletViewModel)
});
}
});

this.WhenAnyValue(x => x.CaretIndex).Subscribe(_ =>
{
if (Label == null) return;
if (CaretIndex != Label.Length)
{
CaretIndex = Label.Length;
}
});
_suggestions = new ObservableCollection<SuggestionViewModel>();
}

@@ -173,16 +183,18 @@ private void UpdateSuggestions(string words)

if (lastWorld.Length < 1)
{
_suggestions.Clear();
Suggestions.Clear();
return;
}

var suggestedWords = Global.WalletService.GetNonSpecialLabels().Where(w => w.StartsWith(lastWorld, StringComparison.InvariantCultureIgnoreCase)).Take(7);
var suggestedWords = Global.WalletService.GetNonSpecialLabels().Where(w => w.StartsWith(lastWorld, StringComparison.InvariantCultureIgnoreCase))
.Concat(Global.WalletService.GetNonSpecialLabels().Where(w => w.Contains(lastWorld, StringComparison.InvariantCultureIgnoreCase)))
.Distinct().Take(3);

_suggestions.Clear();
Suggestions.Clear();
foreach (var suggestion in suggestedWords)
{
_suggestions.Add(new SuggestionViewModel(suggestion, OnAddWord));
Suggestions.Add(new SuggestionViewModel(suggestion, OnAddWord));
}
}

@@ -177,6 +177,10 @@ public SendTabViewModel(WalletViewModel walletViewModel)
}
});





this.WhenAnyValue(x => x.Password).Subscribe(x =>
{
if (x.NotNullAndNotEmpty())
@@ -179,16 +179,16 @@ private void UpdateSuggestions(string words)

if (lastWorld.Length < 1)
{
_suggestions.Clear();
Suggestions.Clear();
return;
}

var suggestedWords = EnglishWords.Where(w => w.StartsWith(lastWorld)).Take(7);

_suggestions.Clear();
Suggestions.Clear();
foreach (var suggestion in suggestedWords)
{
_suggestions.Add(new SuggestionViewModel(suggestion, OnAddWord));
Suggestions.Add(new SuggestionViewModel(suggestion, OnAddWord));
}
}

0 comments on commit 2db7a7c

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