Working rebindable shortcuts
This commit is contained in:
parent
6d75f88927
commit
d1b6d97fe8
@ -191,12 +191,16 @@ namespace unison
|
||||
public HotkeyPair _VolumeDown;
|
||||
public HotkeyPair _VolumeMute;
|
||||
public HotkeyPair _ShowWindow;
|
||||
public HotkeyPair[] _Shortcuts;
|
||||
|
||||
public HotkeyHandler()
|
||||
{
|
||||
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// get shortcuts from settings
|
||||
public void Initialize()
|
||||
{
|
||||
_NextTrack = new HotkeyPair((MOD)Properties.Settings.Default.nextTrack_mod, (VK)Properties.Settings.Default.nextTrack_vk);
|
||||
_PreviousTrack = new HotkeyPair((MOD)Properties.Settings.Default.previousTrack_mod, (VK)Properties.Settings.Default.previousTrack_vk);
|
||||
_PlayPause = new HotkeyPair((MOD)Properties.Settings.Default.playPause_mod, (VK)Properties.Settings.Default.playPause_vk);
|
||||
@ -204,6 +208,7 @@ namespace unison
|
||||
_VolumeDown = new HotkeyPair((MOD)Properties.Settings.Default.volumeDown_mod, (VK)Properties.Settings.Default.volumeDown_vk);
|
||||
_VolumeMute = new HotkeyPair((MOD)Properties.Settings.Default.volumeMute_mod, (VK)Properties.Settings.Default.volumeMute_vk);
|
||||
_ShowWindow = new HotkeyPair((MOD)Properties.Settings.Default.showWindow_mod, (VK)Properties.Settings.Default.showWindow_vk);
|
||||
_Shortcuts = new HotkeyPair[] { _NextTrack, _PreviousTrack, _PlayPause, _VolumeUp, _VolumeDown, _VolumeMute, _ShowWindow };
|
||||
}
|
||||
|
||||
public void Activate(Window win)
|
||||
|
@ -1,15 +1,28 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
||||
|
||||
<system:String x:Key="snapcastPath">snapclient_0.26.0-1_win64</system:String>
|
||||
<system:String x:Key="snapcastPort">1704</system:String>
|
||||
|
||||
<system:String x:Key="connectionOk1"></system:String>
|
||||
<system:String x:Key="connectionOk2"></system:String>
|
||||
<system:String x:Key="connectionFail"></system:String>
|
||||
|
||||
<system:String x:Key="playButton"></system:String>
|
||||
<system:String x:Key="pauseButton"></system:String>
|
||||
|
||||
<system:String x:Key="volume_offset">5</system:String>
|
||||
|
||||
<system:UInt32 x:Key="nextTrack_mod">2</system:UInt32>
|
||||
<system:UInt32 x:Key="nextTrack_vk">176</system:UInt32>
|
||||
<system:UInt32 x:Key="previousTrack_mod">2</system:UInt32>
|
||||
<system:UInt32 x:Key="previousTrack_vk">177</system:UInt32>
|
||||
<system:UInt32 x:Key="playPause_mod">2</system:UInt32>
|
||||
<system:UInt32 x:Key="playPause_vk">179</system:UInt32>
|
||||
<system:UInt32 x:Key="volumeUp_mod">2</system:UInt32>
|
||||
<system:UInt32 x:Key="volumeUp_vk">175</system:UInt32>
|
||||
<system:UInt32 x:Key="volumeDown_mod">2</system:UInt32>
|
||||
<system:UInt32 x:Key="volumeDown_vk">174</system:UInt32>
|
||||
<system:UInt32 x:Key="volumeMute_mod">2</system:UInt32>
|
||||
<system:UInt32 x:Key="volumeMute_vk">173</system:UInt32>
|
||||
<system:UInt32 x:Key="showWindow_mod">3</system:UInt32>
|
||||
<system:UInt32 x:Key="showWindow_vk">13</system:UInt32>
|
||||
|
||||
</ResourceDictionary>
|
@ -4,9 +4,19 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
|
||||
xmlns:properties="clr-namespace:unison.Resources"
|
||||
xmlns:properties="clr-namespace:unison.Resources" xmlns:sys="clr-namespace:System;assembly=System.Runtime"
|
||||
mc:Ignorable="d"
|
||||
Closing="Window_Closing" Title="{x:Static properties:Resources.Settings}" ResizeMode="CanMinimize" Icon="/Resources/icon-full.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
|
||||
|
||||
<Window.Resources>
|
||||
<x:Array x:Key="ShortcutItems" Type="sys:String">
|
||||
<sys:String>None</sys:String>
|
||||
<sys:String>Alt</sys:String>
|
||||
<sys:String>Control</sys:String>
|
||||
<sys:String>Shift</sys:String>
|
||||
</x:Array>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TabControl Margin="10">
|
||||
@ -138,58 +148,58 @@
|
||||
<TextBlock Text="{x:Static properties:Resources.Settings_ShowWindow}" TextWrapping="Wrap" Grid.Column="0" Grid.Row="7" Margin="1,1,1,1"/>
|
||||
|
||||
<StackPanel x:Name="Shortcut_NextTrack" Orientation="Horizontal" Grid.Column="1" Grid.Row="0" Margin="0,0,0,2" Grid.RowSpan="2">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"/>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="Shortcut_PreviousTrack" Orientation="Horizontal" Grid.Column="1" Grid.Row="2" Margin="0,0,0,2">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="Shortcut_PlayPause" Orientation="Horizontal" Grid.Column="1" Grid.Row="3" Margin="0,0,0,2">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="Shortcut_VolumeUp" Orientation="Horizontal" Grid.Column="1" Grid.Row="4" Margin="0,0,0,2">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="Shortcut_VolumeDown" Orientation="Horizontal" Grid.Column="1" Grid.Row="5" Margin="0,0,0,2">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="Shortcut_VolumeMute" Orientation="Horizontal" Grid.Column="1" Grid.Row="6" Margin="0,0,0,2">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel x:Name="Shortcut_ShowWindow" Orientation="Horizontal" Grid.Column="1" Grid.Row="7">
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Bold"></ComboBox>
|
||||
<ComboBox Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Bold"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<TextBlock Text="[key]" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Bold" VerticalAlignment="Stretch"/>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD1" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<ComboBox ItemsSource="{StaticResource ShortcutItems}" Margin="0,0,5,0" MinWidth="70" SelectionChanged="MOD_SelectionChanged" Tag="MOD2" FontWeight="Light" SelectedIndex="0" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"></ComboBox>
|
||||
<Button Click="RemapKey_Clicked" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FocusVisualStyle="{x:Null}">
|
||||
<TextBlock Text="None" TextAlignment="Center" TextWrapping="Wrap" MinWidth="150" Margin="5,1,5,1" HorizontalAlignment="Stretch" FontWeight="Light" VerticalAlignment="Stretch"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
@ -15,8 +15,6 @@ namespace unison
|
||||
{
|
||||
public partial class Settings : Window
|
||||
{
|
||||
Key _pressedKey = Key.None;
|
||||
|
||||
public static string GetVersion => Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
|
||||
public static string GetLicense
|
||||
@ -37,6 +35,8 @@ namespace unison
|
||||
}
|
||||
}
|
||||
|
||||
HotkeyHandler _hotkeys = (HotkeyHandler)Application.Current.Properties["hotkeys"];
|
||||
|
||||
public Settings()
|
||||
{
|
||||
InitHwnd();
|
||||
@ -45,6 +45,11 @@ namespace unison
|
||||
|
||||
WindowState = WindowState.Minimized;
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
MpdHost.Text = Properties.Settings.Default.mpd_host;
|
||||
MpdPort.Text = Properties.Settings.Default.mpd_port.ToString();
|
||||
//MpdPassword.Text = Properties.Settings.Default.mpd_password;
|
||||
@ -54,50 +59,52 @@ namespace unison
|
||||
SnapcastPort.Text = Properties.Settings.Default.snapcast_port.ToString();
|
||||
VolumeOffset.Text = Properties.Settings.Default.volume_offset.ToString();
|
||||
|
||||
SetupShortcuts();
|
||||
InitializeShortcuts();
|
||||
}
|
||||
|
||||
private void SetupShortcuts()
|
||||
void InitializeShortcuts()
|
||||
{
|
||||
var MODValues = System.Enum.GetValues(typeof(HotkeyHandler.MOD));
|
||||
|
||||
System.Collections.Generic.IEnumerable<StackPanel> stackPanelCollection = RebindKeyWrapper.Children.OfType<StackPanel>();
|
||||
foreach (StackPanel stackPanel in stackPanelCollection)
|
||||
StackPanel[] stackPanelList = stackPanelCollection.ToArray();
|
||||
|
||||
// Default state
|
||||
for (int i = 0; i < stackPanelList.Length; i++)
|
||||
{
|
||||
if (stackPanel.Name.Contains("Shortcut"))
|
||||
ComboBox[] comboBoxList = stackPanelList[i].Children.OfType<ComboBox>().ToArray();
|
||||
foreach (ComboBox comboBox in comboBoxList) // default status (for reset)
|
||||
{
|
||||
HotkeyHandler.HotkeyPair hotkey = GetHotkeyVariable(stackPanel.Name);
|
||||
System.Collections.Generic.IEnumerable<ComboBox> comboBoxCollection = stackPanel.Children.OfType<ComboBox>();
|
||||
|
||||
HotkeyHandler.MOD[] MODList = System.Enum.GetValues(typeof(HotkeyHandler.MOD))
|
||||
.OfType<HotkeyHandler.MOD>()
|
||||
.Select(x => x & (HotkeyHandler.MOD)hotkey.GetMOD())
|
||||
.Where(x => x != HotkeyHandler.MOD.None)
|
||||
.ToArray();
|
||||
|
||||
foreach (ComboBox comboBox in comboBoxCollection)
|
||||
{
|
||||
foreach (var value in MODValues)
|
||||
{
|
||||
comboBox.Items.Add(value.ToString().ToLower());
|
||||
comboBox.SelectedItem = comboBox.Items[0];
|
||||
comboBox.FontWeight = FontWeights.Light;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < comboBoxCollection.ToArray().Length; i++)
|
||||
{
|
||||
if (i < MODList.Length)
|
||||
{
|
||||
comboBoxCollection.ToArray()[i].SelectedItem = MODList[i].ToString().ToLower();
|
||||
comboBoxCollection.ToArray()[i].FontWeight = FontWeights.Bold;
|
||||
}
|
||||
}
|
||||
|
||||
System.Collections.Generic.IEnumerable<Button> buttonCollection = stackPanel.Children.OfType<Button>();
|
||||
TextBlock textblock = (TextBlock)buttonCollection.First().Content;
|
||||
textblock.Text = ((HotkeyHandler.VK)hotkey.GetVK()).ToString();
|
||||
comboBox.FontWeight = FontWeights.Light;
|
||||
comboBox.SelectedItem = "None";
|
||||
}
|
||||
TextBlock textBlock = (TextBlock)stackPanelList[i].Children.OfType<Button>().FirstOrDefault().Content;
|
||||
textBlock.Text = "None";
|
||||
}
|
||||
|
||||
// Populate values
|
||||
for (int i = 0; i < stackPanelList.Length; i++)
|
||||
{
|
||||
// setup MOD
|
||||
HotkeyHandler.MOD mod = _hotkeys._Shortcuts[i].mod;
|
||||
|
||||
HotkeyHandler.MOD[] MODList = System.Enum.GetValues(typeof(HotkeyHandler.MOD))
|
||||
.OfType<HotkeyHandler.MOD>()
|
||||
.Select(x => x & _hotkeys._Shortcuts[i].mod)
|
||||
.Where(x => x != HotkeyHandler.MOD.None)
|
||||
.ToArray();
|
||||
|
||||
ComboBox[] comboBox = stackPanelList[i].Children.OfType<ComboBox>().ToArray();
|
||||
for (int j = 0; j < MODList.Length; j++)
|
||||
{
|
||||
comboBox[j].SelectedItem = MODList[j].ToString();
|
||||
if (comboBox[j].SelectedItem.ToString() != "None")
|
||||
comboBox[j].FontWeight = FontWeights.Bold;
|
||||
}
|
||||
|
||||
// setup VK
|
||||
TextBlock textBlock = (TextBlock)stackPanelList[i].Children.OfType<Button>().FirstOrDefault().Content;
|
||||
textBlock.Text = _hotkeys._Shortcuts[i].vk.ToString();
|
||||
if (textBlock.Text != "None")
|
||||
textBlock.FontWeight = FontWeights.Bold;
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,126 +145,6 @@ namespace unison
|
||||
SnapcastPort.Text = (string)Application.Current.FindResource("snapcastPort");
|
||||
}
|
||||
|
||||
private void HotkeyChanged()
|
||||
{
|
||||
HotkeyHandler hotkeys = (HotkeyHandler)Application.Current.Properties["hotkeys"];
|
||||
hotkeys.RemoveHotkeys();
|
||||
hotkeys.AddHotkeys();
|
||||
}
|
||||
|
||||
private ref HotkeyHandler.HotkeyPair GetHotkeyVariable(string Name)
|
||||
{
|
||||
HotkeyHandler hotkeys = (HotkeyHandler)Application.Current.Properties["hotkeys"];
|
||||
|
||||
if (Name == "Shortcut_NextTrack")
|
||||
return ref hotkeys._NextTrack;
|
||||
if (Name == "Shortcut_PreviousTrack")
|
||||
return ref hotkeys._PreviousTrack;
|
||||
if (Name == "Shortcut_PlayPause")
|
||||
return ref hotkeys._PlayPause;
|
||||
if (Name == "Shortcut_VolumeUp")
|
||||
return ref hotkeys._VolumeUp;
|
||||
if (Name == "Shortcut_VolumeDown")
|
||||
return ref hotkeys._VolumeDown;
|
||||
if (Name == "Shortcut_VolumeMute")
|
||||
return ref hotkeys._VolumeMute;
|
||||
if (Name == "Shortcut_ShowWindow")
|
||||
return ref hotkeys._ShowWindow;
|
||||
return ref hotkeys._NextTrack;
|
||||
}
|
||||
|
||||
private void UpdateHotkey_MOD(string Name, HotkeyHandler.MOD mod) => GetHotkeyVariable(Name).SetMOD(mod);
|
||||
private void UpdateHotkey_VK(string Name, HotkeyHandler.VK vk) => GetHotkeyVariable(Name).SetVK(vk);
|
||||
|
||||
private void MOD_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
ComboBox combobox = (ComboBox)sender;
|
||||
StackPanel stackpanel = (StackPanel)combobox.Parent;
|
||||
System.Collections.Generic.IEnumerable<ComboBox> collection = stackpanel.Children.OfType<ComboBox>();
|
||||
|
||||
HotkeyHandler.MOD MOD1, MOD2;
|
||||
|
||||
// we need to do this because the element is modified -after- this function
|
||||
if (combobox.Tag.ToString() == "MOD1")
|
||||
{
|
||||
MOD1 = GetMOD(e.AddedItems[0].ToString());
|
||||
MOD2 = GetMOD(collection.Last().Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
MOD1 = GetMOD(collection.First().Text);
|
||||
MOD2 = GetMOD(e.AddedItems[0].ToString());
|
||||
}
|
||||
|
||||
if (e.AddedItems[0].ToString() == "none")
|
||||
combobox.FontWeight = FontWeights.Light;
|
||||
else
|
||||
combobox.FontWeight = FontWeights.Bold;
|
||||
|
||||
HotkeyHandler.MOD ModKey = MOD1 | MOD2;
|
||||
|
||||
UpdateHotkey_MOD(stackpanel.Name, ModKey);
|
||||
HotkeyChanged();
|
||||
}
|
||||
|
||||
private void RemapKey_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button button = (Button)sender;
|
||||
TextBlock textBlock = (TextBlock)button.Content;
|
||||
textBlock.Text = "Enter key...";
|
||||
button.PreviewKeyDown += DetectPressedKey;
|
||||
}
|
||||
|
||||
private void DetectPressedKey(object sender, KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true; // not enough to handle media keys triggering in this setup
|
||||
|
||||
_pressedKey = e.Key;
|
||||
HotkeyHandler.VK VirtualKey = GetVirtualKey(_pressedKey);
|
||||
if (VirtualKey == HotkeyHandler.VK.None)
|
||||
_pressedKey = Key.None;
|
||||
|
||||
Button button = (Button)sender;
|
||||
TextBlock textBlock = (TextBlock)button.Content;
|
||||
StackPanel stackPanel = (StackPanel)button.Parent;
|
||||
|
||||
textBlock.Text = _pressedKey.ToString();
|
||||
button.PreviewKeyDown -= DetectPressedKey;
|
||||
|
||||
UpdateHotkey_VK(stackPanel.Name, VirtualKey);
|
||||
HotkeyChanged();
|
||||
}
|
||||
|
||||
private HotkeyHandler.VK GetVirtualKey(Key key)
|
||||
{
|
||||
var values = System.Enum.GetValues(typeof(HotkeyHandler.VK));
|
||||
foreach (object value in values)
|
||||
{
|
||||
if (key.ToString().ToLower() == value.ToString().ToLower())
|
||||
return (HotkeyHandler.VK)value;
|
||||
}
|
||||
return HotkeyHandler.VK.None;
|
||||
}
|
||||
|
||||
private HotkeyHandler.MOD GetMOD(string str)
|
||||
{
|
||||
var values = System.Enum.GetValues(typeof(HotkeyHandler.MOD));
|
||||
foreach (object value in values)
|
||||
{
|
||||
if (str.ToLower() == value.ToString().ToLower())
|
||||
return (HotkeyHandler.MOD)value;
|
||||
}
|
||||
return HotkeyHandler.MOD.None;
|
||||
}
|
||||
|
||||
private void ShortcutsReset_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
||||
public void UpdateStats()
|
||||
{
|
||||
MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
@ -270,7 +157,156 @@ namespace unison
|
||||
StatDatabaseUpdate.Text = mpd.GetStats().DatabaseUpdate.ToString();
|
||||
}
|
||||
|
||||
private void HotkeyChanged()
|
||||
{
|
||||
_hotkeys.RemoveHotkeys();
|
||||
_hotkeys.AddHotkeys();
|
||||
}
|
||||
|
||||
private ref HotkeyHandler.HotkeyPair GetHotkeyVariable(string Name)
|
||||
{
|
||||
if (Name == "Shortcut_NextTrack")
|
||||
return ref _hotkeys._NextTrack;
|
||||
if (Name == "Shortcut_PreviousTrack")
|
||||
return ref _hotkeys._PreviousTrack;
|
||||
if (Name == "Shortcut_PlayPause")
|
||||
return ref _hotkeys._PlayPause;
|
||||
if (Name == "Shortcut_VolumeUp")
|
||||
return ref _hotkeys._VolumeUp;
|
||||
if (Name == "Shortcut_VolumeDown")
|
||||
return ref _hotkeys._VolumeDown;
|
||||
if (Name == "Shortcut_VolumeMute")
|
||||
return ref _hotkeys._VolumeMute;
|
||||
if (Name == "Shortcut_ShowWindow")
|
||||
return ref _hotkeys._ShowWindow;
|
||||
return ref _hotkeys._NextTrack;
|
||||
}
|
||||
|
||||
private void UpdateHotkey_MOD(string Name, HotkeyHandler.MOD mod) => GetHotkeyVariable(Name).SetMOD(mod);
|
||||
private void UpdateHotkey_VK(string Name, HotkeyHandler.VK vk) => GetHotkeyVariable(Name).SetVK(vk);
|
||||
|
||||
private void MOD_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
ComboBox comboBox = (ComboBox)sender;
|
||||
StackPanel stackPanel = (StackPanel)comboBox.Parent;
|
||||
System.Collections.Generic.IEnumerable<ComboBox> stackPanelCollection = stackPanel.Children.OfType<ComboBox>();
|
||||
|
||||
HotkeyHandler.MOD MOD1, MOD2;
|
||||
|
||||
// we need to do this because the element is modified -after- this function
|
||||
if (comboBox.Tag.ToString() == "MOD1")
|
||||
{
|
||||
MOD1 = GetMOD(e.AddedItems[0].ToString());
|
||||
MOD2 = GetMOD(stackPanelCollection.Last().Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
MOD1 = GetMOD(stackPanelCollection.First().Text);
|
||||
MOD2 = GetMOD(e.AddedItems[0].ToString());
|
||||
}
|
||||
|
||||
if (e.AddedItems[0].ToString() == "None")
|
||||
comboBox.FontWeight = FontWeights.Light;
|
||||
else
|
||||
comboBox.FontWeight = FontWeights.Bold;
|
||||
|
||||
HotkeyHandler.MOD ModKey = MOD1 | MOD2;
|
||||
|
||||
UpdateHotkey_MOD(stackPanel.Name, ModKey);
|
||||
HotkeyChanged();
|
||||
}
|
||||
|
||||
private void RemapKey_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button button = (Button)sender;
|
||||
TextBlock textBlock = (TextBlock)button.Content;
|
||||
textBlock.Text = "Enter key...";
|
||||
textBlock.FontWeight = FontWeights.Bold;
|
||||
button.PreviewKeyDown += DetectPressedKey;
|
||||
}
|
||||
|
||||
private void DetectPressedKey(object sender, KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
||||
Key pressedKey = e.Key;
|
||||
HotkeyHandler.VK VirtualKey = GetVirtualKey(pressedKey);
|
||||
|
||||
Button button = (Button)sender;
|
||||
TextBlock textBlock = (TextBlock)button.Content;
|
||||
StackPanel stackPanel = (StackPanel)button.Parent;
|
||||
|
||||
if (VirtualKey == HotkeyHandler.VK.None)
|
||||
{
|
||||
pressedKey = Key.None;
|
||||
textBlock.FontWeight = FontWeights.Light;
|
||||
}
|
||||
else
|
||||
textBlock.FontWeight = FontWeights.Bold;
|
||||
|
||||
textBlock.Text = pressedKey.ToString();
|
||||
button.PreviewKeyDown -= DetectPressedKey;
|
||||
|
||||
UpdateHotkey_VK(stackPanel.Name, VirtualKey);
|
||||
HotkeyChanged();
|
||||
}
|
||||
|
||||
private HotkeyHandler.VK GetVirtualKey(Key key)
|
||||
{
|
||||
foreach (object value in System.Enum.GetValues(typeof(HotkeyHandler.VK)))
|
||||
{
|
||||
if (key.ToString().ToLower() == value.ToString().ToLower())
|
||||
return (HotkeyHandler.VK)value;
|
||||
}
|
||||
return HotkeyHandler.VK.None;
|
||||
}
|
||||
|
||||
private HotkeyHandler.MOD GetMOD(string str)
|
||||
{
|
||||
foreach (object value in System.Enum.GetValues(typeof(HotkeyHandler.MOD)))
|
||||
{
|
||||
if (str.ToLower() == value.ToString().ToLower())
|
||||
return (HotkeyHandler.MOD)value;
|
||||
}
|
||||
return HotkeyHandler.MOD.None;
|
||||
}
|
||||
|
||||
private void ShortcutsReset_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Properties.Settings.Default.nextTrack_mod = (uint)Application.Current.FindResource("nextTrack_mod");
|
||||
Properties.Settings.Default.nextTrack_vk = (uint)Application.Current.FindResource("nextTrack_vk");
|
||||
Properties.Settings.Default.previousTrack_mod = (uint)Application.Current.FindResource("previousTrack_mod");
|
||||
Properties.Settings.Default.previousTrack_vk = (uint)Application.Current.FindResource("previousTrack_vk");
|
||||
Properties.Settings.Default.playPause_mod = (uint)Application.Current.FindResource("playPause_mod");
|
||||
Properties.Settings.Default.playPause_vk = (uint)Application.Current.FindResource("playPause_vk");
|
||||
Properties.Settings.Default.volumeUp_mod = (uint)Application.Current.FindResource("volumeUp_mod");
|
||||
Properties.Settings.Default.volumeUp_vk = (uint)Application.Current.FindResource("volumeUp_vk");
|
||||
Properties.Settings.Default.volumeDown_mod = (uint)Application.Current.FindResource("volumeDown_mod");
|
||||
Properties.Settings.Default.volumeDown_vk = (uint)Application.Current.FindResource("volumeDown_vk");
|
||||
Properties.Settings.Default.volumeMute_mod = (uint)Application.Current.FindResource("volumeMute_mod");
|
||||
Properties.Settings.Default.volumeMute_vk = (uint)Application.Current.FindResource("volumeMute_vk");
|
||||
Properties.Settings.Default.showWindow_mod = (uint)Application.Current.FindResource("showWindow_mod");
|
||||
Properties.Settings.Default.showWindow_vk = (uint)Application.Current.FindResource("showWindow_vk");
|
||||
|
||||
_hotkeys.Initialize();
|
||||
HotkeyChanged();
|
||||
InitializeShortcuts();
|
||||
}
|
||||
|
||||
public uint GetMod(StackPanel stackPanel)
|
||||
{
|
||||
return (uint)(GetMOD(stackPanel.Children.OfType<ComboBox>().First().SelectedItem.ToString()) | GetMOD(stackPanel.Children.OfType<ComboBox>().Last().SelectedItem.ToString()));
|
||||
}
|
||||
|
||||
public uint GetVk(StackPanel stackPanel)
|
||||
{
|
||||
Button button = stackPanel.Children.OfType<Button>().First();
|
||||
TextBlock textBlock = (TextBlock)button.Content;
|
||||
return (uint)(HotkeyHandler.VK)System.Enum.Parse(typeof(HotkeyHandler.VK), textBlock.Text, true);
|
||||
}
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
@ -283,21 +319,20 @@ namespace unison
|
||||
Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture);
|
||||
Properties.Settings.Default.volume_offset = int.Parse(VolumeOffset.Text, CultureInfo.InvariantCulture);
|
||||
|
||||
// todo
|
||||
Properties.Settings.Default.nextTrack_mod = (uint)(GetMOD(Shortcut_NextTrack.Children.OfType<ComboBox>().First().SelectedItem.ToString()) | GetMOD(Shortcut_NextTrack.Children.OfType<ComboBox>().Last().SelectedItem.ToString()));
|
||||
/*Properties.Settings.Default.nextTrack_vk) = (uint)GetVirtualKey(Shortcut_NextTrack.Children.OfType<Button>().First().)
|
||||
Properties.Settings.Default.previousTrack_mod;
|
||||
Properties.Settings.Default.previousTrack_vk);
|
||||
Properties.Settings.Default.playPause_mod;
|
||||
Properties.Settings.Default.playPause_vk);
|
||||
Properties.Settings.Default.volumeUp_mod;
|
||||
Properties.Settings.Default.volumeUp_vk);
|
||||
Properties.Settings.Default.volumeDown_mod;
|
||||
Properties.Settings.Default.volumeDown_vk);
|
||||
Properties.Settings.Default.volumeMute_mod;
|
||||
Properties.Settings.Default.volumeMute_vk);
|
||||
Properties.Settings.Default.showWindow_mod;
|
||||
Properties.Settings.Default.showWindow_vk);*/
|
||||
Properties.Settings.Default.nextTrack_mod = GetMod(Shortcut_NextTrack);
|
||||
Properties.Settings.Default.nextTrack_vk = GetVk(Shortcut_NextTrack);
|
||||
Properties.Settings.Default.previousTrack_mod = GetMod(Shortcut_PreviousTrack);
|
||||
Properties.Settings.Default.previousTrack_vk = GetVk(Shortcut_PreviousTrack);
|
||||
Properties.Settings.Default.playPause_mod = GetMod(Shortcut_PlayPause);
|
||||
Properties.Settings.Default.playPause_vk = GetVk(Shortcut_PlayPause);
|
||||
Properties.Settings.Default.volumeUp_mod = GetMod(Shortcut_VolumeUp);
|
||||
Properties.Settings.Default.volumeUp_vk = GetVk(Shortcut_VolumeUp);
|
||||
Properties.Settings.Default.volumeDown_mod = GetMod(Shortcut_VolumeDown);
|
||||
Properties.Settings.Default.volumeDown_vk = GetVk(Shortcut_VolumeDown);
|
||||
Properties.Settings.Default.volumeMute_mod = GetMod(Shortcut_VolumeMute);
|
||||
Properties.Settings.Default.volumeMute_vk = GetVk(Shortcut_VolumeMute);
|
||||
Properties.Settings.Default.showWindow_mod = GetMod(Shortcut_ShowWindow);
|
||||
Properties.Settings.Default.showWindow_vk = GetVk(Shortcut_ShowWindow);
|
||||
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user