55using System . Linq ;
66using System . Runtime . InteropServices ;
77using System . Windows . Forms ;
8- using System . Windows . Input ;
98using Microsoft . Vbe . Interop ;
109using Rubberduck . Common . Hotkeys ;
1110using Rubberduck . Common . WinAPI ;
1211using Rubberduck . Settings ;
1312using Rubberduck . UI . Command ;
14- using Rubberduck . UI . Command . Refactorings ;
1513using NLog ;
16- using Rubberduck . UI ;
1714
1815namespace Rubberduck . Common
1916{
2017 public class RubberduckHooks : IRubberduckHooks
2118 {
2219 private readonly VBE _vbe ;
2320 private readonly IntPtr _mainWindowHandle ;
24- private readonly IntPtr _oldWndPointer ;
2521 private readonly User32 . WndProc _oldWndProc ;
26- private User32 . WndProc _newWndProc ;
2722 private RawInput _rawinput ;
28- private IRawDevice _kb ;
29- private IRawDevice _mouse ;
3023 private readonly IGeneralConfigService _config ;
3124 private readonly IEnumerable < CommandBase > _commands ;
3225 private readonly IList < IAttachable > _hooks = new List < IAttachable > ( ) ;
@@ -37,9 +30,8 @@ public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<Comman
3730 _vbe = vbe ;
3831 _mainWindowHandle = ( IntPtr ) vbe . MainWindow . HWnd ;
3932 _oldWndProc = WindowProc ;
40- _newWndProc = WindowProc ;
41- _oldWndPointer = User32 . SetWindowLong ( _mainWindowHandle , ( int ) WindowLongFlags . GWL_WNDPROC , _newWndProc ) ;
42- _oldWndProc = ( User32 . WndProc ) Marshal . GetDelegateForFunctionPointer ( _oldWndPointer , typeof ( User32 . WndProc ) ) ;
33+ var oldWndPointer = User32 . SetWindowLong ( _mainWindowHandle , ( int ) WindowLongFlags . GWL_WNDPROC , WindowProc ) ;
34+ _oldWndProc = ( User32 . WndProc ) Marshal . GetDelegateForFunctionPointer ( oldWndPointer , typeof ( User32 . WndProc ) ) ;
4335
4436 _commands = commands ;
4537 _config = config ;
@@ -63,12 +55,10 @@ public void HookHotkeys()
6355 var kb = ( RawKeyboard ) _rawinput . CreateKeyboard ( ) ;
6456 _rawinput . AddDevice ( kb ) ;
6557 kb . RawKeyInputReceived += Keyboard_RawKeyboardInputReceived ;
66- _kb = kb ;
6758
6859 var mouse = ( RawMouse ) _rawinput . CreateMouse ( ) ;
6960 _rawinput . AddDevice ( mouse ) ;
7061 mouse . RawMouseInputReceived += Mouse_RawMouseInputReceived ;
71- _mouse = mouse ;
7262
7363 foreach ( var hotkey in settings . Settings . Where ( hotkey => hotkey . IsEnabled ) )
7464 {
@@ -175,7 +165,7 @@ public void Detach()
175165 private void hook_MessageReceived ( object sender , HookEventArgs e )
176166 {
177167 var hotkey = sender as IHotkey ;
178- if ( hotkey != null )
168+ if ( hotkey != null && hotkey . Command . CanExecute ( null ) )
179169 {
180170 hotkey . Command . Execute ( null ) ;
181171 return ;
0 commit comments