11using System ;
2+ using System . Collections . Generic ;
23using System . Windows ;
34using System . Windows . Controls ;
45using System . Windows . Input ;
@@ -26,6 +27,18 @@ public partial class HotkeyEditControl : UserControl
2627 typeof ( HotkeyEditControl ) ,
2728 new PropertyMetadata ( true ) ) ;
2829
30+ public static readonly DependencyProperty EditingPartsProperty = DependencyProperty . Register (
31+ nameof ( EditingParts ) ,
32+ typeof ( List < HotkeyPart > ) ,
33+ typeof ( HotkeyEditControl ) ,
34+ new PropertyMetadata ( new List < HotkeyPart > ( ) ) ) ;
35+
36+ public static readonly DependencyProperty IsGlowActiveProperty = DependencyProperty . Register (
37+ nameof ( IsGlowActive ) ,
38+ typeof ( bool ) ,
39+ typeof ( HotkeyEditControl ) ,
40+ new PropertyMetadata ( false ) ) ;
41+
2942 public HotkeyBinding ? HotkeyBinding
3043 {
3144 get => ( HotkeyBinding ? ) GetValue ( HotkeyBindingProperty ) ;
@@ -44,17 +57,38 @@ public bool IsNotEditing
4457 set => SetValue ( IsNotEditingProperty , value ) ;
4558 }
4659
60+ public List < HotkeyPart > EditingParts
61+ {
62+ get => ( List < HotkeyPart > ) GetValue ( EditingPartsProperty ) ;
63+ set => SetValue ( EditingPartsProperty , value ) ;
64+ }
65+
66+ public bool IsGlowActive
67+ {
68+ get => ( bool ) GetValue ( IsGlowActiveProperty ) ;
69+ set => SetValue ( IsGlowActiveProperty , value ) ;
70+ }
71+
4772 public event EventHandler < HotkeyChangedEventArgs > ? HotkeyChanged ;
4873 public event EventHandler < string > ? HotkeyCleared ;
4974 public event EventHandler ? EditStarted ;
5075 public event EventHandler ? EditEnded ;
5176
5277 private Key _pendingKey = Key . None ;
5378 private ModifierKeys _pendingModifiers = ModifierKeys . None ;
79+ private readonly System . Windows . Threading . DispatcherTimer _glowTimer = new ( )
80+ {
81+ Interval = TimeSpan . FromMilliseconds ( 500 )
82+ } ;
5483
5584 public HotkeyEditControl ( )
5685 {
5786 InitializeComponent ( ) ;
87+ _glowTimer . Tick += ( _ , _ ) =>
88+ {
89+ _glowTimer . Stop ( ) ;
90+ IsGlowActive = false ;
91+ } ;
5892 }
5993
6094 private static void OnIsEditingChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
@@ -79,6 +113,8 @@ private void EditButton_Click(object sender, RoutedEventArgs e)
79113 {
80114 _pendingKey = Key . None ;
81115 _pendingModifiers = ModifierKeys . None ;
116+ EditingParts = HotkeyBinding ? . DisplayParts ?? new List < HotkeyPart > { new ( "Not Set" , true ) } ;
117+ IsGlowActive = false ;
82118 EditStarted ? . Invoke ( this , EventArgs . Empty ) ;
83119 IsEditing = true ;
84120 }
@@ -117,6 +153,7 @@ private void EditBorder_PreviewKeyDown(object sender, KeyEventArgs e)
117153 key == Key . LeftShift || key == Key . RightShift ||
118154 key == Key . LWin || key == Key . RWin )
119155 {
156+ EditingParts = BuildEditingParts ( Keyboard . Modifiers , Key . None ) ;
120157 return ;
121158 }
122159
@@ -133,12 +170,15 @@ private void EditBorder_PreviewKeyDown(object sender, KeyEventArgs e)
133170 _pendingKey = key ;
134171 _pendingModifiers = modifiers ;
135172
173+ EditingParts = BuildEditingParts ( modifiers , key ) ;
174+
136175 // Apply the hotkey
137176 if ( HotkeyBinding != null )
138177 {
139178 HotkeyChanged ? . Invoke ( this , new HotkeyChangedEventArgs ( HotkeyBinding . Name , key , modifiers ) ) ;
140179 }
141180
181+ TriggerGlow ( ) ;
142182 IsEditing = false ;
143183 EditEnded ? . Invoke ( this , EventArgs . Empty ) ;
144184 }
@@ -153,6 +193,36 @@ private static bool IsFunctionKey(Key key)
153193 {
154194 return key >= Key . F1 && key <= Key . F24 ;
155195 }
196+
197+ private static List < HotkeyPart > BuildEditingParts ( ModifierKeys modifiers , Key key )
198+ {
199+ var parts = new List < HotkeyPart > ( ) ;
200+
201+ if ( modifiers . HasFlag ( ModifierKeys . Control ) ) parts . Add ( new HotkeyPart ( "Ctrl" , parts . Count == 0 ) ) ;
202+ if ( modifiers . HasFlag ( ModifierKeys . Alt ) ) parts . Add ( new HotkeyPart ( "Alt" , parts . Count == 0 ) ) ;
203+ if ( modifiers . HasFlag ( ModifierKeys . Shift ) ) parts . Add ( new HotkeyPart ( "Shift" , parts . Count == 0 ) ) ;
204+ if ( modifiers . HasFlag ( ModifierKeys . Windows ) ) parts . Add ( new HotkeyPart ( "Win" , parts . Count == 0 ) ) ;
205+
206+ if ( key != Key . None )
207+ {
208+ var text = HotkeyBinding . GetKeyDisplayName ( key ) ;
209+ parts . Add ( new HotkeyPart ( text , parts . Count == 0 ) ) ;
210+ }
211+
212+ if ( parts . Count == 0 )
213+ {
214+ parts . Add ( new HotkeyPart ( "Not Set" , true ) ) ;
215+ }
216+
217+ return parts ;
218+ }
219+
220+ private void TriggerGlow ( )
221+ {
222+ IsGlowActive = true ;
223+ _glowTimer . Stop ( ) ;
224+ _glowTimer . Start ( ) ;
225+ }
156226}
157227
158228public class HotkeyChangedEventArgs : EventArgs
0 commit comments