Skip to content

Commit cb22100

Browse files
committed
Finish removing Project from QualifiedModuleName, add fallback syntax for ExcelApp.GenerateMethodCall
1 parent 26a0a6e commit cb22100

File tree

7 files changed

+51
-71
lines changed

7 files changed

+51
-71
lines changed

RetailCoder.VBE/Inspections/QuickFixes/RenameProjectQuickFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selec
2828

2929
public override void Fix()
3030
{
31-
var vbe = Selection.QualifiedName.Project.VBE;
31+
var vbe = _target.Project.VBE;
3232

3333
using (var view = new RenameDialog())
3434
{

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ public Declaration(
119119
isBuiltIn,
120120
annotations,
121121
attributes)
122-
{
123-
}
122+
{ }
124123

125124
public Declaration(
126125
QualifiedMemberName qualifiedName,
@@ -140,8 +139,7 @@ public Declaration(
140139
IEnumerable<IAnnotation> annotations = null,
141140
Attributes attributes = null)
142141
{
143-
_qualifiedName = qualifiedName;
144-
_project = qualifiedName.QualifiedModuleName.Project;
142+
_qualifiedName = qualifiedName;
145143
_parentDeclaration = parentDeclaration;
146144
_parentScopeDeclaration = _parentDeclaration;
147145
_parentScope = parentScope ?? string.Empty;
@@ -158,7 +156,7 @@ public Declaration(
158156
_attributes = attributes ?? new Attributes();
159157

160158
_projectId = _qualifiedName.QualifiedModuleName.ProjectId;
161-
var projectDeclaration = Declaration.GetProjectParent(parentDeclaration);
159+
var projectDeclaration = GetProjectParent(parentDeclaration);
162160
if (projectDeclaration != null)
163161
{
164162
_projectName = projectDeclaration.IdentifierName;
@@ -406,14 +404,13 @@ public void AddReference(
406404

407405
public QualifiedSelection QualifiedSelection { get { return new QualifiedSelection(_qualifiedName.QualifiedModuleName, _selection); } }
408406

409-
private readonly IVBProject _project;
410407
/// <summary>
411408
/// Gets a reference to the VBProject the declaration is made in.
412409
/// </summary>
413410
/// <remarks>
414411
/// This property is intended to differenciate identically-named VBProjects.
415412
/// </remarks>
416-
public virtual IVBProject Project { get { return _project ?? _parentDeclaration.Project; } }
413+
public virtual IVBProject Project { get { return _parentDeclaration.Project; } }
417414

418415
private readonly string _projectId;
419416
/// <summary>

Rubberduck.SourceControl/SourceControlProviderBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void ReloadComponent(string filePath)
181181
directory += directory.EndsWith("\\") ? string.Empty : "\\";
182182
components.Import(directory + filePath);
183183

184-
VBE.SetSelection(selection.QualifiedName.Project, selection.Selection, name);
184+
VBE.SetSelection(component.Collection.Parent, selection.Selection, name);
185185
}
186186
}
187187
else
@@ -224,7 +224,7 @@ private void Refresh()
224224
throw new SourceControlException("Unknown exception.", ex);
225225
}
226226

227-
VBE.SetSelection(selection.QualifiedName.Project, selection.Selection, name);
227+
VBE.SetSelection(component.Collection.Parent, selection.Selection, name);
228228
}
229229
}
230230
else

Rubberduck.VBEEditor/Application/ExcelApp.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Path = System.IO.Path;
2-
using System.Runtime.InteropServices;
3-
using Microsoft.Office.Interop.Visio;
42
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
53

64
namespace Rubberduck.VBEditor.Application
@@ -20,11 +18,13 @@ protected virtual string GenerateMethodCall(QualifiedMemberName qualifiedMemberN
2018
{
2119
var module = qualifiedMemberName.QualifiedModuleName;
2220

23-
var documentName = string.IsNullOrEmpty(module.Project.FileName)
21+
var documentName = string.IsNullOrEmpty(module.ProjectPath)
2422
? module.ProjectDisplayName
25-
: Path.GetFileName(module.Project.FileName);
23+
: Path.GetFileName(module.ProjectPath);
2624

27-
return string.Format("'{0}'!{1}", documentName.Replace("'", "''"), qualifiedMemberName);
25+
return string.IsNullOrEmpty(documentName)
26+
? qualifiedMemberName.ToString()
27+
: string.Format("'{0}'!{1}", documentName.Replace("'", "''"), qualifiedMemberName);
2828
}
2929
}
3030
}

Rubberduck.VBEEditor/Application/PowerPointApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private string GenerateMethodCall(QualifiedMemberName qualifiedMemberName)
1919
/* Note: Powerpoint supports a `FileName.ppt!Module.method` syntax
2020
** http://msdn.microsoft.com/en-us/library/office/ff744221(v=office.15).aspx
2121
*/
22-
var path = qualifiedMemberName.QualifiedModuleName.Project.FileName;
22+
var path = qualifiedMemberName.QualifiedModuleName.ProjectPath;
2323
if (string.IsNullOrEmpty(path))
2424
{
2525
// if project isn't saved yet, we can't qualify the method call: this only works with the active project.

Rubberduck.VBEEditor/Application/SolidWorksApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public SolidWorksApp(IVBE vbe) : base(vbe, "SolidWorks") { }
1010

1111
public override void Run(QualifiedMemberName qualifiedMemberName)
1212
{
13-
var projectFileName = qualifiedMemberName.QualifiedModuleName.Project.FileName;
13+
var projectFileName = qualifiedMemberName.QualifiedModuleName.ProjectPath;
1414
if (Application == null || string.IsNullOrEmpty(projectFileName)) { return; }
1515

1616
var moduleName = qualifiedMemberName.QualifiedModuleName.ComponentName;

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,35 @@ public QualifiedModuleName(IVBProject project)
3636
_component = null;
3737
_componentName = null;
3838
_componentType = ComponentType.Undefined;
39-
_project = project;
4039
_projectName = project.Name;
4140
_projectPath = string.Empty;
42-
_projectId = GetProjectId(project);
43-
_projectDisplayName = string.Empty;
41+
_projectId = GetProjectId(project);
4442
_contentHashCode = 0;
43+
_projectDisplayName = string.Empty;
44+
SetProjectDisplayName(project);
4545
}
4646

4747
public QualifiedModuleName(IVBComponent component)
4848
{
49-
_project = null; // field is only assigned when the instance refers to a VBProject.
50-
5149
_componentType = component.Type;
5250
_component = component;
5351
_componentName = component.IsWrappingNullReference ? string.Empty : component.Name;
5452

55-
var components = component.Collection;
56-
{
57-
_project = components.Parent;
58-
_projectName = _project == null ? string.Empty : _project.Name;
59-
_projectPath = string.Empty;
60-
_projectId = GetProjectId(_project);
61-
_projectDisplayName = string.Empty;
62-
}
63-
64-
_projectName = _project == null ? string.Empty : _project.Name;
65-
_projectPath = string.Empty;
66-
_projectId = GetProjectId(_project);
67-
_projectDisplayName = string.Empty;
68-
6953
_contentHashCode = 0;
70-
if (component.IsWrappingNullReference)
71-
{
72-
return;
73-
}
74-
75-
var module = component.CodeModule;
54+
if (!component.IsWrappingNullReference)
7655
{
56+
var module = _component.CodeModule;
7757
_contentHashCode = module.CountOfLines > 0
7858
? module.GetLines(1, module.CountOfLines).GetHashCode()
7959
: 0;
8060
}
61+
62+
var project = component.Collection.Parent;
63+
_projectName = project == null ? string.Empty : project.Name;
64+
_projectPath = string.Empty;
65+
_projectId = GetProjectId(project);
66+
_projectDisplayName = string.Empty;
67+
SetProjectDisplayName(project);
8168
}
8269

8370
/// <summary>
@@ -86,7 +73,6 @@ public QualifiedModuleName(IVBComponent component)
8673
/// </summary>
8774
public QualifiedModuleName(string projectName, string projectPath, string componentName)
8875
{
89-
_project = null;
9076
_projectName = projectName;
9177
_projectDisplayName = null;
9278
_projectPath = projectPath;
@@ -108,9 +94,6 @@ public QualifiedMemberName QualifyMemberName(string member)
10894
private readonly ComponentType _componentType;
10995
public ComponentType ComponentType { get { return _componentType; } }
11096

111-
private readonly IVBProject _project;
112-
public IVBProject Project { get { return _project; } }
113-
11497
private readonly int _contentHashCode;
11598
public int ContentHashCode { get { return _contentHashCode; } }
11699

@@ -137,37 +120,37 @@ public QualifiedMemberName QualifyMemberName(string member)
137120
private string _projectDisplayName;
138121
public string ProjectDisplayName
139122
{
140-
get
123+
get { return _projectDisplayName; }
124+
}
125+
126+
private void SetProjectDisplayName(IVBProject project)
127+
{
128+
if (project == null)
141129
{
142-
if (_projectDisplayName != string.Empty)
130+
return;
131+
}
132+
var vbe = project.VBE;
133+
var activeProject = vbe.ActiveVBProject;
134+
var mainWindow = vbe.MainWindow;
135+
{
136+
try
143137
{
144-
return _projectDisplayName;
145-
}
138+
if (project.HelpFile != activeProject.HelpFile)
139+
{
140+
vbe.ActiveVBProject = project;
141+
}
146142

147-
var vbe = _project.VBE;
148-
var activeProject = vbe.ActiveVBProject;
149-
var mainWindow = vbe.MainWindow;
150-
{
151-
try
143+
var caption = mainWindow.Caption;
144+
if (CaptionProjectRegex.IsMatch(caption))
152145
{
153-
if (_project.HelpFile != activeProject.HelpFile)
154-
{
155-
vbe.ActiveVBProject = _project;
156-
}
157-
158-
var caption = mainWindow.Caption;
159-
if (CaptionProjectRegex.IsMatch(caption))
160-
{
161-
caption = CaptionProjectRegex.Matches(caption)[0].Groups["project"].Value;
162-
_projectDisplayName = OpenModuleRegex.IsMatch(caption)
163-
? OpenModuleRegex.Matches(caption)[0].Groups["project"].Value
164-
: caption;
165-
}
146+
caption = CaptionProjectRegex.Matches(caption)[0].Groups["project"].Value;
147+
_projectDisplayName = OpenModuleRegex.IsMatch(caption)
148+
? OpenModuleRegex.Matches(caption)[0].Groups["project"].Value
149+
: caption;
166150
}
167-
// ReSharper disable once EmptyGeneralCatchClause
168-
catch { }
169-
return _projectDisplayName;
170151
}
152+
// ReSharper disable once EmptyGeneralCatchClause
153+
catch { }
171154
}
172155
}
173156

0 commit comments

Comments
 (0)