Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to transform a list of special keys into keycapborder visuals #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions src/Carnac/UI/KeyShowView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<ui:ToSpecialKeyConverter x:Key="ToSpecialKeyConverter"/>

<DrawingBrush x:Key="Layer1" Stretch="Uniform">
<DrawingBrush.Drawing>
Expand Down Expand Up @@ -149,26 +150,7 @@
<Setter TargetName="regular" Property="Control.Visibility" Value="Collapsed" />
</DataTrigger>

<DataTrigger Value="Back" Binding="{Binding .}">
<Setter TargetName="KeyCapBorder" Property="Control.Visibility" Value="Visible" />
<Setter TargetName="regular" Property="Control.Visibility" Value="Collapsed" />
</DataTrigger>

<DataTrigger Value="Escape" Binding="{Binding .}">
<Setter TargetName="KeyCapBorder" Property="Control.Visibility" Value="Visible" />
<Setter TargetName="regular" Property="Control.Visibility" Value="Collapsed" />
</DataTrigger>

<DataTrigger Value="Alt" Binding="{Binding .}">
<Setter TargetName="KeyCapBorder" Property="Control.Visibility" Value="Visible" />
<Setter TargetName="regular" Property="Control.Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Value="Ctrl" Binding="{Binding .}">
<Setter TargetName="KeyCapBorder" Property="Control.Visibility" Value="Visible" />
<Setter TargetName="regular" Property="Control.Visibility" Value="Collapsed" />
</DataTrigger>

<DataTrigger Value="Shift" Binding="{Binding .}">
<DataTrigger Value="SPECIAL_KEY" Binding="{Binding ., Converter={StaticResource ToSpecialKeyConverter}}">
<Setter TargetName="KeyCapBorder" Property="Control.Visibility" Value="Visible" />
<Setter TargetName="regular" Property="Control.Visibility" Value="Collapsed" />
</DataTrigger>
Expand Down
55 changes: 55 additions & 0 deletions src/Carnac/UI/ToSpecialKeyConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;

namespace Carnac.UI
{
public class ToSpecialKeyConverter : IValueConverter
{

private readonly List<String> specialKeys = new List<String>(){
"Escape",
"Alt",
"Ctrl",
"Shift",
"Tab",
"Delete",
"Insert",
"Home",
"Next",
"PageUp",
"PageDown",
"End",
"Back",
"NumLock",
"PrintScreen",
"Scroll",
"Capital",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12",
"Apps",
"BrowserHome",
};

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return specialKeys.Contains(value.ToString()) ? "SPECIAL_KEY" : value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}