Skip to content

Commit

Permalink
Make labels selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
nopara73 committed Nov 13, 2018
1 parent 365e407 commit 0e66242
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 25 deletions.
59 changes: 58 additions & 1 deletion WalletWasabi.Gui/Behaviors/SuggestionBehavior.cs
Expand Up @@ -36,6 +36,63 @@ protected override void OnAttached()
HandleAutoUpdate();
e.Handled = true;
}
if (e.Key == Avalonia.Input.Key.Down)
{
if (SuggestionItems != null)
{
if (SuggestionItems.All(x => !x.IsHighLighted))
{
var item = SuggestionItems.FirstOrDefault();
if (item != null)
{
item.IsHighLighted = true;
}
}
else
{
var index = SuggestionItems.Select((v, i) => new { sugg = v, index = i })?.FirstOrDefault(x => x.sugg.IsHighLighted)?.index;
if (index != null)
{
var suggItemsArray = SuggestionItems.ToArray();
suggItemsArray[index.Value].IsHighLighted = false;
index++;
if (suggItemsArray.Length <= index.Value)
{
index = 0;
}
suggItemsArray[index.Value].IsHighLighted = true;
}
}
e.Handled = true;
}
}
if (e.Key == Avalonia.Input.Key.Up)
{
if (SuggestionItems != null)
{
foreach (var item in SuggestionItems)
{
item.IsHighLighted = false;
}
e.Handled = true;
}
}
if (e.Key == Avalonia.Input.Key.Enter)
{
if (SuggestionItems != null)
{
foreach (var item in SuggestionItems)
{
if (item.IsHighLighted)
{
item.OnSelected();
break;
}
}
e.Handled = true;
}
}
}));
}

Expand All @@ -51,4 +108,4 @@ private void HandleAutoUpdate()
SuggestionItems.FirstOrDefault()?.OnSelected();
}
}
}
}
40 changes: 20 additions & 20 deletions WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabView.xaml
Expand Up @@ -27,20 +27,20 @@
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>
<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}" IsPressed ="{Binding IsHighLighted}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>

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

Expand Down Expand Up @@ -82,17 +82,17 @@
</Panel>
</Expander>
<Grid ColumnDefinitions="400, *, 100" Margin="30 0 0 0">
<TextBlock Text="{Binding Address}" >
<TextBlock Text="{Binding Address}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="_Copy" Command="{Binding CopyToClipboard}" >
<MenuItem Header="_Copy" Command="{Binding CopyToClipboard}">
<MenuItem.Icon>
<DrawingPresenter Height="16" Width="16">
<DrawingPresenter.Drawing>
<GeometryDrawing Brush="#FFFFFFFF" Geometry="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
</DrawingPresenter.Drawing>
</DrawingPresenter>
</MenuItem.Icon>
<DrawingPresenter.Drawing>
<GeometryDrawing Brush="#FFFFFFFF" Geometry="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
</DrawingPresenter.Drawing>
</DrawingPresenter>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
Expand Down
4 changes: 2 additions & 2 deletions WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletView.xaml
Expand Up @@ -20,12 +20,12 @@
<ItemsControl Items="{Binding Suggestions}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation ="Horizontal" Spacing="2"/>
<StackPanel Orientation ="Horizontal" Spacing="2" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Focusable="False" Content="{Binding Word}" Command="{Binding OnSelected}" />
<Button Focusable="False" Content="{Binding Word}" Command="{Binding OnSelected}" IsPressed ="{Binding IsHighLighted}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down
12 changes: 10 additions & 2 deletions WalletWasabi.Gui/Tabs/WalletManager/SuggestionViewModel.cs
Expand Up @@ -5,11 +5,13 @@

namespace WalletWasabi.Gui.Tabs.WalletManager
{
public class SuggestionViewModel
public class SuggestionViewModel : ReactiveObject
{
public string Word { get; }
public Action<string> OnSelection { get; }

public bool _isHighLighted;

public SuggestionViewModel(string word, Action<string> onSeleted)
{
Word = word;
Expand All @@ -20,5 +22,11 @@ public void OnSelected()
{
OnSelection(Word);
}

public bool IsHighLighted
{
get { return _isHighLighted; }
set { this.RaiseAndSetIfChanged(ref _isHighLighted, value); }
}
}
}
}

0 comments on commit 0e66242

Please sign in to comment.