Skip to content

Commit bd847cd

Browse files
committed
Close #1778
1 parent 0bc0b21 commit bd847cd

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_AddClassModuleCommand.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@ namespace Rubberduck.UI.CodeExplorer.Commands
77
{
88
public class CodeExplorer_AddClassModuleCommand : CommandBase
99
{
10+
private readonly VBE _vbe;
11+
12+
public CodeExplorer_AddClassModuleCommand(VBE vbe)
13+
{
14+
_vbe = vbe;
15+
}
16+
1017
public override bool CanExecute(object parameter)
1118
{
12-
return GetDeclaration(parameter) != null;
19+
return GetDeclaration(parameter) != null || _vbe.VBProjects.Count == 1;
1320
}
1421

1522
public override void Execute(object parameter)
1623
{
17-
GetDeclaration(parameter).Project.VBComponents.Add(vbext_ComponentType.vbext_ct_ClassModule);
24+
if (parameter != null)
25+
{
26+
GetDeclaration(parameter).Project.VBComponents.Add(vbext_ComponentType.vbext_ct_ClassModule);
27+
}
28+
else
29+
{
30+
_vbe.VBProjects.Item(1).VBComponents.Add(vbext_ComponentType.vbext_ct_ClassModule);
31+
}
1832
}
1933

2034
private Declaration GetDeclaration(object parameter)

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_AddStdModuleCommand.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@ namespace Rubberduck.UI.CodeExplorer.Commands
77
{
88
public class CodeExplorer_AddStdModuleCommand : CommandBase
99
{
10+
private readonly VBE _vbe;
11+
12+
public CodeExplorer_AddStdModuleCommand(VBE vbe)
13+
{
14+
_vbe = vbe;
15+
}
16+
1017
public override bool CanExecute(object parameter)
1118
{
12-
return GetDeclaration(parameter) != null;
19+
return GetDeclaration(parameter) != null || _vbe.VBProjects.Count == 1;
1320
}
1421

1522
public override void Execute(object parameter)
1623
{
17-
GetDeclaration(parameter).Project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
24+
if (parameter != null)
25+
{
26+
GetDeclaration(parameter).Project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
27+
}
28+
else
29+
{
30+
_vbe.VBProjects.Item(1).VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
31+
}
1832
}
1933

2034
private Declaration GetDeclaration(object parameter)

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_AddTestModuleCommand.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.Vbe.Interop;
12
using Rubberduck.Navigation.CodeExplorer;
23
using Rubberduck.Parsing.Symbols;
34
using Rubberduck.UI.Command;
@@ -7,21 +8,30 @@ namespace Rubberduck.UI.CodeExplorer.Commands
78
{
89
public class CodeExplorer_AddTestModuleCommand : CommandBase
910
{
11+
private readonly VBE _vbe;
1012
private readonly NewUnitTestModuleCommand _newUnitTestModuleCommand;
1113

12-
public CodeExplorer_AddTestModuleCommand(NewUnitTestModuleCommand newUnitTestModuleCommand)
14+
public CodeExplorer_AddTestModuleCommand(VBE vbe, NewUnitTestModuleCommand newUnitTestModuleCommand)
1315
{
16+
_vbe = vbe;
1417
_newUnitTestModuleCommand = newUnitTestModuleCommand;
1518
}
1619

1720
public override bool CanExecute(object parameter)
1821
{
19-
return GetDeclaration(parameter) != null;
22+
return GetDeclaration(parameter) != null || _vbe.VBProjects.Count == 1;
2023
}
2124

2225
public override void Execute(object parameter)
2326
{
24-
_newUnitTestModuleCommand.NewUnitTestModule(GetDeclaration(parameter).Project);
27+
if (parameter != null)
28+
{
29+
_newUnitTestModuleCommand.NewUnitTestModule(GetDeclaration(parameter).Project);
30+
}
31+
else
32+
{
33+
_newUnitTestModuleCommand.NewUnitTestModule(_vbe.VBProjects.Item(1));
34+
}
2535
}
2636

2737
private Declaration GetDeclaration(object parameter)

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_AddUserFormCommand.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,28 @@ namespace Rubberduck.UI.CodeExplorer.Commands
77
{
88
public class CodeExplorer_AddUserFormCommand : CommandBase
99
{
10+
private readonly VBE _vbe;
11+
12+
public CodeExplorer_AddUserFormCommand(VBE vbe)
13+
{
14+
_vbe = vbe;
15+
}
16+
1017
public override bool CanExecute(object parameter)
1118
{
12-
return GetDeclaration(parameter) != null;
19+
return GetDeclaration(parameter) != null || _vbe.VBProjects.Count == 1;
1320
}
1421

1522
public override void Execute(object parameter)
1623
{
17-
GetDeclaration(parameter).Project.VBComponents.Add(vbext_ComponentType.vbext_ct_MSForm);
24+
if (parameter != null)
25+
{
26+
GetDeclaration(parameter).Project.VBComponents.Add(vbext_ComponentType.vbext_ct_MSForm);
27+
}
28+
else
29+
{
30+
_vbe.VBProjects.Item(1).VBComponents.Add(vbext_ComponentType.vbext_ct_MSForm);
31+
}
1832
}
1933

2034
private Declaration GetDeclaration(object parameter)

0 commit comments

Comments
 (0)