Skip to content

Commit

Permalink
Merge pull request rubberduck-vba#964 from ThunderFrame/next
Browse files Browse the repository at this point in the history
Adds CorelDRAW
  • Loading branch information
Hosch250 committed Feb 8, 2016
2 parents 8ba01d0 + dec0325 commit efebe3c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 9 deletions.
2 changes: 0 additions & 2 deletions RetailCoder.VBE/UnitTesting/ProjectTestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static void RunMethodsWithAttribute<TAttribute>(this VBComponent componen

public static IEnumerable<TestMethod> TestMethods(this VBProject project)
{
var hostApp = project.VBE.HostApplication();

var result = project.VBComponents
.Cast<VBComponent>()
Expand All @@ -50,7 +49,6 @@ public static IEnumerable<TestMethod> TestMethods(this VBProject project)

public static IEnumerable<TestMethod> TestMethods(this VBComponent component)
{
var hostApp = component.VBE.HostApplication();

if (component.Type == vbext_ComponentType.vbext_ct_StdModule
&& component.CodeModule.HasAttribute<TestModuleAttribute>())
Expand Down
1 change: 1 addition & 0 deletions Rubberduck.Parsing/VBA/RubberduckParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void ParseParallel()
try
{
var components = _vbe.VBProjects.Cast<VBProject>()
.Where(project => project.Protection == vbext_ProjectProtection.vbext_pp_none)
.SelectMany(project => project.VBComponents.Cast<VBComponent>())
.ToList();

Expand Down
6 changes: 4 additions & 2 deletions Rubberduck.VBEEditor/Extensions/VbeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public static IHostApplication HostApplication(this VBE vbe)
switch (reference.Name)
{
case "Excel":
return new ExcelApp();
return new ExcelApp(vbe);
case "Access":
return new AccessApp();
case "Word":
return new WordApp();
return new WordApp(vbe);
case "PowerPoint":
return new PowerPointApp();
case "Outlook":
Expand All @@ -75,6 +75,8 @@ public static IHostApplication HostApplication(this VBE vbe)
return new PublisherApp();
case "AutoCAD":
return new AutoCADApp();
case "CorelDRAW":
return new CorelDRAWApp(vbe);
}
}

Expand Down
11 changes: 8 additions & 3 deletions Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@
<HintPath>..\libs\Microsoft.Office.Interop.Publisher.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Autodesk.AutoCAD.Interop">
<Reference Include="Autodesk.AutoCAD.Interop">
<HintPath>..\libs\Autodesk.AutoCAD.Interop.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Autodesk.AutoCAD.Interop.Common">
<Reference Include="Autodesk.AutoCAD.Interop.Common">
<HintPath>..\libs\Autodesk.AutoCAD.Interop.Common.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Corel.GraphicsSuite.Interop.CorelDRAW">
<HintPath>..\libs\Corel.GraphicsSuite.Interop.CorelDRAW.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>True</EmbedInteropTypes>
Expand Down Expand Up @@ -95,14 +99,15 @@
<Compile Include="Extensions\VBComponentsExtensions.cs" />
<Compile Include="Extensions\VbeExtensions.cs" />
<Compile Include="VBEHost\AccessApp.cs" />
<Compile Include="VBEHost\CorelDRAWApp.cs" />
<Compile Include="VBEHost\ExcelApp.cs" />
<Compile Include="VBEHost\HostApplicationBase.cs" />
<Compile Include="VBEHost\IHostApplication.cs" />
<Compile Include="VBEHost\OutlookApp.cs" />
<Compile Include="VBEHost\PowerPointApp.cs" />
<Compile Include="VBEHost\PublisherApp.cs" />
<Compile Include="VBEHost\WordApp.cs" />
<Compile Include="VBEHost\AutoCADApp.cs" />
<Compile Include="VBEHost\AutoCADApp.cs" />
<Compile Include="Extensions\VbProjectExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Extensions\WindowExtensions.cs" />
Expand Down
28 changes: 28 additions & 0 deletions Rubberduck.VBEEditor/VBEHost/CorelDRAWApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Corel.GraphicsSuite.Interop.CorelDRAW;
using Microsoft.Vbe.Interop;

namespace Rubberduck.VBEditor.VBEHost
{
public class CorelDRAWApp : HostApplicationBase<Corel.GraphicsSuite.Interop.CorelDRAW.Application>
{
public CorelDRAWApp() : base("CorelDRAW") { }
public CorelDRAWApp(VBE vbe) : base(vbe, "CorelDRAW") { }

//Function RunMacro(ModuleName As String, MacroName As String, Parameter() As Variant) As Variant
//Where ModuleName appears to mean ProjectName, and MacroName has to be provided as "ModuleName.ProcName"

//TODO:RunMacro can only execute methods in stand-alone projects (not document hosted projects)
//TODO:Can only get a CorelDraw application if at least one document is open in CorelDraw.

public override void Run(QualifiedMemberName qualifiedMemberName)
{
var projectName = qualifiedMemberName.QualifiedModuleName.ProjectName;
var memberName = qualifiedMemberName.QualifiedModuleName.ComponentName + "." + qualifiedMemberName.MemberName;

if (Application != null)
{
Application.GMSManager.RunMacro(projectName, memberName, new object[] {});
}
}
}
}
4 changes: 3 additions & 1 deletion Rubberduck.VBEEditor/VBEHost/ExcelApp.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Reflection;
using Microsoft.Office.Interop.Excel;
using Microsoft.Vbe.Interop;

namespace Rubberduck.VBEditor.VBEHost
{
public class ExcelApp : HostApplicationBase<Application>
public class ExcelApp : HostApplicationBase<Microsoft.Office.Interop.Excel.Application>
{
public ExcelApp() : base("Excel") { }
public ExcelApp(VBE vbe) : base(vbe, "Excel") { }

public override void Run(QualifiedMemberName qualifiedMemberName)
{
Expand Down
32 changes: 32 additions & 0 deletions Rubberduck.VBEEditor/VBEHost/HostApplicationBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Vbe.Interop;
using System.Linq;

namespace Rubberduck.VBEditor.VBEHost
{
Expand All @@ -24,6 +26,36 @@ protected HostApplicationBase(string applicationName)
}
}

protected HostApplicationBase(VBE vbe, string applicationName)
{
_applicationName = applicationName;

try
{
var appProperty = vbe.VBProjects
.Cast<VBProject>()
.Where(project => project.Protection == vbext_ProjectProtection.vbext_pp_none)
.SelectMany(project => project.VBComponents.Cast<VBComponent>())
.Where(component => component.Type == vbext_ComponentType.vbext_ct_Document
&& component.Properties.Count > 1)
.SelectMany(component => component.Properties.OfType<Property>())
.FirstOrDefault(property => property.Name == "Application");
if (appProperty != null)
{
Application = (TApplication)appProperty.Object;
}
else
{
Application = (TApplication)Marshal.GetActiveObject(applicationName + ".Application");
}

}
catch (COMException)
{
Application = null; // unit tests don't need it anyway.
}
}

~HostApplicationBase()
{
Dispose(false);
Expand Down
4 changes: 3 additions & 1 deletion Rubberduck.VBEEditor/VBEHost/WordApp.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.Office.Interop.Word;
using Microsoft.Vbe.Interop;

namespace Rubberduck.VBEditor.VBEHost
{
public class WordApp : HostApplicationBase<Application>
public class WordApp : HostApplicationBase<Microsoft.Office.Interop.Word.Application>
{
public WordApp() : base("Word") { }
public WordApp(VBE vbe) : base(vbe, "Word") { }

public override void Run(QualifiedMemberName qualifiedMemberName)
{
Expand Down
1 change: 1 addition & 0 deletions Rubberduck.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
appveyor.yml = appveyor.yml
libs\Autodesk.AutoCAD.Interop.Common.dll = libs\Autodesk.AutoCAD.Interop.Common.dll
libs\Autodesk.AutoCAD.Interop.dll = libs\Autodesk.AutoCAD.Interop.dll
libs\Corel.GraphicsSuite.Interop.CorelDRAW.dll = libs\Corel.GraphicsSuite.Interop.CorelDRAW.dll
libs\Interop.VisioViewer.dll = libs\Interop.VisioViewer.dll
libs\Microsoft.Office.Interop.Access.dll = libs\Microsoft.Office.Interop.Access.dll
libs\Microsoft.Office.Interop.Excel.dll = libs\Microsoft.Office.Interop.Excel.dll
Expand Down
Binary file added libs/Corel.GraphicsSuite.Interop.CorelDRAW.dll
Binary file not shown.

0 comments on commit efebe3c

Please sign in to comment.