From 6bf930a9e00cb473684b22c261e711a1b6640ba9 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 13 May 2025 22:50:10 +0800 Subject: [PATCH] feature: show tags count in tags tree (#1306) Signed-off-by: leo --- src/ViewModels/BranchTreeNode.cs | 12 ++++++++++-- src/ViewModels/TagCollection.cs | 8 ++++++++ src/Views/TagsView.axaml | 10 ++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index 1b735d41..130893ec 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -56,8 +56,16 @@ namespace SourceGit.ViewModels public string Tooltip { - get => Backend is Models.Branch b ? - b.FriendlyName : (Backend is Models.Remote r ? r.URL : null); + get + { + if (Backend is Models.Branch b) + return b.FriendlyName; + + if (Backend is Models.Remote r) + return r.URL; + + return null; + } } private Models.FilterMode _filterMode = Models.FilterMode.None; diff --git a/src/ViewModels/TagCollection.cs b/src/ViewModels/TagCollection.cs index 2f503a83..f05a727e 100644 --- a/src/ViewModels/TagCollection.cs +++ b/src/ViewModels/TagCollection.cs @@ -26,6 +26,7 @@ namespace SourceGit.ViewModels public Models.Tag Tag { get; private set; } = null; public TagTreeNodeToolTip ToolTip { get; private set; } = null; public List Children { get; private set; } = []; + public int Counter { get; set; } = 0; public bool IsFolder { @@ -38,6 +39,11 @@ namespace SourceGit.ViewModels set => SetProperty(ref _isExpanded, value); } + public string TagsCount + { + get => Counter > 0 ? $"({Counter})" : string.Empty; + } + public TagTreeNode(Models.Tag t, int depth) { FullPath = t.Name; @@ -52,6 +58,7 @@ namespace SourceGit.ViewModels FullPath = path; Depth = depth; IsExpanded = isExpanded; + Counter = 1; } public static List Build(IList tags, HashSet expaneded) @@ -77,6 +84,7 @@ namespace SourceGit.ViewModels if (folders.TryGetValue(folder, out var value)) { lastFolder = value; + lastFolder.Counter++; } else if (lastFolder == null) { diff --git a/src/Views/TagsView.axaml b/src/Views/TagsView.axaml index 94898bad..9bf1e653 100644 --- a/src/Views/TagsView.axaml +++ b/src/Views/TagsView.axaml @@ -34,7 +34,7 @@ - + @@ -59,8 +59,10 @@ + Margin="8,0,0,0"> + + + @@ -91,7 +93,7 @@ - +