Skip to content

Commit e9937a2

Browse files
committed
Correct ProjectDisplayName for VB6
1 parent 433a57b commit e9937a2

File tree

2 files changed

+10
-64
lines changed

2 files changed

+10
-64
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.ComponentModel;
32
using System.Linq;
43
using System.Windows;
54
using Rubberduck.AddRemoveReferences;

Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBProject.cs

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5-
using System.Linq;
65
using System.Runtime.InteropServices;
76
using System.Text.RegularExpressions;
87
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
@@ -193,15 +192,9 @@ public string ProjectDisplayName
193192
_displayName = DisplayNameFromWindowCaption();
194193
}
195194

196-
if (string.IsNullOrEmpty(_displayName)
197-
|| _displayName.EndsWith("..."))
195+
if (string.IsNullOrEmpty(_displayName))
198196
{
199-
var nameFromBuildFileName = DisplayNameFromBuildFileName();
200-
if (!string.IsNullOrEmpty(nameFromBuildFileName)
201-
&& nameFromBuildFileName.Length > _displayName.Length - 3) //Otherwise, we got more of the name from the previous attempt.
202-
{
203-
_displayName = nameFromBuildFileName;
204-
}
197+
_displayName = DisplayNameFromBuildFileName();
205198
}
206199

207200
return _displayName;
@@ -221,11 +214,7 @@ private string DisplayNameFromBuildFileName()
221214
: pseudoDllName.Substring(0, pseudoDllName.Length - 4);
222215
}
223216

224-
private static readonly Regex CaptionProjectRegex = new Regex(@"^(?:[^-]+)(?:\s-\s)(?<project>.+)(?:\s-\s.*)?$");
225-
private static readonly Regex OpenModuleRegex = new Regex(@"^(?<project>.+)(?<module>\s-\s\[.*\((Code|UserForm)\)\])$");
226-
private static readonly Regex PartialOpenModuleRegex = new Regex(@"^(?<project>.+)(\s-\s\[)");
227-
private static readonly Regex NearlyOnlyProject = new Regex(@"^(?<project>.+)(\s-?\s?)$");
228-
217+
private static readonly Regex CaptionProjectRegex = new Regex(@"^(?<project>.+)(?:\s-\s)Microsoft Visual");
229218
private string DisplayNameFromWindowCaption()
230219
{
231220
using (var vbe = VBE)
@@ -240,62 +229,20 @@ private string DisplayNameFromWindowCaption()
240229
}
241230

242231
var caption = mainWindow.Caption;
243-
if (caption.Length > 99)
232+
if (CaptionProjectRegex.IsMatch(caption))
244233
{
245-
//The value returned will be truncated at character 99 and the rest is garbage due to a bug in the VBE API.
246-
caption = caption.Substring(0, 99);
247-
248-
if (CaptionProjectRegex.IsMatch(caption))
249-
{
250-
var projectRelatedPartOfCaption = CaptionProjectRegex
251-
.Matches(caption)[0]
252-
.Groups["project"]
253-
.Value;
254-
255-
if (PartialOpenModuleRegex.IsMatch(projectRelatedPartOfCaption))
256-
{
257-
return PartialOpenModuleRegex
258-
.Matches(projectRelatedPartOfCaption)[0]
259-
.Groups["project"]
260-
.Value;
261-
}
262-
263-
if (NearlyOnlyProject.IsMatch(projectRelatedPartOfCaption))
264-
{
265-
return NearlyOnlyProject
266-
.Matches(projectRelatedPartOfCaption)[0]
267-
.Groups["project"]
268-
.Value;
269-
}
270-
271-
return $"{projectRelatedPartOfCaption}...";
272-
}
273-
}
274-
else
275-
{
276-
if (CaptionProjectRegex.IsMatch(caption))
277-
{
278-
var projectRelatedPartOfCaption = CaptionProjectRegex
279-
.Matches(caption)[0]
280-
.Groups["project"]
281-
.Value;
282-
283-
if (OpenModuleRegex.IsMatch(projectRelatedPartOfCaption))
284-
{
285-
return OpenModuleRegex
286-
.Matches(projectRelatedPartOfCaption)[0]
287-
.Groups["project"]
288-
.Value;
289-
}
290-
}
234+
return CaptionProjectRegex
235+
.Matches(caption)[0]
236+
.Groups["project"]
237+
.Value;
291238
}
239+
240+
return string.Empty;
292241
}
293242
catch
294243
{
295244
return string.Empty;
296245
}
297-
298-
return string.Empty;
299246
}
300247
}
301248

0 commit comments

Comments
 (0)