|
5 | 5 | using Rubberduck.VBEditor.Application;
|
6 | 6 | using Rubberduck.VBEditor.SafeComWrappers.Abstract;
|
7 | 7 | using Rubberduck.VBEditor.SafeComWrappers.MSForms;
|
| 8 | +using Exception = System.Exception; |
8 | 9 |
|
9 | 10 | namespace Rubberduck.VBEditor.Extensions
|
10 | 11 | {
|
11 | 12 | public static class VBEExtensions
|
12 | 13 | {
|
| 14 | + private static readonly Dictionary<string, Type> HostAppMap = new Dictionary<string, Type> |
| 15 | + { |
| 16 | + {"EXCEL.EXE", typeof(ExcelApp)}, |
| 17 | + {"WINWORD.EXE", typeof(WordApp)}, |
| 18 | + {"MSACCESS.EXE", typeof(AccessApp)}, |
| 19 | + {"POWERPNT.EXE", typeof(PowerPointApp)}, |
| 20 | + {"OUTLOOK.EXE", typeof(OutlookApp)}, |
| 21 | + {"WINPROJ.EXE", typeof(ProjectApp)}, |
| 22 | + {"MSPUB.EXE", typeof(PublisherApp)}, |
| 23 | + {"VISIO.EXE", typeof(VisioApp)}, |
| 24 | + {"ACAD.EXE", typeof(AutoCADApp)}, |
| 25 | + {"CORELDRW.EXE", typeof(CorelDRAWApp)}, |
| 26 | + {"SLDWORKS.EXE", typeof(SolidWorksApp)}, |
| 27 | + }; |
| 28 | + |
13 | 29 | /// <summary> Returns the type of Office Application that is hosting the VBE. </summary>
|
14 | 30 | public static IHostApplication HostApplication(this IVBE vbe)
|
15 | 31 | {
|
| 32 | + var host = Path.GetFileName(System.Windows.Forms.Application.ExecutablePath).ToUpperInvariant(); |
| 33 | + //This needs the VBE as a ctor argument. |
| 34 | + if (host.Equals("SLDWORKS.EXE")) |
| 35 | + { |
| 36 | + return new SolidWorksApp(vbe); |
| 37 | + } |
| 38 | + //The rest don't. |
| 39 | + if (HostAppMap.ContainsKey(host)) |
| 40 | + { |
| 41 | + return (IHostApplication)Activator.CreateInstance(HostAppMap[host]); |
| 42 | + } |
| 43 | + |
| 44 | + //Guessing the above will work like 99.9999% of the time for supported applications. |
16 | 45 | var project = vbe.ActiveVBProject;
|
17 | 46 | {
|
18 | 47 | if (project.IsWrappingNullReference)
|
@@ -114,6 +143,10 @@ public static IHostApplication HostApplication(this IVBE vbe)
|
114 | 143 | /// <summary> Returns whether the host supports unit tests.</summary>
|
115 | 144 | public static bool HostSupportsUnitTests(this IVBE vbe)
|
116 | 145 | {
|
| 146 | + var host = Path.GetFileName(System.Windows.Forms.Application.ExecutablePath).ToUpperInvariant(); |
| 147 | + if (HostAppMap.ContainsKey(host)) return true; |
| 148 | + //Guessing the above will work like 99.9999% of the time for supported applications. |
| 149 | + |
117 | 150 | var project = vbe.ActiveVBProject;
|
118 | 151 | {
|
119 | 152 | if (project.IsWrappingNullReference)
|
|
0 commit comments