Skip to content

Commit

Permalink
Merge branch 'next' into Issue541
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosch250 committed Jul 14, 2016
2 parents 6039b16 + 5b9bfd5 commit bce3a7c
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions RetailCoder.VBE/Common/RubberduckHooks.cs
Expand Up @@ -5,28 +5,21 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Input;
using Microsoft.Vbe.Interop;
using Rubberduck.Common.Hotkeys;
using Rubberduck.Common.WinAPI;
using Rubberduck.Settings;
using Rubberduck.UI.Command;
using Rubberduck.UI.Command.Refactorings;
using NLog;
using Rubberduck.UI;

namespace Rubberduck.Common
{
public class RubberduckHooks : IRubberduckHooks
{
private readonly VBE _vbe;
private readonly IntPtr _mainWindowHandle;
private readonly IntPtr _oldWndPointer;
private readonly User32.WndProc _oldWndProc;
private User32.WndProc _newWndProc;
private RawInput _rawinput;
private IRawDevice _kb;
private IRawDevice _mouse;
private readonly IGeneralConfigService _config;
private readonly IEnumerable<CommandBase> _commands;
private readonly IList<IAttachable> _hooks = new List<IAttachable>();
Expand All @@ -37,9 +30,8 @@ public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<Comman
_vbe = vbe;
_mainWindowHandle = (IntPtr)vbe.MainWindow.HWnd;
_oldWndProc = WindowProc;
_newWndProc = WindowProc;
_oldWndPointer = User32.SetWindowLong(_mainWindowHandle, (int)WindowLongFlags.GWL_WNDPROC, _newWndProc);
_oldWndProc = (User32.WndProc)Marshal.GetDelegateForFunctionPointer(_oldWndPointer, typeof(User32.WndProc));
var oldWndPointer = User32.SetWindowLong(_mainWindowHandle, (int)WindowLongFlags.GWL_WNDPROC, WindowProc);
_oldWndProc = (User32.WndProc)Marshal.GetDelegateForFunctionPointer(oldWndPointer, typeof(User32.WndProc));

_commands = commands;
_config = config;
Expand All @@ -63,12 +55,10 @@ public void HookHotkeys()
var kb = (RawKeyboard)_rawinput.CreateKeyboard();
_rawinput.AddDevice(kb);
kb.RawKeyInputReceived += Keyboard_RawKeyboardInputReceived;
_kb = kb;

var mouse = (RawMouse)_rawinput.CreateMouse();
_rawinput.AddDevice(mouse);
mouse.RawMouseInputReceived += Mouse_RawMouseInputReceived;
_mouse = mouse;

foreach (var hotkey in settings.Settings.Where(hotkey => hotkey.IsEnabled))
{
Expand Down Expand Up @@ -175,7 +165,7 @@ public void Detach()
private void hook_MessageReceived(object sender, HookEventArgs e)
{
var hotkey = sender as IHotkey;
if (hotkey != null)
if (hotkey != null && hotkey.Command.CanExecute(null))
{
hotkey.Command.Execute(null);
return;
Expand Down

0 comments on commit bce3a7c

Please sign in to comment.