Skip to content

Commit 35a490b

Browse files
committed
overloads AddComponent to accept a file path to import
1 parent 461934a commit 35a490b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Rubberduck.Core/UI/CodeExplorer/Commands/AddComponentCommand.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ public void AddComponent(CodeExplorerItemViewModel node, ComponentType type)
5151
}
5252
}
5353

54+
public void AddComponent(CodeExplorerItemViewModel node, string fileName)
55+
{
56+
var nodeProject = GetDeclaration(node)?.Project;
57+
if (node != null && nodeProject == null)
58+
{
59+
return; //The project is not available.
60+
}
61+
62+
using (var components = node != null
63+
? nodeProject.VBComponents
64+
: ComponentsCollectionFromActiveProject())
65+
{
66+
var folderAnnotation = $"'@Folder(\"{GetFolder(node)}\")";
67+
68+
using (var newComponent = components.Import(fileName))
69+
{
70+
using (var codeModule = newComponent.CodeModule)
71+
{
72+
codeModule.InsertLines(1, folderAnnotation);
73+
}
74+
}
75+
}
76+
}
77+
5478
private IVBComponents ComponentsCollectionFromActiveProject()
5579
{
5680
using (var activeProject = _vbe.ActiveVBProject)

0 commit comments

Comments
 (0)