Skip to content

Commit ccaa7f5

Browse files
author
Andrew Mansell
committed
Changes per PR comments
1 parent 8e27089 commit ccaa7f5

File tree

6 files changed

+68
-344
lines changed

6 files changed

+68
-344
lines changed

Rubberduck.VBEEditor/Events/VBENativeServices.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public static void VbeEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr
8888
if (idObject != (int)ObjId.Cursor)
8989
{
9090
var windowClassName = hwnd.ToClassName();
91-
if (!WinEventMap.Lookup.TryGetValue(eventType, out var eventName))
91+
if (!WinEventMap.Lookup.TryGetValue((int)eventType, out var eventName))
9292
{
9393
eventName = "Unknown";
9494
}
95-
Debug.WriteLine("EVT: {0:X4} ({1}) Hwnd {2:X4} ({3}), idObject {4}, idChild {5}", eventType, eventName, (int)hwnd, windowClassName, idObject, idChild);
95+
Debug.WriteLine($"EVT: 0x{eventType:X4} ({eventName}) Hwnd 0x{(int)hwnd:X4} ({windowClassName}), idObject {idObject}, idChild {idChild}");
9696
}
9797
#endif
9898

Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<Compile Include="SafeComWrappers\SafeRedirectedEventedComWrapper.cs" />
9999
<Compile Include="SafeComWrappers\VB\Abstract\IHostApplication.cs" />
100100
<Compile Include="SafeComWrappers\VB\Enums\VBEKind.cs" />
101+
<Compile Include="Utility\EnumHelper.cs" />
101102
<Compile Include="Utility\UiContext.cs" />
102103
<Compile Include="VBERuntime\IVBERuntime.cs" />
103104
<Compile Include="VBERuntime\Settings\IVBESettings.cs" />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
6+
namespace Rubberduck.VBEditor.Utility
7+
{
8+
public static class EnumHelper
9+
{
10+
public static Dictionary<TUnderlying, string> ToDictionary<TEnum, TUnderlying>()
11+
{
12+
var enumType = typeof(TEnum);
13+
var underlyingType = typeof(TUnderlying);
14+
15+
Debug.Assert(enumType.IsEnum, $"Type '{enumType.Name}' is not an enum");
16+
17+
Debug.Assert(Enum.GetUnderlyingType(enumType) == underlyingType,
18+
$"Type parameter '{underlyingType}' does not match underlying type for enum '{enumType.Name}' ('{Enum.GetUnderlyingType(enumType).Name}')");
19+
20+
var dictionary = new Dictionary<TUnderlying, string>();
21+
22+
foreach (var fieldInfo in enumType.GetFields().Where(fi => fi.FieldType.IsEnum))
23+
{
24+
if (fieldInfo.GetCustomAttributes(typeof(ReflectionIgnoreAttribute), false).Any())
25+
{
26+
continue;
27+
}
28+
29+
var key = (TUnderlying) fieldInfo.GetRawConstantValue();
30+
31+
dictionary[key] = dictionary.ContainsKey(key)
32+
? $"{dictionary[key]} / {fieldInfo.Name}"
33+
: fieldInfo.Name;
34+
}
35+
36+
return dictionary;
37+
}
38+
}
39+
40+
public class ReflectionIgnoreAttribute : Attribute
41+
{
42+
}
43+
}

Rubberduck.VBEEditor/WindowsApi/SubclassingWindow.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ public virtual int SubClassProc(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr l
8989
#if (DEBUG && (THIRSTY_DUCK || THIRSTY_DUCK_WM))
9090
//This is an output window firehose kind of like spy++. Prepare for some spam.
9191
var windowClassName = ToClassName(hWnd);
92-
if (!(WM_MAP.Lookup.TryGetValue((uint) msg, out var wmName)))
92+
if (WM_MAP.Lookup.TryGetValue((uint) msg, out var wmName))
93+
{
94+
wmName = $"WM_{wmName}";
95+
}
96+
else
9397
{
9498
wmName = "Unknown";
9599
}
96-
Debug.WriteLine("MSG: {0:X4} ({1}), Hwnd {2:X4} ({3}), wParam {4:X4}, lParam {5:X4}", (uint)msg, wmName, (uint)hWnd, windowClassName, (uint)wParam, (uint)lParam);
100+
101+
102+
Debug.WriteLine($"MSG: 0x{(uint)msg:X4} ({wmName}), Hwnd 0x{(uint)hWnd:X4} ({windowClassName}), wParam 0x{(uint)wParam:X4}, lParam 0x{(uint)lParam:X4}");
97103
#endif
98104

99105
if ((uint) msg == (uint) WM.DESTROY)

0 commit comments

Comments
 (0)