Skip to content

Commit 13a483a

Browse files
added VBETypeLibsAPI.GetComponentTypeFlags
refactored ConditionalCompilationArguments dictionary parsing into the lower API
1 parent 86cf344 commit 13a483a

File tree

2 files changed

+114
-22
lines changed

2 files changed

+114
-22
lines changed

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibs.cs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Text;
66
using System.Globalization;
7+
using System.Linq;
78
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
89
using Rubberduck.VBEditor.ComManagement.TypeLibsAbstract;
910
using ComTypes = System.Runtime.InteropServices.ComTypes;
@@ -13,7 +14,14 @@
1314
// TODO comments/XML doc
1415
// TODO a few FIXMEs
1516

17+
// make GetControlType support Access forms etc
18+
// IsAccessForm example
19+
// split into TypeInfos.cs
1620

21+
/*VBETypeLibsAPI::GetModuleFlags(ide, projectName, moduleName) to get the TYPEFLAGS
22+
VBETypeLibsAPI::GetMemberId(ide, projectName, moduleName, memberName)
23+
VBETypeLibsAPI::GetMemberHelpString(ide, projectName, moduleName, memberName)
24+
*/
1725

1826

1927
// USAGE GUIDE: see class VBETypeLibsAPI for demonstrations of usage.
@@ -662,6 +670,7 @@ TypeLibTextFields CachedTextFields
662670
public TYPEKIND_VBE TypeKind { get => (TYPEKIND_VBE)Attributes.typekind; }
663671

664672
public bool HasPredeclaredId { get => Attributes.wTypeFlags.HasFlag(ComTypes.TYPEFLAGS.TYPEFLAG_FPREDECLID); }
673+
public ComTypes.TYPEFLAGS Flags { get => Attributes.wTypeFlags; }
665674

666675
private bool HasNoContainer() => _containerTypeLib == null;
667676

@@ -735,12 +744,11 @@ public object StdModExecute(string name, Reflection.BindingFlags invokeAttr, obj
735744
}
736745
}
737746

738-
// FIXME this needs work
739747
// Gets the control ITypeInfo by looking for the corresponding getter on the form interface and returning its retval type
740748
// Supports UserForms. what about Access forms etc
741749
public TypeInfoWrapper GetControlType(string controlName)
742750
{
743-
// FIXME should encapsulate handling of raw datatypes
751+
// TODO should encapsulate handling of raw datatypes
744752
foreach (var func in Funcs)
745753
{
746754
using (func)
@@ -1142,7 +1150,7 @@ public bool CompileProject()
11421150
}
11431151
}
11441152

1145-
public string ConditionalCompilationArguments
1153+
public string ConditionalCompilationArgumentsRaw
11461154
{
11471155
get
11481156
{
@@ -1169,6 +1177,44 @@ public string ConditionalCompilationArguments
11691177
}
11701178
}
11711179

1180+
public Dictionary<string, string> ConditionalCompilationArguments
1181+
{
1182+
get
1183+
{
1184+
if (HasVBEExtensions)
1185+
{
1186+
string args = target_IVBEProject.GetConditionalCompilationArgs();
1187+
1188+
if (args.Length > 0)
1189+
{
1190+
string[] argsArray = args.Split(new[] { ':' });
1191+
return argsArray.Select(item => item.Split('=')).ToDictionary(s => s[0], s => s[1]);
1192+
}
1193+
else
1194+
{
1195+
return new Dictionary<string, string>();
1196+
}
1197+
}
1198+
else
1199+
{
1200+
throw new ArgumentException("This ITypeLib is not hosted by the VBE, so does not support ConditionalCompilationArguments");
1201+
}
1202+
}
1203+
1204+
set
1205+
{
1206+
if (HasVBEExtensions)
1207+
{
1208+
var rawArgsString = string.Join(" : ", value.Select(x => x.Key + " = " + x.Value));
1209+
ConditionalCompilationArgumentsRaw = rawArgsString;
1210+
}
1211+
else
1212+
{
1213+
throw new ArgumentException("This ITypeLib is not hosted by the VBE, so does not support ConditionalCompilationArguments");
1214+
}
1215+
}
1216+
}
1217+
11721218
public void Document(StringLineBuilder output)
11731219
{
11741220
output.AppendLine();

Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeLibsAPI.cs

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4-
using System.Threading.Tasks;
54
using Rubberduck.VBEditor.ComManagement.TypeLibs;
65
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
76
using Reflection = System.Reflection;
8-
using System.Linq;
7+
using ComTypes = System.Runtime.InteropServices.ComTypes;
98

109
namespace Rubberduck.VBEditor.ComManagement.TypeLibsAPI
1110
{
@@ -258,7 +257,7 @@ public static string GetProjectConditionalCompilationArgsRaw(IVBProject project)
258257
/// <returns>returns the raw unparsed conditional arguments string, e.g. "foo = 1 : bar = 2"</returns>
259258
public static string GetProjectConditionalCompilationArgsRaw(TypeLibWrapper projectTypeLib)
260259
{
261-
return projectTypeLib.ConditionalCompilationArguments;
260+
return projectTypeLib.ConditionalCompilationArgumentsRaw;
262261
}
263262

264263
/// <summary>
@@ -298,18 +297,7 @@ public static Dictionary<string, string> GetProjectConditionalCompilationArgs(IV
298297
/// <returns>returns a Dictionary<string, string>, parsed from the conditional arguments string</returns>
299298
public static Dictionary<string, string> GetProjectConditionalCompilationArgs(TypeLibWrapper projectTypeLib)
300299
{
301-
// FIXME move dictionary stuff into the lower API here
302-
string args = GetProjectConditionalCompilationArgsRaw(projectTypeLib);
303-
304-
if (args.Length > 0)
305-
{
306-
string[] argsArray = args.Split(new[] { ':' });
307-
return argsArray.Select(item => item.Split('=')).ToDictionary(s => s[0], s => s[1]);
308-
}
309-
else
310-
{
311-
return new Dictionary<string, string>();
312-
}
300+
return projectTypeLib.ConditionalCompilationArguments;
313301
}
314302

315303
/// <summary>
@@ -349,7 +337,7 @@ public static void SetProjectConditionalCompilationArgsRaw(IVBProject project, s
349337
/// <param name="newConditionalArgs">Raw string representing the arguments, e.g. "foo = 1 : bar = 2"</param>
350338
public static void SetProjectConditionalCompilationArgsRaw(TypeLibWrapper projectTypeLib, string newConditionalArgs)
351339
{
352-
projectTypeLib.ConditionalCompilationArguments = newConditionalArgs;
340+
projectTypeLib.ConditionalCompilationArgumentsRaw = newConditionalArgs;
353341
}
354342

355343
/// <summary>
@@ -389,9 +377,7 @@ public static void SetProjectConditionalCompilationArgs(IVBProject project, Dict
389377
/// <param name="newConditionalArgs">Dictionary<string, string> representing the argument name-value pairs</param>
390378
public static void SetProjectConditionalCompilationArgs(TypeLibWrapper projectTypeLib, Dictionary<string, string> newConditionalArgs)
391379
{
392-
// FIXME move dictionary stuff into the lower API here
393-
var rawArgsString = string.Join(" : ", newConditionalArgs.Select(x => x.Key + " = " + x.Value));
394-
SetProjectConditionalCompilationArgsRaw(projectTypeLib, rawArgsString);
380+
projectTypeLib.ConditionalCompilationArguments = newConditionalArgs;
395381
}
396382

397383
/// <summary>
@@ -829,6 +815,66 @@ public static string GetUserFormControlType(TypeInfoWrapper userFormTypeInfo, st
829815
return userFormTypeInfo.ImplementedInterfaces.Get("FormItf").GetControlType(controlName).GetProgID();
830816
}
831817

818+
/// <summary>
819+
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
820+
/// </summary>
821+
/// <param name="ide">Safe-com wrapper representing the VBE</param>
822+
/// <param name="projectName">The VBA project name</param>
823+
/// <param name="componentName">The name of the component (module/class etc) to get flags for</param>
824+
/// <returns>bool indicating success/failure.</returns>
825+
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBE ide, string projectName, string componentName)
826+
{
827+
using (var typeLibs = new VBETypeLibsAccessor(ide))
828+
{
829+
return GetComponentTypeFlags(typeLibs.Get(projectName), componentName);
830+
}
831+
}
832+
833+
/// <summary>
834+
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
835+
/// </summary>
836+
/// <param name="project">Safe-com wrapper representing the VBA project</param>
837+
/// <param name="componentName">The name of the component (module/class etc) to get flags for</param>
838+
/// <returns>bool indicating success/failure.</returns>
839+
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBProject project, string componentName)
840+
{
841+
using (var typeLib = TypeLibWrapper.FromVBProject(project))
842+
{
843+
return GetComponentTypeFlags(typeLib, componentName);
844+
}
845+
}
846+
847+
/// <summary>
848+
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
849+
/// </summary>
850+
/// <param name="projectTypeLib">Low-level ITypeLib wrapper representing the VBA project</param>
851+
/// <param name="componentName">The name of the component (module/class etc) to get flags for</param>
852+
/// <returns>bool indicating success/failure.</returns>
853+
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(TypeLibWrapper projectTypeLib, string componentName)
854+
{
855+
return GetComponentTypeFlags(projectTypeLib.TypeInfos.Get(componentName));
856+
}
857+
858+
/// <summary>
859+
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
860+
/// </summary>
861+
/// <param name="component">Safe-com wrapper representing the VBA component to get flags for</param>
862+
/// <returns>bool indicating success/failure.</returns>
863+
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(IVBComponent component)
864+
{
865+
return GetComponentTypeFlags(component.ParentProject, component.Name);
866+
}
867+
868+
/// <summary>
869+
/// Retreives the TYPEFLAGS of a VBA component (e.g. module/class), providing flags like TYPEFLAG_FCANCREATE, TYPEFLAG_FPREDECLID
870+
/// </summary>
871+
/// <param name="componentTypeInfo">Low-level ITypeInfo wrapper representing the VBA component to get flags for</param>
872+
/// <returns>bool indicating success/failure.</returns>
873+
public static ComTypes.TYPEFLAGS GetComponentTypeFlags(TypeInfoWrapper componentTypeInfo)
874+
{
875+
return componentTypeInfo.Flags;
876+
}
877+
832878
/// <summary>
833879
/// Returns a TypeInfoReference object containing information about the specified VBA project reference
834880
/// </summary>

0 commit comments

Comments
 (0)