Skip to content

Commit 37da2d0

Browse files
committed
attempt to make hook failures less fatal
1 parent 31235ed commit 37da2d0

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

RetailCoder.VBE/Common/Hotkeys/Hotkey.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void Detach()
6363
{
6464
if (!IsAttached)
6565
{
66-
throw new InvalidOperationException(Rubberduck.UI.RubberduckUI.CommonHotkey_HookDetached);
66+
return;
6767
}
6868

6969
User32.UnregisterHotKey(_hWndVbe, HotkeyInfo.HookId);
@@ -76,7 +76,7 @@ private void HookKey(Keys key, uint shift)
7676
{
7777
if (IsAttached)
7878
{
79-
throw new InvalidOperationException(Rubberduck.UI.RubberduckUI.CommonHotkey_HookAttached);
79+
return;
8080
}
8181

8282
var hookId = (IntPtr)Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());

RetailCoder.VBE/Common/KeyboardHook.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public void Detach()
112112

113113
if (!User32.UnhookWindowsHookEx(_hookId))
114114
{
115+
IsAttached = false;
116+
_hookId = IntPtr.Zero;
115117
throw new Win32Exception();
116118
}
117119

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public void Detach()
109109
{
110110
foreach (var hook in Hooks)
111111
{
112-
hook.Detach();
113112
hook.MessageReceived -= hook_MessageReceived;
113+
hook.Detach();
114114
}
115115
}
116116
catch (Win32Exception exception)

RetailCoder.VBE/UI/Command/Refactorings/RefactorIntroduceParameterCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override bool CanExecute(object parameter)
3131
var selection = Vbe.ActiveCodePane.GetSelection();
3232
var target = _state.AllUserDeclarations.FindTarget(selection, new []{DeclarationType.Variable, DeclarationType.Constant});
3333

34-
var canExecute = target != null && target.ParentScopeDeclaration.DeclarationType.HasFlag(DeclarationType.Member);
34+
var canExecute = target != null && target.ParentScopeDeclaration != null && target.ParentScopeDeclaration.DeclarationType.HasFlag(DeclarationType.Member);
3535

3636
Debug.WriteLine("{0}.CanExecute evaluates to {1}", GetType().Name, canExecute);
3737
return canExecute;

0 commit comments

Comments
 (0)