File tree Expand file tree Collapse file tree 4 files changed +61
-9
lines changed
RetailCoder.VBE/UI/CodeExplorer/Commands Expand file tree Collapse file tree 4 files changed +61
-9
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,28 @@ namespace Rubberduck.UI.CodeExplorer.Commands
7
7
{
8
8
public class CodeExplorer_AddClassModuleCommand : CommandBase
9
9
{
10
+ private readonly VBE _vbe ;
11
+
12
+ public CodeExplorer_AddClassModuleCommand ( VBE vbe )
13
+ {
14
+ _vbe = vbe ;
15
+ }
16
+
10
17
public override bool CanExecute ( object parameter )
11
18
{
12
- return GetDeclaration ( parameter ) != null ;
19
+ return GetDeclaration ( parameter ) != null || _vbe . VBProjects . Count == 1 ;
13
20
}
14
21
15
22
public override void Execute ( object parameter )
16
23
{
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
+ }
18
32
}
19
33
20
34
private Declaration GetDeclaration ( object parameter )
Original file line number Diff line number Diff line change @@ -7,14 +7,28 @@ namespace Rubberduck.UI.CodeExplorer.Commands
7
7
{
8
8
public class CodeExplorer_AddStdModuleCommand : CommandBase
9
9
{
10
+ private readonly VBE _vbe ;
11
+
12
+ public CodeExplorer_AddStdModuleCommand ( VBE vbe )
13
+ {
14
+ _vbe = vbe ;
15
+ }
16
+
10
17
public override bool CanExecute ( object parameter )
11
18
{
12
- return GetDeclaration ( parameter ) != null ;
19
+ return GetDeclaration ( parameter ) != null || _vbe . VBProjects . Count == 1 ;
13
20
}
14
21
15
22
public override void Execute ( object parameter )
16
23
{
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
+ }
18
32
}
19
33
20
34
private Declaration GetDeclaration ( object parameter )
Original file line number Diff line number Diff line change
1
+ using Microsoft . Vbe . Interop ;
1
2
using Rubberduck . Navigation . CodeExplorer ;
2
3
using Rubberduck . Parsing . Symbols ;
3
4
using Rubberduck . UI . Command ;
@@ -7,21 +8,30 @@ namespace Rubberduck.UI.CodeExplorer.Commands
7
8
{
8
9
public class CodeExplorer_AddTestModuleCommand : CommandBase
9
10
{
11
+ private readonly VBE _vbe ;
10
12
private readonly NewUnitTestModuleCommand _newUnitTestModuleCommand ;
11
13
12
- public CodeExplorer_AddTestModuleCommand ( NewUnitTestModuleCommand newUnitTestModuleCommand )
14
+ public CodeExplorer_AddTestModuleCommand ( VBE vbe , NewUnitTestModuleCommand newUnitTestModuleCommand )
13
15
{
16
+ _vbe = vbe ;
14
17
_newUnitTestModuleCommand = newUnitTestModuleCommand ;
15
18
}
16
19
17
20
public override bool CanExecute ( object parameter )
18
21
{
19
- return GetDeclaration ( parameter ) != null ;
22
+ return GetDeclaration ( parameter ) != null || _vbe . VBProjects . Count == 1 ;
20
23
}
21
24
22
25
public override void Execute ( object parameter )
23
26
{
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
+ }
25
35
}
26
36
27
37
private Declaration GetDeclaration ( object parameter )
Original file line number Diff line number Diff line change @@ -7,14 +7,28 @@ namespace Rubberduck.UI.CodeExplorer.Commands
7
7
{
8
8
public class CodeExplorer_AddUserFormCommand : CommandBase
9
9
{
10
+ private readonly VBE _vbe ;
11
+
12
+ public CodeExplorer_AddUserFormCommand ( VBE vbe )
13
+ {
14
+ _vbe = vbe ;
15
+ }
16
+
10
17
public override bool CanExecute ( object parameter )
11
18
{
12
- return GetDeclaration ( parameter ) != null ;
19
+ return GetDeclaration ( parameter ) != null || _vbe . VBProjects . Count == 1 ;
13
20
}
14
21
15
22
public override void Execute ( object parameter )
16
23
{
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
+ }
18
32
}
19
33
20
34
private Declaration GetDeclaration ( object parameter )
You can’t perform that action at this time.
0 commit comments