Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ViewModels/EditRepositoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override Task<bool> Sure()
{
Preferences.Instance.SortByRenamedNode(_node);
Welcome.Instance.Refresh();
App.GetLauncher().RefreshTabDisplayNames();
}

return Task.FromResult(true);
Expand Down
50 changes: 50 additions & 0 deletions src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

Expand Down Expand Up @@ -244,6 +245,7 @@ public void CloseTab(LauncherPage page)

CloseRepositoryInTab(page);
Pages.RemoveAt(removeIdx);
RefreshTabDisplayNames();
GC.Collect();
}

Expand All @@ -266,6 +268,7 @@ public void CloseOtherTabs()

_activeWorkspace.ActiveIdx = 0;
_ignoreIndexChange = false;
RefreshTabDisplayNames();
GC.Collect();
}

Expand All @@ -281,6 +284,7 @@ public void CloseRightTabs()
}

_ignoreIndexChange = false;
RefreshTabDisplayNames();
GC.Collect();
}

Expand Down Expand Up @@ -371,6 +375,8 @@ public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)
PostActivePageChanged();
else
ActivePage = page;

RefreshTabDisplayNames();
}

public void OpenSubRepository(LauncherPage ownerPage, string fullpath)
Expand Down Expand Up @@ -437,6 +443,50 @@ public void OpenSubRepository(LauncherPage ownerPage, string fullpath)
Pages.Insert(idxOfOwner + 1, page);
_activeWorkspace.Repositories.Insert(idxOfOwner + 1, normalizedPath);
ActivePage = page;

RefreshTabDisplayNames();
}

public void RefreshTabDisplayNames()
{
var nameUsages = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
foreach (var page in Pages)
{
if (page.Node is not { IsRepository: true })
continue;

nameUsages.TryGetValue(page.Node.Name, out var count);
nameUsages[page.Node.Name] = count + 1;
}

foreach (var page in Pages)
{
if (page.Node is not { IsRepository: true } node)
continue;

nameUsages.TryGetValue(node.Name, out var count);
if (count > 1)
{
var parent = GetParentFolderName(node.Id);
page.DisplayName = string.IsNullOrEmpty(parent) ? node.Name : $"{node.Name} ({parent})";
}
else
{
page.DisplayName = node.Name;
}
}
}

private static string GetParentFolderName(string repoPath)
{
var normalized = repoPath.Replace('\\', '/').TrimEnd('/');
var idx = normalized.LastIndexOf('/');
if (idx < 0)
return string.Empty;

var parent = normalized.Substring(0, idx).TrimEnd('/');
idx = parent.LastIndexOf('/');
return idx < 0 ? parent : parent.Substring(idx + 1);
}

private void DispatchNotification(Models.Notification notification)
Expand Down
8 changes: 8 additions & 0 deletions src/ViewModels/LauncherPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public Popup Popup
set => SetProperty(ref _popup, value);
}

public string DisplayName
{
get => _displayName;
set => SetProperty(ref _displayName, value);
}

public AvaloniaList<Models.Notification> Notifications
{
get;
Expand All @@ -50,6 +56,7 @@ public LauncherPage(RepositoryNode node, Repository repo)
{
_node = node;
_data = repo;
_displayName = node.Name;
}

public void ClearNotifications()
Expand Down Expand Up @@ -124,6 +131,7 @@ public void TerminatePopup()

private RepositoryNode _node = null;
private object _data = null;
private string _displayName = string.Empty;
private Models.DirtyState _dirtyState = Models.DirtyState.None;
private Popup _popup = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Views/LauncherTabBar.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
VerticalAlignment="Center"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
TextAlignment="Center"
Text="{Binding Node.Name}"
Text="{Binding DisplayName}"
IsHitTestVisible="False"/>
</Grid>

Expand Down