Skip to content

Commit a7b1ac4

Browse files
committed
added FallbackApp; commented-out because, well, it blows up the host unfortunately. If anyone gets this to work, they get RD unit tests to work in *any* host.
1 parent d614aa5 commit a7b1ac4

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

Rubberduck.VBEEditor/Extensions/VbeExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static IHostApplication HostApplication(this VBE vbe)
5656
{
5757
const int ctl_view_host = 106;
5858

59-
CommandBarControl host_app_control = vbe.CommandBars.FindControl(MsoControlType.msoControlButton, ctl_view_host);
59+
var host_app_control = vbe.CommandBars.FindControl(MsoControlType.msoControlButton, ctl_view_host);
6060

6161
if (host_app_control == null)
6262
{
@@ -67,7 +67,7 @@ public static IHostApplication HostApplication(this VBE vbe)
6767
switch (host_app_control.Caption)
6868
{
6969
case "Microsoft Excel":
70-
return new ExcelApp();
70+
/*return new FallbackApp(vbe);//*/return new ExcelApp();
7171
case "Microsoft Access":
7272
return new AccessApp();
7373
case "Microsoft Word":
@@ -79,12 +79,12 @@ public static IHostApplication HostApplication(this VBE vbe)
7979
case "Microsoft Publisher":
8080
return new PublisherApp();
8181
case "AutoCAD":
82-
return null; //TODO - Confirm the button caption
82+
return new AutoCADApp();
8383
case "CorelDRAW":
84-
return null;
84+
return new CorelDRAWApp();
8585
}
8686
}
87-
return null;
87+
return null; //new FallbackApp(vbe);
8888
}
8989

9090
foreach (var reference in vbe.ActiveVBProject.References.Cast<Reference>()
@@ -93,7 +93,7 @@ public static IHostApplication HostApplication(this VBE vbe)
9393
switch (reference.Name)
9494
{
9595
case "Excel":
96-
return new ExcelApp(vbe);
96+
/*return new FallbackApp(vbe);//*/return new ExcelApp(vbe);
9797
case "Access":
9898
return new AccessApp();
9999
case "Word":
@@ -111,7 +111,7 @@ public static IHostApplication HostApplication(this VBE vbe)
111111
}
112112
}
113113

114-
return null;
114+
return null; //new FallbackApp(vbe);
115115
}
116116
}
117117
}

Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<Compile Include="VBEHost\AccessApp.cs" />
107107
<Compile Include="VBEHost\CorelDRAWApp.cs" />
108108
<Compile Include="VBEHost\ExcelApp.cs" />
109+
<Compile Include="VBEHost\FallbackApp.cs" />
109110
<Compile Include="VBEHost\HostApplicationBase.cs" />
110111
<Compile Include="VBEHost\IHostApplication.cs" />
111112
<Compile Include="VBEHost\OutlookApp.cs" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Microsoft.Office.Core;
4+
using Microsoft.Vbe.Interop;
5+
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;
6+
7+
namespace Rubberduck.VBEditor.VBEHost
8+
{
9+
public class FallbackApp : IHostApplication
10+
{
11+
private readonly VBE _vbe;
12+
private readonly CommandBarButton _runButton;
13+
14+
private const int DebugCommandBarId = 4;
15+
private const int RunMacroCommand = 5415;
16+
17+
public FallbackApp(VBE vbe)
18+
{
19+
_vbe = vbe;
20+
var mainCommandBar = _vbe.CommandBars[DebugCommandBarId];
21+
_runButton = (CommandBarButton)mainCommandBar.FindControl(Id: RunMacroCommand);
22+
}
23+
24+
public void Run(QualifiedMemberName qualifiedMemberName)
25+
{
26+
27+
var component = qualifiedMemberName.QualifiedModuleName.Component;
28+
var line = component.CodeModule.get_ProcBodyLine(qualifiedMemberName.MemberName, vbext_ProcKind.vbext_pk_Proc);
29+
30+
component.CodeModule.CodePane.SetSelection(line, 1, line, 1);
31+
component.CodeModule.CodePane.ForceFocus();
32+
33+
_runButton.Execute();
34+
}
35+
36+
public TimeSpan TimedMethodCall(QualifiedMemberName qualifiedMemberName)
37+
{
38+
var stopwatch = Stopwatch.StartNew();
39+
40+
Run(qualifiedMemberName);
41+
42+
stopwatch.Stop();
43+
return stopwatch.Elapsed;
44+
}
45+
46+
public string ApplicationName { get { return "(unknown)"; } }
47+
48+
public void Dispose()
49+
{
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)