Skip to content

Commit ffb411b

Browse files
committed
Synced with latest from remote master. Merge branch 'rubberduck-vba/next' into next
2 parents 70a7054 + 75be978 commit ffb411b

File tree

125 files changed

+1716
-1698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1716
-1698
lines changed

RetailCoder.VBE/App.cs

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
using System.Windows.Forms;
1616
using Rubberduck.UI.Command;
1717
using Rubberduck.UI.Command.MenuItems.CommandBars;
18+
using Rubberduck.VBEditor.SafeComWrappers;
1819
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
20+
using Rubberduck.VBEditor.SafeComWrappers.MSForms;
21+
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
1922
using Rubberduck.VersionCheck;
2023

2124
namespace Rubberduck
@@ -88,26 +91,76 @@ private void _hooks_MessageReceived(object sender, HookEventArgs e)
8891

8992
private void RefreshSelection()
9093
{
94+
95+
var caption = String.Empty;
96+
var refCount = 0;
97+
98+
WindowKind windowKind = _vbe.ActiveWindow.Type;
9199
var pane = _vbe.ActiveCodePane;
100+
var component = _vbe.SelectedVBComponent;
101+
102+
Declaration selectedDeclaration = null;
103+
104+
//TODO - I doubt this is the best way to check if the SelectedVBComponent and the ActiveCodePane are the same component.
105+
if (windowKind == WindowKind.CodeWindow || (!_vbe.SelectedVBComponent.IsWrappingNullReference
106+
&& component.ParentProject.ProjectId == pane.CodeModule.Parent.ParentProject.ProjectId
107+
&& component.Name == pane.CodeModule.Parent.Name))
92108
{
93-
Declaration selectedDeclaration = null;
94-
if (!pane.IsWrappingNullReference)
109+
selectedDeclaration = _parser.State.FindSelectedDeclaration(pane);
110+
refCount = selectedDeclaration == null ? 0 : selectedDeclaration.References.Count();
111+
caption = _stateBar.GetContextSelectionCaption(_vbe.ActiveCodePane, selectedDeclaration);
112+
}
113+
else if (windowKind == WindowKind.Designer)
114+
{
115+
caption = GetComponentControlsCaption(component);
116+
}
117+
else
118+
{
119+
if (_vbe.SelectedVBComponent.IsWrappingNullReference)
95120
{
96-
selectedDeclaration = _parser.State.FindSelectedDeclaration(pane);
97-
var refCount = selectedDeclaration == null ? 0 : selectedDeclaration.References.Count();
98-
var caption = _stateBar.GetContextSelectionCaption(_vbe.ActiveCodePane, selectedDeclaration);
99-
_stateBar.SetContextSelectionCaption(caption, refCount);
121+
//The user might have selected the project node in Project Explorer
122+
//If they've chosen a folder, we'll return the project anyway
123+
caption = !_vbe.ActiveVBProject.IsWrappingNullReference
124+
? _vbe.ActiveVBProject.Name
125+
: null;
100126
}
101-
102-
var currentStatus = _parser.State.Status;
103-
if (ShouldEvaluateCanExecute(selectedDeclaration, currentStatus))
127+
else
104128
{
105-
_appMenus.EvaluateCanExecute(_parser.State);
106-
_stateBar.EvaluateCanExecute(_parser.State);
129+
caption = component.Type == ComponentType.UserForm && component.HasOpenDesigner
130+
? GetComponentControlsCaption(component)
131+
: String.Format("{0}.{1} ({2})", component.ParentProject.Name, component.Name, component.Type);
107132
}
133+
}
134+
135+
_stateBar.SetContextSelectionCaption(caption, refCount);
136+
137+
var currentStatus = _parser.State.Status;
138+
if (ShouldEvaluateCanExecute(selectedDeclaration, currentStatus))
139+
{
140+
_appMenus.EvaluateCanExecute(_parser.State);
141+
_stateBar.EvaluateCanExecute(_parser.State);
142+
}
108143

109-
_lastStatus = currentStatus;
110-
_lastSelectedDeclaration = selectedDeclaration;
144+
_lastStatus = currentStatus;
145+
_lastSelectedDeclaration = selectedDeclaration;
146+
}
147+
148+
private string GetComponentControlsCaption(IVBComponent component)
149+
{
150+
switch (component.SelectedControls.Count)
151+
{
152+
case 0:
153+
//TODO get the real designer for VB6
154+
return String.Format("{0}.{1} ({2})", component.ParentProject.Name, component.Name, "MSForms.UserForm");
155+
break;
156+
case 1:
157+
//TODO return the libraryName.className of the control
158+
IControl control = component.SelectedControls.First();
159+
return String.Format("{0}.{1}.{2} ({3})", component.ParentProject.Name, component.Name, control.Name, control.TypeName());
160+
break;
161+
default:
162+
return String.Format("{0}.{1} ({2})", component.ParentProject.Name, component.Name, RubberduckUI.ContextMultipleControlsSelection);
163+
break;
111164
}
112165
}
113166

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ private IntPtr WindowProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
220220
}
221221
break;
222222
case WM.CLOSE:
223+
case WM.RUBBERDUCK_SINKING:
224+
suppress = true;
223225
Detach();
224226
break;
225227
}

RetailCoder.VBE/Common/WinAPI/RawInput.cs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
using System.Collections.Generic;
44
using System.ComponentModel;
55
using System.Runtime.InteropServices;
6-
using System.Windows.Forms;
6+
using Rubberduck.UI;
77

88
namespace Rubberduck.Common.WinAPI
99
{
10-
public class RawInput : NativeWindow
10+
public class RawInput : SubclassingWindow
1111
{
1212
static readonly Guid DeviceInterfaceHid = new Guid("4D1E55B2-F16F-11CF-88CB-001111000030");
1313
private readonly List<IRawDevice> _devices;
1414
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
15+
private static int _currentId;
1516

16-
public RawInput(IntPtr parentHandle)
17+
public RawInput(IntPtr parentHandle) : base (new IntPtr((int)parentHandle + (_currentId++)), parentHandle)
1718
{
18-
AssignHandle(parentHandle);
1919
_devices = new List<IRawDevice>();
2020
}
2121

@@ -26,56 +26,56 @@ public void AddDevice(IRawDevice device)
2626

2727
public IRawDevice CreateKeyboard()
2828
{
29-
return new RawKeyboard(Handle, true);
29+
return new RawKeyboard(Hwnd, true);
3030
}
3131

3232
public IRawDevice CreateMouse()
3333
{
34-
return new RawMouse(Handle, true);
35-
}
34+
return new RawMouse(Hwnd, true);
35+
}
3636

37-
protected override void WndProc(ref Message message)
37+
public override int SubClassProc(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, IntPtr dwRefData)
3838
{
39-
switch ((WM)message.Msg)
39+
switch ((WM)msg)
4040
{
4141
case WM.INPUT:
42-
{
43-
if (message.LParam == IntPtr.Zero)
44-
{
45-
break;
46-
}
47-
InputData rawBuffer;
48-
var dwSize = 0;
49-
var res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
50-
if (res != 0)
5142
{
52-
var ex = new Win32Exception(Marshal.GetLastWin32Error());
53-
Logger.Error(ex, "Error sizing the rawinput buffer: {0}", ex.Message);
54-
break;
55-
}
43+
if (lParam == IntPtr.Zero)
44+
{
45+
break;
46+
}
47+
InputData rawBuffer;
48+
var dwSize = 0;
49+
var res = User32.GetRawInputData(lParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
50+
if (res != 0)
51+
{
52+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
53+
Logger.Error(ex, "Error sizing the rawinput buffer: {0}", ex.Message);
54+
break;
55+
}
5656

57-
res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, out rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
58-
if (res == -1)
59-
{
60-
var ex = new Win32Exception(Marshal.GetLastWin32Error());
61-
Logger.Error(ex, "Error getting the rawinput buffer: {0}", ex.Message);
62-
break;
63-
}
64-
if (res == dwSize)
65-
{
66-
foreach (var device in _devices)
57+
res = User32.GetRawInputData(lParam, DataCommand.RID_INPUT, out rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
58+
if (res == -1)
6759
{
68-
device.ProcessRawInput(rawBuffer);
60+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
61+
Logger.Error(ex, "Error getting the rawinput buffer: {0}", ex.Message);
62+
break;
63+
}
64+
if (res == dwSize)
65+
{
66+
foreach (var device in _devices)
67+
{
68+
device.ProcessRawInput(rawBuffer);
69+
}
70+
}
71+
else
72+
{
73+
//Something is seriously f'd up with Windows - the number of bytes copied does not match the reported buffer size.
6974
}
7075
}
71-
else
72-
{
73-
//Something is seriously f'd up with Windows - the number of bytes copied does not match the reported buffer size.
74-
}
75-
}
76-
break;
76+
break;
7777
}
78-
base.WndProc(ref message);
78+
return base.SubClassProc(hWnd, msg, wParam, lParam, uIdSubclass, dwRefData);
7979
}
8080
}
8181
}

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
using Rubberduck.UI.CodeExplorer.Commands;
3434
using Rubberduck.UI.Command.MenuItems.CommandBars;
3535
using Rubberduck.VBEditor.Application;
36-
using Rubberduck.VBEditor.Events;
3736
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
3837
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
3938
using ReparseCommandMenuItem = Rubberduck.UI.Command.MenuItems.CommandBars.ReparseCommandMenuItem;
@@ -62,7 +61,6 @@ public override void Load()
6261
// bind VBE and AddIn dependencies to host-provided instances.
6362
Bind<IVBE>().ToConstant(_vbe);
6463
Bind<IAddIn>().ToConstant(_addin);
65-
Bind<Sinks>().ToSelf().InSingletonScope();
6664
Bind<App>().ToSelf().InSingletonScope();
6765
Bind<RubberduckParserState>().ToSelf().InSingletonScope();
6866
Bind<ISourceControlProvider>().To<GitProvider>();
@@ -87,7 +85,6 @@ public override void Load()
8785

8886
BindCommandsToMenuItems();
8987

90-
Rebind<ISinks>().To<Sinks>().InSingletonScope();
9188
Rebind<IIndenter>().To<Indenter>().InSingletonScope();
9289
Rebind<IIndenterSettings>().To<IndenterSettings>();
9390
Bind<Func<IIndenterSettings>>().ToMethod(t => () => KernelInstance.Get<IGeneralConfigService>().LoadConfiguration().UserSettings.IndenterSettings);

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@
500500
<Compile Include="UI\CodeExplorer\Commands\AddClassModuleCommand.cs" />
501501
<Compile Include="UI\CodeExplorer\Commands\AddStdModuleCommand.cs" />
502502
<Compile Include="UI\CodeExplorer\Commands\AddTestModuleCommand.cs" />
503+
<Compile Include="UI\SubclassingWindow.cs" />
503504
<Compile Include="VersionCheck\IVersionCheck.cs" />
504505
<Compile Include="UI\Command\MenuItems\CommandBars\AppCommandBarBase.cs" />
505506
<Compile Include="UI\Command\MenuItems\CommandBars\ContextSelectionLabelMenuItem.cs" />

RetailCoder.VBE/UI/Command/ReparseCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ protected override bool CanExecuteImpl(object parameter)
3333
protected override void ExecuteImpl(object parameter)
3434
{
3535
_state.OnParseRequested(this);
36-
_state.StartEventSinks(); // no-op if already started
3736
}
3837
}
3938
}

RetailCoder.VBE/UI/DockableToolwindowPresenter.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Configuration;
32
using System.Runtime.InteropServices;
43
using System.Windows.Forms;
54
using NLog;
@@ -59,17 +58,13 @@ private IWindow CreateToolWindow(IDockableUserControl control)
5958
}
6059
catch (COMException exception)
6160
{
62-
//var logEvent = new LogEventInfo(LogLevel.Error, Logger.Name, "Error Creating Control");
63-
//logEvent.Exception = exception;
64-
//logEvent.Properties.Add("EventID", 1);
65-
6661
Logger.Error(exception);
67-
return null; //throw;
62+
throw;
6863
}
6964
catch (NullReferenceException exception)
7065
{
7166
Logger.Error(exception);
72-
return null; //throw;
67+
throw;
7368
}
7469

7570
var userControlHost = (_DockableWindowHost)_userControlObject;
@@ -135,6 +130,16 @@ protected virtual void Dispose(bool disposing)
135130
}
136131
if (disposing && _window != null)
137132
{
133+
if (_userControlObject != null)
134+
{
135+
((_DockableWindowHost)_userControlObject).Dispose();
136+
}
137+
_userControlObject = null;
138+
139+
if (_userControl != null)
140+
{
141+
_userControl.Dispose();
142+
}
138143
// cleanup unmanaged resource wrappers
139144
_window.Close();
140145
_window.Release(true);
@@ -143,18 +148,6 @@ protected virtual void Dispose(bool disposing)
143148
{
144149
return;
145150
}
146-
147-
if (_userControlObject != null)
148-
{
149-
((_DockableWindowHost)_userControlObject).Dispose();
150-
}
151-
_userControlObject = null;
152-
153-
if (_userControl != null)
154-
{
155-
_userControl.Dispose();
156-
}
157-
158151
_disposed = true;
159152
}
160153
}

0 commit comments

Comments
 (0)