Skip to content

Commit 4090a3a

Browse files
committed
IsBadPtr fix in COM collector, IOException fix in QualifiedModuleName (#1601)
* added AsTypeName to the context-sensitive commandbar * clear built-in references at every resolution; fixed issue with null parse trees, given built-in modules get a module state instance. * fixed OverflowException in GetTypeName; built-in parameters now have return type info :) * returning built-in members now have return type info as well * removed hard-coded defaults in ClassModuleDeclaration * added IsBadReadPtr check in COM declarations collector * Implemented CanExecute in Project Explorer rename command * cleaned up FormDesignerRefactorRename command * fixed IOExceptions in QualifiedModuleName * use filename, not buildfilename * GetDisplayName being the part in parens, should be null when not applicable; made it private
1 parent 4529765 commit 4090a3a

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

RetailCoder.VBE/UI/Command/Refactorings/FormDesignerRefactorRenameCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using Microsoft.Vbe.Interop;
3-
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;
43
using System.Runtime.InteropServices;
54
using Rubberduck.Parsing.Symbols;
65
using Rubberduck.Parsing.VBA;
@@ -14,14 +13,12 @@ public class FormDesignerRefactorRenameCommand : RefactorCommandBase
1413
{
1514
private readonly VBE _vbe;
1615
private readonly RubberduckParserState _state;
17-
private readonly ICodePaneWrapperFactory _wrapperWrapperFactory;
1816

19-
public FormDesignerRefactorRenameCommand(VBE vbe, RubberduckParserState state, ICodePaneWrapperFactory wrapperWrapperFactory)
17+
public FormDesignerRefactorRenameCommand(VBE vbe, RubberduckParserState state)
2018
: base (vbe)
2119
{
2220
_vbe = vbe;
2321
_state = state;
24-
_wrapperWrapperFactory = wrapperWrapperFactory;
2522
}
2623

2724
public override bool CanExecute(object parameter)

RetailCoder.VBE/UI/Command/Refactorings/ProjectExplorerRefactorRenameCommand.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public ProjectExplorerRefactorRenameCommand(VBE vbe, RubberduckParserState state
2121
_msgBox = msgBox;
2222
}
2323

24+
public override bool CanExecute(object parameter)
25+
{
26+
return _state.Status == ParserState.Ready;
27+
}
28+
2429
public override void Execute(object parameter)
2530
{
2631
using (var view = new RenameDialog())

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,34 @@ namespace Rubberduck.VBEditor
1010
/// </summary>
1111
public struct QualifiedModuleName
1212
{
13-
14-
public static string GetDisplayName(VBProject project)
13+
private static string GetDisplayName(VBProject project)
1514
{
16-
try
15+
if (!string.IsNullOrEmpty(Path.GetDirectoryName(project.BuildFileName)))
1716
{
1817
return Path.GetFileName(project.FileName);
1918
}
20-
catch
21-
{
22-
//the file hasn't been saved yet
23-
}
2419

25-
try
26-
{
27-
//Don't need to check protection, as a protected project is saved, by definition
28-
return project.VBComponents.Cast<VBComponent>()
29-
.Where(component => component.Type == vbext_ComponentType.vbext_ct_Document
30-
&& component.Properties.Count > 1)
31-
.SelectMany(component => component.Properties.OfType<Property>())
32-
.FirstOrDefault(property => property.Name == "Name").Value.ToString();
33-
}
34-
catch
35-
{
36-
return null;
37-
}
20+
//Don't need to check protection, as a protected project is saved, by definition
21+
var firstOrDefault = project.VBComponents.Cast<VBComponent>()
22+
.Where(component => component.Type == vbext_ComponentType.vbext_ct_Document
23+
&& component.Properties.Count > 1)
24+
.SelectMany(component => component.Properties.OfType<Property>())
25+
.FirstOrDefault(property => property.Name == "Name");
26+
return firstOrDefault == null
27+
? null
28+
: firstOrDefault.Value.ToString();
3829
}
3930

40-
public static string GetDisplayName(VBComponent component)
31+
private static string GetDisplayName(VBComponent component)
4132
{
42-
if (component.Type == vbext_ComponentType.vbext_ct_Document)
33+
if (component.Type != vbext_ComponentType.vbext_ct_Document)
4334
{
44-
try
45-
{
46-
return component.Properties.Item("Name").Value.ToString();
47-
}
48-
catch
49-
{
50-
return null;
51-
}
52-
}
53-
else {
5435
return null;
5536
}
37+
var nameProperty = component.Properties.Cast<Property>().SingleOrDefault(p => p.Name == "Name");
38+
return nameProperty == null
39+
? null
40+
: nameProperty.Value.ToString();
5641
}
5742

5843
public static string GetProjectId(VBProject project)
@@ -61,7 +46,9 @@ public static string GetProjectId(VBProject project)
6146
{
6247
return string.Empty;
6348
}
64-
return string.IsNullOrEmpty(project.HelpFile) ? project.GetHashCode().ToString() : project.HelpFile;
49+
return string.IsNullOrEmpty(project.HelpFile)
50+
? project.GetHashCode().ToString()
51+
: project.HelpFile;
6552
}
6653

6754
public static string GetProjectId(Reference reference)

0 commit comments

Comments
 (0)