Skip to content

Commit f3a6b6d

Browse files
committed
Fix rename-project crashing bug.
1 parent 05141a3 commit f3a6b6d

File tree

4 files changed

+75
-15
lines changed

4 files changed

+75
-15
lines changed

RetailCoder.VBE/UI/Command/AddTestModuleCommand.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,7 @@ public AddTestModuleCommand(VBE vbe, RubberduckParserState state, NewUnitTestMod
2525

2626
public override bool CanExecute(object parameter)
2727
{
28-
var app = _vbe.HostApplication();
29-
if (app == null || _state.Status != ParserState.Ready)
30-
{
31-
return false;
32-
}
33-
34-
// Outlook requires test methods to be located in [ThisOutlookSession] class.
35-
//return app.ApplicationName != "Outlook";
36-
return true;
28+
return _vbe.HostSupportsUnitTests();
3729
}
3830

3931
public override void Execute(object parameter)

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void RemoveProject(string projectId)
158158

159159
public void RemoveProject(VBProject project)
160160
{
161-
RemoveProject(QualifiedModuleName.GetProjectId(project));
161+
RemoveProject(project.HelpFile);
162162
ClearStateCache(project);
163163
}
164164

@@ -584,6 +584,12 @@ public void ClearStateCache(VBProject project, bool notifyStateChanged = false)
584584
// until Hell freezes over?
585585
}
586586
}
587+
588+
ModuleState state;
589+
if (_moduleStates.TryRemove(new QualifiedModuleName(project), out state))
590+
{
591+
state.Dispose();
592+
}
587593
}
588594
catch (COMException)
589595
{
@@ -690,6 +696,10 @@ public bool RemoveRenamedComponent(VBComponent component, string oldComponentNam
690696
OnStateChanged(ParserState.ResolvedDeclarations); // trigger test explorer and code explorer updates
691697
OnStateChanged(ParserState.Ready); // trigger find all references &c. updates
692698
}
699+
700+
_projects.Remove(match.ProjectId);
701+
_projects.Add(match.ProjectId, component.Collection.Parent);
702+
693703
return success;
694704
}
695705

Rubberduck.VBEEditor/Extensions/VbeExtensions.cs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static IHostApplication HostApplication(this VBE vbe)
7878
return new CorelDRAWApp();
7979
}
8080
}
81-
return null;// new FallbackApp(vbe);
81+
return null;
8282
}
8383

8484
foreach (var reference in vbe.ActiveVBProject.References.Cast<Reference>()
@@ -109,7 +109,61 @@ public static IHostApplication HostApplication(this VBE vbe)
109109
}
110110
}
111111

112-
return null; //new FallbackApp(vbe);
112+
return null;
113+
}
114+
115+
/// <summary> Returns whether the host supports unit tests.</summary>
116+
public static bool HostSupportsUnitTests(this VBE vbe)
117+
{
118+
if (vbe.ActiveVBProject == null)
119+
{
120+
const int ctlViewHost = 106;
121+
122+
var hostAppControl = vbe.CommandBars.FindControl(MsoControlType.msoControlButton, ctlViewHost);
123+
124+
if (hostAppControl == null)
125+
{
126+
return false;
127+
}
128+
129+
switch (hostAppControl.Caption)
130+
{
131+
case "Microsoft Excel":
132+
case "Microsoft Access":
133+
case "Microsoft Word":
134+
case "Microsoft PowerPoint":
135+
case "Microsoft Outlook":
136+
case "Microsoft Project":
137+
case "Microsoft Publisher":
138+
case "Microsoft Visio":
139+
case "AutoCAD":
140+
case "CorelDRAW":
141+
return true;
142+
default:
143+
return false;
144+
}
145+
}
146+
147+
foreach (var reference in vbe.ActiveVBProject.References.Cast<Reference>()
148+
.Where(reference => (reference.BuiltIn && reference.Name != "VBA") || (reference.Name == "AutoCAD")))
149+
{
150+
switch (reference.Name)
151+
{
152+
case "Excel":
153+
case "Access":
154+
case "Word":
155+
case "PowerPoint":
156+
case "Outlook":
157+
case "MSProject":
158+
case "Publisher":
159+
case "Visio":
160+
case "AutoCAD":
161+
case "CorelDRAW":
162+
return true;
163+
}
164+
}
165+
166+
return false;
113167
}
114168
}
115169
}

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ public static string GetProjectId(VBProject project)
108108
{
109109
return string.Empty;
110110
}
111-
return string.IsNullOrEmpty(project.HelpFile)
112-
? project.GetHashCode().ToString()
113-
: project.HelpFile;
111+
112+
if (string.IsNullOrEmpty(project.HelpFile))
113+
{
114+
project.HelpFile = project.GetHashCode().ToString();
115+
}
116+
117+
return project.HelpFile;
114118
}
115119

116120
public static string GetProjectId(Reference reference)

0 commit comments

Comments
 (0)