Skip to content

Commit 1931826

Browse files
committed
enhance: show parent folder name on tabs for repositories with duplicate names
1 parent e42fa32 commit 1931826

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/ViewModels/EditRepositoryNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public override Task<bool> Sure()
4848
{
4949
Preferences.Instance.SortByRenamedNode(_node);
5050
Welcome.Instance.Refresh();
51+
App.GetLauncher().RefreshTabDisplayNames();
5152
}
5253

5354
return Task.FromResult(true);

src/ViewModels/Launcher.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using 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)

src/ViewModels/LauncherPage.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public Popup Popup
3131
set => SetProperty(ref _popup, value);
3232
}
3333

34+
public string DisplayName
35+
{
36+
get => _displayName;
37+
set => SetProperty(ref _displayName, value);
38+
}
39+
3440
public AvaloniaList<Models.Notification> Notifications
3541
{
3642
get;
@@ -50,6 +56,7 @@ public LauncherPage(RepositoryNode node, Repository repo)
5056
{
5157
_node = node;
5258
_data = repo;
59+
_displayName = node.Name;
5360
}
5461

5562
public void ClearNotifications()
@@ -124,6 +131,7 @@ public void TerminatePopup()
124131

125132
private RepositoryNode _node = null;
126133
private object _data = null;
134+
private string _displayName = string.Empty;
127135
private Models.DirtyState _dirtyState = Models.DirtyState.None;
128136
private Popup _popup = null;
129137
}

src/Views/LauncherTabBar.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
VerticalAlignment="Center"
111111
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
112112
TextAlignment="Center"
113-
Text="{Binding Node.Name}"
113+
Text="{Binding DisplayName}"
114114
IsHitTestVisible="False"/>
115115
</Grid>
116116

0 commit comments

Comments
 (0)