Skip to content

Commit 992a776

Browse files
committed
Fix up unit tests and some code cleanup
1 parent 0c0f94b commit 992a776

File tree

6 files changed

+83
-136
lines changed

6 files changed

+83
-136
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Linq;
54
using System.Runtime.InteropServices;
65
using System.Windows.Media.Imaging;
7-
using NLog;
86
using Rubberduck.Parsing.Symbols;
97
using Rubberduck.VBEditor;
108
using Rubberduck.Parsing.Annotations;

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ public double FontSize
544544
public AddUserDocumentCommand AddUserDocumentCommand { get; set; }
545545
public AddTestModuleCommand AddTestModuleCommand { get; set; }
546546
public AddTestModuleWithStubsCommand AddTestModuleWithStubsCommand { get; set; }
547-
//public CommandBase AddPredeclaredClassModuleCommand { get; set; }
548-
public AddTemplateCommand AddTemplateCommand { get; set; }
547+
public AddTemplateCommand AddTemplateCommand { get; set; }
549548
public CommandBase OpenDesignerCommand { get; set; }
550549
public CommandBase OpenProjectPropertiesCommand { get; set; }
551550
public SetAsStartupProjectCommand SetAsStartupProjectCommand { get; set; }

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public bool CanAddComponent(CodeExplorerItemViewModel parameter, IEnumerable<Pro
2525
{
2626
var project = GetDeclaration(parameter)?.Project;
2727

28-
if (project == null && _vbe.ProjectsCount == 1)
28+
if (project != null || _vbe.ProjectsCount != 1)
2929
{
30-
using (var vbProjects = _vbe.VBProjects)
31-
using (project = vbProjects[1])
32-
{
33-
return project != null && allowableProjectTypes.Contains(project.Type);
34-
}
30+
return project != null && allowableProjectTypes.Contains(project.Type);
3531
}
3632

37-
return project != null && allowableProjectTypes.Contains(project.Type);
33+
using (var vbProjects = _vbe.VBProjects)
34+
using (project = vbProjects[1])
35+
{
36+
return project != null && allowableProjectTypes.Contains(project.Type);
37+
}
3838

3939
}
4040
catch (COMException)
@@ -75,8 +75,8 @@ public void AddComponent(CodeExplorerItemViewModel node, string moduleText)
7575
return; //The project is not available.
7676
}
7777

78-
string optionCompare = string.Empty;
79-
using (IHostApplication hostApp = _vbe.HostApplication())
78+
string optionCompare;
79+
using (var hostApp = _vbe.HostApplication())
8080
{
8181
optionCompare = hostApp?.ApplicationName == "Access" ? "Option Compare Database" :
8282
string.Empty;
@@ -87,13 +87,12 @@ public void AddComponent(CodeExplorerItemViewModel node, string moduleText)
8787
: ComponentsCollectionFromActiveProject())
8888
{
8989
var folderAnnotation = $"'@Folder(\"{GetFolder(node)}\")";
90-
string fileName = createTempTextFile(moduleText);
90+
var fileName = CreateTempTextFile(moduleText);
9191

9292
using (var newComponent = components.Import(fileName))
9393
{
9494
using (var codeModule = newComponent.CodeModule)
9595
{
96-
var delarationLines = string.Concat(folderAnnotation, optionCompare);
9796
if (optionCompare.Length > 0)
9897
{
9998
codeModule.InsertLines(1, optionCompare);
@@ -109,14 +108,14 @@ public void AddComponent(CodeExplorerItemViewModel node, string moduleText)
109108
}
110109
}
111110

112-
private string createTempTextFile(string moduleText)
111+
private static string CreateTempTextFile(string moduleText)
113112
{
114-
string tempFolder = ApplicationConstants.RUBBERDUCK_TEMP_PATH;
113+
var tempFolder = ApplicationConstants.RUBBERDUCK_TEMP_PATH;
115114
if (!Directory.Exists(tempFolder))
116115
{
117116
Directory.CreateDirectory(tempFolder);
118117
}
119-
string filePath = Path.Combine(tempFolder, Path.GetRandomFileName());
118+
var filePath = Path.Combine(tempFolder, Path.GetRandomFileName());
120119
File.WriteAllText(filePath, moduleText);
121120
return filePath;
122121
}

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

Lines changed: 0 additions & 46 deletions
This file was deleted.

Rubberduck.Resources/CodeExplorer/CodeExplorerUI.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,4 @@
376376
<data name="CodeExplorer_SetAsStartupProject" xml:space="preserve">
377377
<value>Set as start up</value>
378378
</data>
379-
<data name="CodeExplorer_AddPredeclaredClassModuleText" xml:space="preserve">
380-
<value>Predeclared Class module (.cls)</value>
381-
</data>
382379
</root>

0 commit comments

Comments
 (0)