2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
- using System . Linq ;
6
5
using System . Runtime . InteropServices ;
7
6
using System . Text . RegularExpressions ;
8
7
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
@@ -193,15 +192,9 @@ public string ProjectDisplayName
193
192
_displayName = DisplayNameFromWindowCaption ( ) ;
194
193
}
195
194
196
- if ( string . IsNullOrEmpty ( _displayName )
197
- || _displayName . EndsWith ( "..." ) )
195
+ if ( string . IsNullOrEmpty ( _displayName ) )
198
196
{
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 ( ) ;
205
198
}
206
199
207
200
return _displayName ;
@@ -221,11 +214,7 @@ private string DisplayNameFromBuildFileName()
221
214
: pseudoDllName . Substring ( 0 , pseudoDllName . Length - 4 ) ;
222
215
}
223
216
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" ) ;
229
218
private string DisplayNameFromWindowCaption ( )
230
219
{
231
220
using ( var vbe = VBE )
@@ -240,62 +229,20 @@ private string DisplayNameFromWindowCaption()
240
229
}
241
230
242
231
var caption = mainWindow . Caption ;
243
- if ( caption . Length > 99 )
232
+ if ( CaptionProjectRegex . IsMatch ( caption ) )
244
233
{
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 ;
291
238
}
239
+
240
+ return string . Empty ;
292
241
}
293
242
catch
294
243
{
295
244
return string . Empty ;
296
245
}
297
-
298
- return string . Empty ;
299
246
}
300
247
}
301
248
0 commit comments