From d1b6d97fe85282ba18ff9cd4f3e2401af90d0be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Thu, 7 Apr 2022 00:01:55 +0200 Subject: [PATCH] Working rebindable shortcuts --- Handlers/HotkeyHandler.cs | 9 +- Resources/Resources.xaml | 23 ++- Views/Settings.xaml | 68 ++++--- Views/Settings.xaml.cs | 385 +++++++++++++++++++++----------------- 4 files changed, 274 insertions(+), 211 deletions(-) diff --git a/Handlers/HotkeyHandler.cs b/Handlers/HotkeyHandler.cs index 3d57eb2..37337ad 100644 --- a/Handlers/HotkeyHandler.cs +++ b/Handlers/HotkeyHandler.cs @@ -173,7 +173,7 @@ namespace unison public uint GetMOD() { return (uint)mod; } public uint GetVK() { return (uint)vk; } - + public void SetMOD(MOD modmod) { mod = modmod; } public void SetVK(VK vkvk) { vk = vkvk; } } @@ -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) diff --git a/Resources/Resources.xaml b/Resources/Resources.xaml index 858e664..925671d 100644 --- a/Resources/Resources.xaml +++ b/Resources/Resources.xaml @@ -1,15 +1,28 @@  + xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:sys="clr-namespace:System;assembly=System.Runtime"> snapclient_0.26.0-1_win64 1704 - - - - + 5 + + 2 + 176 + 2 + 177 + 2 + 179 + 2 + 175 + 2 + 174 + 2 + 173 + 3 + 13 + \ No newline at end of file diff --git a/Views/Settings.xaml b/Views/Settings.xaml index 61bf055..1035abf 100644 --- a/Views/Settings.xaml +++ b/Views/Settings.xaml @@ -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"> + + + + None + Alt + Control + Shift + + + @@ -138,58 +148,58 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/Views/Settings.xaml.cs b/Views/Settings.xaml.cs index 386bade..09bbeae 100644 --- a/Views/Settings.xaml.cs +++ b/Views/Settings.xaml.cs @@ -15,8 +15,6 @@ namespace unison { public partial class Settings : Window { - Key _pressedKey = Key.None; - public static string GetVersion => Assembly.GetEntryAssembly().GetCustomAttribute().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 stackPanelCollection = RebindKeyWrapper.Children.OfType(); - 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().ToArray(); + foreach (ComboBox comboBox in comboBoxList) // default status (for reset) { - HotkeyHandler.HotkeyPair hotkey = GetHotkeyVariable(stackPanel.Name); - System.Collections.Generic.IEnumerable comboBoxCollection = stackPanel.Children.OfType(); - - HotkeyHandler.MOD[] MODList = System.Enum.GetValues(typeof(HotkeyHandler.MOD)) - .OfType() - .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