Skip to content

Commit

Permalink
IsBadPtr fix in COM collector, IOException fix in QualifiedModuleName (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
retailcoder committed May 27, 2016
1 parent 4529765 commit 4090a3a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
@@ -1,6 +1,5 @@
using System.Linq;
using Microsoft.Vbe.Interop;
using Rubberduck.VBEditor.VBEInterfaces.RubberduckCodePane;
using System.Runtime.InteropServices;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
Expand All @@ -14,14 +13,12 @@ public class FormDesignerRefactorRenameCommand : RefactorCommandBase
{
private readonly VBE _vbe;
private readonly RubberduckParserState _state;
private readonly ICodePaneWrapperFactory _wrapperWrapperFactory;

public FormDesignerRefactorRenameCommand(VBE vbe, RubberduckParserState state, ICodePaneWrapperFactory wrapperWrapperFactory)
public FormDesignerRefactorRenameCommand(VBE vbe, RubberduckParserState state)
: base (vbe)
{
_vbe = vbe;
_state = state;
_wrapperWrapperFactory = wrapperWrapperFactory;
}

public override bool CanExecute(object parameter)
Expand Down
Expand Up @@ -21,6 +21,11 @@ public ProjectExplorerRefactorRenameCommand(VBE vbe, RubberduckParserState state
_msgBox = msgBox;
}

public override bool CanExecute(object parameter)
{
return _state.Status == ParserState.Ready;
}

public override void Execute(object parameter)
{
using (var view = new RenameDialog())
Expand Down
53 changes: 20 additions & 33 deletions Rubberduck.VBEEditor/QualifiedModuleName.cs
Expand Up @@ -10,49 +10,34 @@ namespace Rubberduck.VBEditor
/// </summary>
public struct QualifiedModuleName
{

public static string GetDisplayName(VBProject project)
private static string GetDisplayName(VBProject project)
{
try
if (!string.IsNullOrEmpty(Path.GetDirectoryName(project.BuildFileName)))
{
return Path.GetFileName(project.FileName);
}
catch
{
//the file hasn't been saved yet
}

try
{
//Don't need to check protection, as a protected project is saved, by definition
return project.VBComponents.Cast<VBComponent>()
.Where(component => component.Type == vbext_ComponentType.vbext_ct_Document
&& component.Properties.Count > 1)
.SelectMany(component => component.Properties.OfType<Property>())
.FirstOrDefault(property => property.Name == "Name").Value.ToString();
}
catch
{
return null;
}
//Don't need to check protection, as a protected project is saved, by definition
var firstOrDefault = project.VBComponents.Cast<VBComponent>()
.Where(component => component.Type == vbext_ComponentType.vbext_ct_Document
&& component.Properties.Count > 1)
.SelectMany(component => component.Properties.OfType<Property>())
.FirstOrDefault(property => property.Name == "Name");
return firstOrDefault == null
? null
: firstOrDefault.Value.ToString();
}

public static string GetDisplayName(VBComponent component)
private static string GetDisplayName(VBComponent component)
{
if (component.Type == vbext_ComponentType.vbext_ct_Document)
if (component.Type != vbext_ComponentType.vbext_ct_Document)
{
try
{
return component.Properties.Item("Name").Value.ToString();
}
catch
{
return null;
}
}
else {
return null;
}
var nameProperty = component.Properties.Cast<Property>().SingleOrDefault(p => p.Name == "Name");
return nameProperty == null
? null
: nameProperty.Value.ToString();
}

public static string GetProjectId(VBProject project)
Expand All @@ -61,7 +46,9 @@ public static string GetProjectId(VBProject project)
{
return string.Empty;
}
return string.IsNullOrEmpty(project.HelpFile) ? project.GetHashCode().ToString() : project.HelpFile;
return string.IsNullOrEmpty(project.HelpFile)
? project.GetHashCode().ToString()
: project.HelpFile;
}

public static string GetProjectId(Reference reference)
Expand Down

0 comments on commit 4090a3a

Please sign in to comment.