Skip to content

Commit

Permalink
Add shortcut edit control
Browse files Browse the repository at this point in the history
  • Loading branch information
comzyh committed Jul 23, 2019
1 parent 7b01698 commit c2ff6a8
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 7 deletions.
19 changes: 19 additions & 0 deletions WpfDemo/Models/SFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;

namespace WpfDemo
{
Expand Down Expand Up @@ -41,6 +42,20 @@ public class BLEGravitySensorConfig
public string BindedMonitor;

}
public class SFShortcutConfig
{
public string Clockwise_0;
public string Clockwise_90;
public string Clockwise_180;
public string Clockwise_270;
}
public class SFManualSettings
{
public string BindedMonitor;


}

public class SFSettings
{
public List<BLEGravitySensorConfig> sensors;
Expand All @@ -49,5 +64,9 @@ public SFSettings()
{
sensors = new List<BLEGravitySensorConfig>();
}
public static SFSettings GetDefault()
{
return new SFSettings();
}
}
}
56 changes: 56 additions & 0 deletions WpfDemo/Models/ShortcutBinding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfDemo.Models
{
public class ShortcutBinding : INotifyPropertyChanged
{
private string shortcut;
private bool enabled;
private bool isActive;
public string Shortcut
{
get => shortcut;
set
{
if (value != shortcut)
{
shortcut = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Shortcut"));
}
}
}
public bool Enabled
{
get => enabled;
set
{
if (value != enabled)
{
enabled = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Enabled"));

}

}
}

public bool IsActive
{
get => isActive;
set
{
if (value != isActive)
{
isActive = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("isActive"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
25 changes: 24 additions & 1 deletion WpfDemo/Pages/ManualPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfDemo"
xmlns:controls="clr-namespace:WpfDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="ManualPage">
Expand All @@ -15,7 +16,29 @@
<Label Margin="50,40,0,0" Height="Auto" Width="330" HorizontalAlignment="Left">Default hotkey setting</Label>
</StackPanel>

<Grid Margin="60,185,160,0">
<StackPanel Margin="60,185,160,0" Orientation="Vertical">
<StackPanel Height="60" Orientation="Horizontal">
<Image Source="/Imgs/arrayUp.png" Grid.Column="0" Grid.Row="6" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="Auto" Width="Auto" ></Image>
<controls:ShortcutEdit />
</StackPanel>
<StackPanel Height="60" Orientation="Horizontal">
<Image Source="/Imgs/arrayRight.png" Grid.Column="0" Grid.Row="6" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="Auto" Width="Auto" ></Image>
<controls:ShortcutEdit />
</StackPanel>
<StackPanel Height="60" Orientation="Horizontal">
<Image Source="/Imgs/arrayLeft.png" Grid.Column="0" Grid.Row="6" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="Auto" Width="Auto" ></Image>
<controls:ShortcutEdit />
</StackPanel>
<StackPanel Height="60" Orientation="Horizontal">
<Image Source="/Imgs/arrayDown.png" Grid.Column="0" Grid.Row="6" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="Auto" Width="Auto" ></Image>
<controls:ShortcutEdit />
</StackPanel>
</StackPanel>
<Grid Margin="60,185,160,0" Visibility="Hidden">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="500"/>
Expand Down
17 changes: 11 additions & 6 deletions WpfDemo/UserControls/SensorControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public SensorControl(IBLEAccelerationSensor sensor)
this.sensor = sensor;
stackPanelMain.DataContext = sensor;
comboBindMonitor.ItemsSource = monitorDeviceNames;
RefreshDisplays();
}

private void ButtonCalibrate_Click(object sender, RoutedEventArgs e)
Expand All @@ -42,12 +43,7 @@ private void ButtonCalibrate_Click(object sender, RoutedEventArgs e)

private void BtnRefresh_Click(object sender, RoutedEventArgs e)
{
Dictionary<uint, Display.MonitorInfo> devDic = Display.FindDevNumList();
monitorDeviceNames.Clear();
foreach (uint devNum in devDic.Keys)
{
monitorDeviceNames.Add(devDic[devNum].deviceName);
}
RefreshDisplays();
}

private void BtnDisconnect_Click(object sender, RoutedEventArgs e)
Expand All @@ -59,6 +55,15 @@ private void BtnClearBind_Click(object sender, RoutedEventArgs e)
{
sensor.Binding.MonitorDeviceName = "";
}
private void RefreshDisplays()
{
Dictionary<uint, Display.MonitorInfo> devDic = Display.FindDevNumList();
monitorDeviceNames.Clear();
foreach (uint devNum in devDic.Keys)
{
monitorDeviceNames.Add(devDic[devNum].deviceName);
}
}
}


Expand Down
24 changes: 24 additions & 0 deletions WpfDemo/UserControls/ShortcutEdit.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<UserControl x:Class="WpfDemo.UserControls.ShortcutEdit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfDemo.UserControls"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="350">
<Grid x:Name="mainGrid">
<StackPanel x:Name="panelEdit" Orientation="Horizontal" Margin="0,0,-22,0" Visibility="Visible" Width="372">
<CheckBox Content="Enable" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0" IsChecked="{Binding Enable}" />
<TextBox x:Name="txtShortcut" VerticalAlignment="Center" Margin="10,0,10,0" TextWrapping="Wrap" Width="230" Height="26" IsReadOnly="True"
KeyDown="TxtShortcut_KeyDown"
KeyUp="TxtShortcut_KeyUp"
LostFocus="TxtShortcut_LostFocus"
Visibility="Collapsed"
/>
<Label x:Name="txtBlockShortcut" VerticalAlignment="Center" Width="230" Height="26" Content="{Binding Shortcut}" Margin="10,0,0,0"
MouseDoubleClick="TxtBlockShortcut_MouseDoubleClick"
Visibility="Visible"
/>
</StackPanel>
</Grid>
</UserControl>
86 changes: 86 additions & 0 deletions WpfDemo/UserControls/ShortcutEdit.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfDemo.Models;

namespace WpfDemo.UserControls
{
/// <summary>
/// Interaction logic for ShortcutEdit.xaml
/// </summary>
public partial class ShortcutEdit : UserControl
{
ShortcutBinding binding;
HashSet<Key> keys;
public ShortcutEdit()
{
InitializeComponent();
binding = DataContext as ShortcutBinding;
keys = new HashSet<Key>();
}



private void TxtShortcut_KeyDown(object sender, KeyEventArgs e)
{
keys.Add(e.Key);
txtShortcut.Text = TransformSetToText(keys);
}

private void TxtShortcut_KeyUp(object sender, KeyEventArgs e)
{
//keys.Remove(e.Key);
//txtShortcut.Text = TransformSetToText(keys);
}

static public string TransformSetToText(HashSet<Key> keys)
{
StringBuilder stringBuilder = new StringBuilder();
foreach(var key in keys)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(" + ");
}
string keyString = key.ToString();
if (keyString.StartsWith("Left"))
{
keyString = keyString.Replace("Left", "");
} else if (keyString.StartsWith("Right"))
{
keyString = keyString.Replace("Left", "");
}
stringBuilder.Append(keyString);
}
return stringBuilder.ToString();
}

private void TxtBlockShortcut_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
txtBlockShortcut.Visibility = Visibility.Collapsed;
txtShortcut.Text = txtBlockShortcut.Content as string ;
keys.Clear();
txtShortcut.Visibility = Visibility.Visible;
txtShortcut.Focus();

}
private void TxtShortcut_LostFocus(object sender, RoutedEventArgs e)
{
txtShortcut.Visibility = Visibility.Collapsed;
txtBlockShortcut.Visibility = Visibility.Visible;
txtBlockShortcut.Content = txtShortcut.Text;
}

}
}
8 changes: 8 additions & 0 deletions WpfDemo/WpfDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<DependentUpon>HomeWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Models\MonitorBinding.cs" />
<Compile Include="Models\ShortcutBinding.cs" />
<Compile Include="Pages\ManualPage.xaml.cs">
<DependentUpon>ManualPage.xaml</DependentUpon>
</Compile>
Expand All @@ -97,6 +98,9 @@
<Compile Include="UserControls\SensorItem.xaml.cs">
<DependentUpon>SensorItem.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\ShortcutEdit.xaml.cs">
<DependentUpon>ShortcutEdit.xaml</DependentUpon>
</Compile>
<Compile Include="ValueConverters.cs" />
<Page Include="CalibrationWindow.xaml">
<SubType>Designer</SubType>
Expand Down Expand Up @@ -138,6 +142,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\ShortcutEdit.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down

0 comments on commit c2ff6a8

Please sign in to comment.