Skip to content

Commit 9258158

Browse files
committed
Merge branch 'cacheBugs' of https://github.com/Hosch250/Rubberduck
2 parents 0bef34a + 0f81ef7 commit 9258158

File tree

11 files changed

+112
-47
lines changed

11 files changed

+112
-47
lines changed

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ public void Detach()
173173

174174
private void hook_MessageReceived(object sender, HookEventArgs e)
175175
{
176-
var active = User32.GetForegroundWindow();
177-
if (active != _mainWindowHandle)
178-
{
179-
return;
180-
}
181-
182176
var hotkey = sender as IHotkey;
183177
if (hotkey != null)
184178
{
@@ -207,6 +201,16 @@ private IntPtr WindowProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
207201
case WM.SETFOCUS:
208202
Attach();
209203
break;
204+
case WM.RUBBERDUCK_CHILD_FOCUS:
205+
if (lParam == IntPtr.Zero)
206+
{
207+
Detach();
208+
}
209+
else
210+
{
211+
Attach();
212+
}
213+
return IntPtr.Zero;
210214
case WM.NCACTIVATE:
211215
if (wParam == IntPtr.Zero)
212216
{
@@ -235,14 +239,11 @@ private bool HandleHotkeyMessage(IntPtr wParam)
235239
var processed = false;
236240
try
237241
{
238-
if (User32.IsVbeWindowActive(_mainWindowHandle))
242+
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
243+
if (hook != null)
239244
{
240-
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
241-
if (hook != null)
242-
{
243-
hook.OnMessageReceived();
244-
processed = true;
245-
}
245+
hook.OnMessageReceived();
246+
processed = true;
246247
}
247248
}
248249
catch (Exception exception)

RetailCoder.VBE/Common/WinAPI/User32.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public static class User32
180180
[DllImport("user32.dll", SetLastError = true)]
181181
internal static extern bool UnregisterDeviceNotification(IntPtr handle);
182182

183+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
184+
internal static extern IntPtr SendMessage(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
185+
183186
/// <summary>
184187
/// A helper function that returns <c>true</c> when the specified handle is that of the foreground window.
185188
/// </summary>

RetailCoder.VBE/Common/WinAPI/WM.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,11 @@ public enum WM : uint
922922
/// </summary>
923923
SYSTIMER = 0x118,
924924

925+
/// <summary>
926+
/// Private message to signal focus set/lost for a DockableWindowHost. Set wParam to the DockableWindowHost hWnd, lParam to zero for lost focus, non-zero for gained focus.
927+
/// </summary>
928+
RUBBERDUCK_CHILD_FOCUS = USER + 0x0F00,
929+
925930
/// <summary>
926931
/// The accessibility state has changed.
927932
/// </summary>

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,27 @@ public string PanelTitle
177177
return string.Empty;
178178
}
179179

180-
if (SelectedItem is CodeExplorerProjectViewModel)
180+
if (!(SelectedItem is ICodeExplorerDeclarationViewModel))
181181
{
182-
var node = (CodeExplorerProjectViewModel)SelectedItem;
183-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
182+
return SelectedItem.Name;
184183
}
185184

186-
if (SelectedItem is CodeExplorerComponentViewModel)
187-
{
188-
var node = (CodeExplorerComponentViewModel)SelectedItem;
189-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
190-
}
185+
var declaration = SelectedItem.GetSelectedDeclaration();
186+
187+
var nameWithDeclarationType = declaration.IdentifierName +
188+
string.Format(" - ({0})", RubberduckUI.ResourceManager.GetString(
189+
"DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture));
191190

192-
if (SelectedItem is CodeExplorerMemberViewModel)
191+
if (string.IsNullOrEmpty(declaration.AsTypeName))
193192
{
194-
var node = (CodeExplorerMemberViewModel)SelectedItem;
195-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
193+
return nameWithDeclarationType;
196194
}
197195

198-
return SelectedItem.Name;
196+
var typeName = declaration.HasTypeHint
197+
? Declaration.TypeHintToTypeName[declaration.TypeHint]
198+
: declaration.AsTypeName;
199+
200+
return nameWithDeclarationType + ": " + typeName;
199201
}
200202
}
201203

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@
741741

742742
<Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="DimGray">
743743

744-
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
745-
<StackPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
744+
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto">
745+
<WrapPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
746746

747747
<Grid Margin="4" HorizontalAlignment="Stretch">
748748
<Grid.ColumnDefinitions>
@@ -777,7 +777,7 @@
777777
CommandParameter="{Binding SelectedItem}"
778778
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_FindAllReferencesText}" />
779779
</WrapPanel>
780-
</StackPanel>
780+
</WrapPanel>
781781
</ScrollViewer>
782782
</Border>
783783
</Grid>

RetailCoder.VBE/UI/Command/AddTestMethodCommand.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
37+
try
38+
{
39+
// the code modules consistently match correctly, but the components don't
40+
return testModules.Any(a =>
41+
a.QualifiedName.QualifiedModuleName.Component.CodeModule ==
42+
_vbe.SelectedVBComponent.CodeModule);
43+
}
44+
catch (COMException)
45+
{
46+
return false;
47+
}
3848
}
3949

4050
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UI/Command/AddTestMethodExpectedErrorCommand.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ protected override bool CanExecuteImpl(object parameter)
3434
d.DeclarationType == DeclarationType.ProceduralModule &&
3535
d.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule));
3636

37-
return testModules.Any(a => a.QualifiedName.QualifiedModuleName.Component == _vbe.SelectedVBComponent);
37+
try
38+
{
39+
// the code modules consistently match correctly, but the components don't
40+
return testModules.Any(a =>
41+
a.QualifiedName.QualifiedModuleName.Component.CodeModule ==
42+
_vbe.SelectedVBComponent.CodeModule);
43+
}
44+
catch (COMException)
45+
{
46+
return false;
47+
}
3848
}
3949

4050
protected override void ExecuteImpl(object parameter)

RetailCoder.VBE/UI/Command/MenuItems/RubberduckCommandBar.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void SetSelectionText(Declaration declaration)
5151
if (selection.HasValue) { SetSelectionText(selection.Value); }
5252
_selectionButton.TooltipText = _selectionButton.Caption;
5353
}
54-
else if (declaration != null)
54+
else if (declaration != null && !declaration.IsBuiltIn && declaration.DeclarationType != DeclarationType.ClassModule && declaration.DeclarationType != DeclarationType.ProceduralModule)
5555
{
5656
var typeName = declaration.HasTypeHint
5757
? Declaration.TypeHintToTypeName[declaration.TypeHint]
@@ -63,6 +63,28 @@ public void SetSelectionText(Declaration declaration)
6363
declaration.IdentifierName,
6464
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture),
6565
string.IsNullOrEmpty(declaration.AsTypeName) ? string.Empty : ": " + typeName);
66+
67+
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
68+
? _selectionButton.Caption
69+
: declaration.DescriptionString;
70+
}
71+
else if (declaration != null)
72+
{
73+
// todo: confirm this is what we want, and then refator
74+
var selection = _vbe.ActiveCodePane.GetQualifiedSelection();
75+
if (selection.HasValue)
76+
{
77+
var typeName = declaration.HasTypeHint
78+
? Declaration.TypeHintToTypeName[declaration.TypeHint]
79+
: declaration.AsTypeName;
80+
81+
_selectionButton.Caption = string.Format("{0}|{1}: {2} ({3}{4})",
82+
selection.Value.Selection,
83+
declaration.QualifiedName.QualifiedModuleName,
84+
declaration.IdentifierName,
85+
RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture),
86+
string.IsNullOrEmpty(declaration.AsTypeName) ? string.Empty : ": " + typeName);
87+
}
6688
_selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString)
6789
? _selectionButton.Caption
6890
: declaration.DescriptionString;

RetailCoder.VBE/UI/DockableToolwindowPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private Window CreateToolWindow(IDockableUserControl control)
6262

6363
toolWindow.Visible = false; //hide it again
6464

65-
userControlHost.AddUserControl(control as UserControl);
65+
userControlHost.AddUserControl(control as UserControl, new IntPtr(_vbe.MainWindow.HWnd));
6666
return toolWindow;
6767
}
6868

RetailCoder.VBE/UI/DockableWindowHost.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Drawing;
55
using System.Runtime.InteropServices;
66
using System.Windows.Forms;
7+
using Rubberduck.Common.WinAPI;
78
using Rubberduck.VBEditor;
89

910
namespace Rubberduck.UI
@@ -40,10 +41,10 @@ private struct Rect
4041
private IntPtr _parentHandle;
4142
private SubClassingWindow _subClassingWindow;
4243

43-
internal void AddUserControl(UserControl control)
44+
internal void AddUserControl(UserControl control, IntPtr vbeHwnd)
4445
{
4546
_parentHandle = GetParent(Handle);
46-
_subClassingWindow = new SubClassingWindow(_parentHandle);
47+
_subClassingWindow = new SubClassingWindow(_parentHandle, vbeHwnd);
4748
_subClassingWindow.CallBackEvent += OnCallBackEvent;
4849

4950
if (control != null)
@@ -116,27 +117,35 @@ public class SubClassingWindow : NativeWindow
116117
public event SubClassingWindowEventHandler CallBackEvent;
117118
public delegate void SubClassingWindowEventHandler(object sender, SubClassingWindowEventArgs e);
118119

120+
private readonly IntPtr _vbeHwnd;
121+
119122
private void OnCallBackEvent(SubClassingWindowEventArgs e)
120123
{
121124
Debug.Assert(CallBackEvent != null, "CallBackEvent != null");
122125
CallBackEvent(this, e);
123126
}
124127

125-
public SubClassingWindow(IntPtr handle)
128+
public SubClassingWindow(IntPtr handle, IntPtr vbeHwnd)
126129
{
130+
_vbeHwnd = vbeHwnd;
127131
AssignHandle(handle);
128132
}
129133

130134
protected override void WndProc(ref Message msg)
131135
{
132-
const int wmSize = 0x5;
133-
134-
if (msg.Msg == wmSize)
136+
switch ((uint)msg.Msg)
135137
{
136-
var args = new SubClassingWindowEventArgs(msg);
137-
OnCallBackEvent(args);
138+
case (uint)WM.SIZE:
139+
var args = new SubClassingWindowEventArgs(msg);
140+
OnCallBackEvent(args);
141+
break;
142+
case (uint)WM.SETFOCUS:
143+
User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Handle, Handle);
144+
break;
145+
case (uint)WM.KILLFOCUS:
146+
User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Handle, IntPtr.Zero);
147+
break;
138148
}
139-
140149
base.WndProc(ref msg);
141150
}
142151

0 commit comments

Comments
 (0)