Skip to content

Commit 1a0ddf4

Browse files
authored
Merge pull request #1993 from Hosch250/cacheBugs
Make Open Project Properties open the properties for the correct proj…
2 parents f843f49 + bf5a454 commit 1a0ddf4

File tree

5 files changed

+60
-44
lines changed

5 files changed

+60
-44
lines changed

RetailCoder.VBE/Inspections/InspectionResultBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public int CompareTo(object obj)
121121
public object[] ToArray()
122122
{
123123
var module = QualifiedSelection.QualifiedName;
124-
return new object[] { Inspection.Severity.ToString(), module.ProjectTitle, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
124+
return new object[] { Inspection.Severity.ToString(), module.ProjectName, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
125125
}
126126

127127
public string ToCsvString()

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@
374374
CommandParameter="{Binding SelectedItem}" />
375375
<Separator />
376376
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_OpenProjectProperties}"
377-
Command="{Binding OpenProjectPropertiesCommand}" />
377+
Command="{Binding OpenProjectPropertiesCommand}"
378+
CommandParameter="{Binding SelectedItem}" />
378379
<Separator />
379380
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Add}">
380381
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_AddTestModuleText}"

RetailCoder.VBE/UI/CodeExplorer/Commands/CodeExplorer_OpenProjectPropertiesCommand.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Runtime.InteropServices;
12
using Microsoft.Vbe.Interop;
23
using NLog;
4+
using Rubberduck.Navigation.CodeExplorer;
35
using Rubberduck.UI.Command;
46

57
namespace Rubberduck.UI.CodeExplorer.Commands
@@ -13,10 +15,36 @@ public CodeExplorer_OpenProjectPropertiesCommand(VBE vbe) : base(LogManager.GetC
1315
_vbe = vbe;
1416
}
1517

18+
protected override bool CanExecuteImpl(object parameter)
19+
{
20+
return parameter != null || _vbe.VBProjects.Count == 1;
21+
}
22+
1623
protected override void ExecuteImpl(object parameter)
1724
{
1825
const int openProjectPropertiesId = 2578;
1926

27+
if (_vbe.VBProjects.Count == 1)
28+
{
29+
_vbe.CommandBars.FindControl(Id: openProjectPropertiesId).Execute();
30+
return;
31+
}
32+
33+
var node = parameter as CodeExplorerItemViewModel;
34+
while (!(node is ICodeExplorerDeclarationViewModel))
35+
{
36+
node = node.Parent; // the project node is an ICodeExplorerDeclarationViewModel--no worries here
37+
}
38+
39+
try
40+
{
41+
_vbe.ActiveVBProject = node.GetSelectedDeclaration().Project;
42+
}
43+
catch (COMException)
44+
{
45+
return; // the project was probably removed from the VBE, but not from the CE
46+
}
47+
2048
_vbe.CommandBars.FindControl(Id: openProjectPropertiesId).Execute();
2149
}
2250
}

RetailCoder.VBE/UnitTesting/TestMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public NavigateCodeEventArgs GetNavigationArgs()
109109

110110
public object[] ToArray()
111111
{
112-
return new object[] { Declaration.QualifiedName.QualifiedModuleName.ProjectTitle, Declaration.QualifiedName.QualifiedModuleName.ComponentName, Declaration.IdentifierName,
112+
return new object[] { Declaration.QualifiedName.QualifiedModuleName.ProjectName, Declaration.QualifiedName.QualifiedModuleName.ComponentName, Declaration.IdentifierName,
113113
_result.Outcome.ToString(), _result.Output, _result.StartTime.ToString(CultureInfo.InvariantCulture), _result.EndTime.ToString(CultureInfo.InvariantCulture), _result.Duration };
114114
}
115115

Rubberduck.VBEEditor/QualifiedModuleName.cs

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@ namespace Rubberduck.VBEditor
99
/// </summary>
1010
public struct QualifiedModuleName
1111
{
12-
private static string GetDisplayName(VBProject project)
13-
{
14-
try
15-
{
16-
if (project.HelpFile != project.VBE.ActiveVBProject.HelpFile)
17-
{
18-
project.VBE.ActiveVBProject = project;
19-
}
20-
return project.VBE.MainWindow.Caption.Split(' ').Last();
21-
}
22-
catch
23-
{
24-
return string.Empty;
25-
}
26-
}
27-
2812
public static string GetProjectId(VBProject project)
2913
{
3014
if (project == null)
@@ -55,7 +39,7 @@ public QualifiedModuleName(VBProject project)
5539
_projectName = project.Name;
5640
_projectPath = string.Empty;
5741
_projectId = GetProjectId(project);
58-
_projectDisplayName = GetDisplayName(project);
42+
_projectDisplayName = string.Empty;
5943
_contentHashCode = 0;
6044
}
6145

@@ -67,9 +51,9 @@ public QualifiedModuleName(VBComponent component)
6751
_componentName = component == null ? string.Empty : component.Name;
6852
_project = component == null ? null : component.Collection.Parent;
6953
_projectName = _project == null ? string.Empty : _project.Name;
70-
_projectDisplayName = GetDisplayName(_project);
7154
_projectPath = string.Empty;
7255
_projectId = GetProjectId(_project);
56+
_projectDisplayName = string.Empty;
7357

7458
_contentHashCode = 0;
7559
if (component == null)
@@ -121,37 +105,40 @@ public QualifiedMemberName QualifyMemberName(string member)
121105
public string ComponentName { get { return _componentName ?? string.Empty; } }
122106

123107
public string Name { get { return ToString(); } }
124-
125-
private readonly string _projectDisplayName;
126-
public string ProjectDisplayName { get { return _projectDisplayName; } }
127108

128-
/// <summary>
129-
/// returns: "ProjectName (DisplayName)" as typically displayed in VBE Project Explorer
130-
/// </summary>
131-
public string ProjectTitle
132-
{
133-
get
134-
{
135-
return _projectName + (_projectDisplayName != null ? " (" + _projectDisplayName + ")" : string.Empty);
136-
}
137-
}
138-
139109
private readonly string _projectName;
110+
public string ProjectName { get { return _projectName; } }
140111

141-
public string ProjectName
142-
{
143-
get
144-
{
145-
return _projectName;
146-
}
147-
}
148112
private readonly string _projectPath;
113+
public string ProjectPath { get { return _projectPath; } }
149114

150-
public string ProjectPath
115+
// because this causes a flicker in the VBE, we only want to do it once.
116+
// we also want to defer it as long as possible because it is only
117+
// needed in a couple places, and QualifiedModuleName is used in many places.
118+
private string _projectDisplayName;
119+
public string ProjectDisplayName
151120
{
152121
get
153122
{
154-
return _projectPath;
123+
if (_projectDisplayName != string.Empty)
124+
{
125+
return _projectDisplayName;
126+
}
127+
128+
try
129+
{
130+
if (_project.HelpFile != _project.VBE.ActiveVBProject.HelpFile)
131+
{
132+
_project.VBE.ActiveVBProject = _project;
133+
}
134+
135+
_projectDisplayName = _project.VBE.MainWindow.Caption.Split(' ').Last();
136+
return _projectDisplayName;
137+
}
138+
catch
139+
{
140+
return string.Empty;
141+
}
155142
}
156143
}
157144

0 commit comments

Comments
 (0)