Skip to content
Permalink
Browse files

Make labels selectable

  • Loading branch information...
nopara73 committed Nov 13, 2018
1 parent 365e407 commit 0e662420d593d73e9adebbe11dbeb1c9b3d7585f
@@ -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;
}
}
}));
}

@@ -51,4 +108,4 @@ private void HandleAutoUpdate()
SuggestionItems.FirstOrDefault()?.OnSelected();
}
}
}
}
@@ -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>

@@ -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>
@@ -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>
@@ -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;
@@ -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.
You can’t perform that action at this time.