11using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
34using System . Text ;
45
@@ -244,6 +245,7 @@ public void CloseTab(LauncherPage page)
244245
245246 CloseRepositoryInTab ( page ) ;
246247 Pages . RemoveAt ( removeIdx ) ;
248+ RefreshTabDisplayNames ( ) ;
247249 GC . Collect ( ) ;
248250 }
249251
@@ -266,6 +268,7 @@ public void CloseOtherTabs()
266268
267269 _activeWorkspace . ActiveIdx = 0 ;
268270 _ignoreIndexChange = false ;
271+ RefreshTabDisplayNames ( ) ;
269272 GC . Collect ( ) ;
270273 }
271274
@@ -281,6 +284,7 @@ public void CloseRightTabs()
281284 }
282285
283286 _ignoreIndexChange = false ;
287+ RefreshTabDisplayNames ( ) ;
284288 GC . Collect ( ) ;
285289 }
286290
@@ -371,6 +375,8 @@ public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)
371375 PostActivePageChanged ( ) ;
372376 else
373377 ActivePage = page ;
378+
379+ RefreshTabDisplayNames ( ) ;
374380 }
375381
376382 public void OpenSubRepository ( LauncherPage ownerPage , string fullpath )
@@ -437,6 +443,50 @@ public void OpenSubRepository(LauncherPage ownerPage, string fullpath)
437443 Pages . Insert ( idxOfOwner + 1 , page ) ;
438444 _activeWorkspace . Repositories . Insert ( idxOfOwner + 1 , normalizedPath ) ;
439445 ActivePage = page ;
446+
447+ RefreshTabDisplayNames ( ) ;
448+ }
449+
450+ public void RefreshTabDisplayNames ( )
451+ {
452+ var nameUsages = new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase ) ;
453+ foreach ( var page in Pages )
454+ {
455+ if ( page . Node is not { IsRepository : true } )
456+ continue ;
457+
458+ nameUsages . TryGetValue ( page . Node . Name , out var count ) ;
459+ nameUsages [ page . Node . Name ] = count + 1 ;
460+ }
461+
462+ foreach ( var page in Pages )
463+ {
464+ if ( page . Node is not { IsRepository : true } node )
465+ continue ;
466+
467+ nameUsages . TryGetValue ( node . Name , out var count ) ;
468+ if ( count > 1 )
469+ {
470+ var parent = GetParentFolderName ( node . Id ) ;
471+ page . DisplayName = string . IsNullOrEmpty ( parent ) ? node . Name : $ "{ node . Name } ({ parent } )";
472+ }
473+ else
474+ {
475+ page . DisplayName = node . Name ;
476+ }
477+ }
478+ }
479+
480+ private static string GetParentFolderName ( string repoPath )
481+ {
482+ var normalized = repoPath . Replace ( '\\ ' , '/' ) . TrimEnd ( '/' ) ;
483+ var idx = normalized . LastIndexOf ( '/' ) ;
484+ if ( idx < 0 )
485+ return string . Empty ;
486+
487+ var parent = normalized . Substring ( 0 , idx ) . TrimEnd ( '/' ) ;
488+ idx = parent . LastIndexOf ( '/' ) ;
489+ return idx < 0 ? parent : parent . Substring ( idx + 1 ) ;
440490 }
441491
442492 private void DispatchNotification ( Models . Notification notification )
0 commit comments