From 47fa073b400a45242c2ee2e71a070e2efc808116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Mon, 12 May 2025 22:45:27 +0200 Subject: [PATCH] New icon for annotated tag, to distinguish from lightweight tag The new icon is applied everywhere - except for Models.Decorator and Models.Filter, since these are not (yet) updated to discern the specific tag type. --- src/Commands/QueryTags.cs | 13 +++++----- src/Models/Tag.cs | 9 +++++++ src/Resources/Icons.axaml | 1 + src/ViewModels/Histories.cs | 2 +- src/Views/Archive.axaml | 3 ++- src/Views/CreateBranch.axaml | 3 ++- src/Views/DeleteTag.axaml | 3 ++- src/Views/Merge.axaml | 3 ++- src/Views/PushTag.axaml | 3 ++- src/Views/TagsView.axaml | 5 +--- src/Views/TagsView.axaml.cs | 48 +++++++++++++++++++++++++++++++++++- 11 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/Commands/QueryTags.cs b/src/Commands/QueryTags.cs index b0264beb..2952b840 100644 --- a/src/Commands/QueryTags.cs +++ b/src/Commands/QueryTags.cs @@ -11,7 +11,7 @@ namespace SourceGit.Commands Context = repo; WorkingDirectory = repo; - Args = $"tag -l --format=\"{_boundary}%(refname)%00%(objectname)%00%(*objectname)%00%(creatordate:unix)%00%(contents:subject)%0a%0a%(contents:body)\""; + Args = $"tag -l --format=\"{_boundary}%(refname)%00%(objecttype)%00%(objectname)%00%(*objectname)%00%(creatordate:unix)%00%(contents:subject)%0a%0a%(contents:body)\""; } public List Result() @@ -25,16 +25,17 @@ namespace SourceGit.Commands foreach (var record in records) { var subs = record.Split('\0', StringSplitOptions.None); - if (subs.Length != 5) + if (subs.Length != 6) continue; - var name = subs[0].Substring(10); - var message = subs[4].Trim(); + var name = subs[0].Substring(10); // Skip the prefix "refs/tags/" + var message = subs[5].Trim(); tags.Add(new Models.Tag() { Name = name, - SHA = string.IsNullOrEmpty(subs[2]) ? subs[1] : subs[2], - CreatorDate = ulong.Parse(subs[3]), + Type = (subs[1] == "tag") ? Models.TagType.Annotated : Models.TagType.Lightweight, // tag/commit + SHA = string.IsNullOrEmpty(subs[3]) ? subs[2] : subs[3], + CreatorDate = ulong.Parse(subs[4]), Message = string.IsNullOrEmpty(message) ? name : message, }); } diff --git a/src/Models/Tag.cs b/src/Models/Tag.cs index 51681d93..d75c138f 100644 --- a/src/Models/Tag.cs +++ b/src/Models/Tag.cs @@ -9,9 +9,16 @@ namespace SourceGit.Models NameInDescending, } + public enum TagType + { + Lightweight = 0, + Annotated, + } + public class Tag : ObservableObject { public string Name { get; set; } = string.Empty; + public TagType Type { get; set; } = TagType.Lightweight; public string SHA { get; set; } = string.Empty; public ulong CreatorDate { get; set; } = 0; public string Message { get; set; } = string.Empty; @@ -23,5 +30,7 @@ namespace SourceGit.Models } private FilterMode _filterMode = FilterMode.None; + + public bool IsLightweight => (Type == TagType.Lightweight); } } diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index 9da3a51e..d1b12b36 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -123,6 +123,7 @@ M875 128h-725A107 107 0 0043 235v555A107 107 0 00149 896h725a107 107 0 00107-107v-555A107 107 0 00875 128zm-115 640h-183v-58l25-3c15 0 19-8 14-24l-22-61H419l-28 82 39 2V768h-166v-58l18-3c18-2 22-11 26-24l125-363-40-4V256h168l160 448 39 3zM506 340l-72 218h145l-71-218h-2z M177 156c-22 5-33 17-36 37c-10 57-33 258-13 278l445 445c23 23 61 23 84 0l246-246c23-23 23-61 0-84l-445-445C437 120 231 145 177 156zM331 344c-26 26-69 26-95 0c-26-26-26-69 0-95s69-26 95 0C357 276 357 318 331 344z M683 537h-144v-142h-142V283H239a44 44 0 00-41 41v171a56 56 0 0014 34l321 321a41 41 0 0058 0l174-174a41 41 0 000-58zm-341-109a41 41 0 110-58a41 41 0 010 58zM649 284V142h-69v142h-142v68h142v142h69v-142h142v-68h-142z + M 177 156 c -22 5 -33 17 -36 37 c -10 57 -33 258 -13 278 l 445 445 c 23 23 61 23 84 0 l 246 -246 c 23 -23 23 -61 0 -84 l -445 -445 c -21 -21 -227 4 -281 15 z M 331 344 c -26 26 -69 26 -95 0 c -26 -26 -26 -69 0 -95 s 69 -26 95 0 c 26 27 26 69 0 95 m 115 -15 l 30 -30 l 340 340 l -60 60 l -340 -340 l 30 -30 m -125 125 l 30 -30 l 340 340 l -60 60 l -340 -340 l 30 -30 z M996 452 572 28A96 96 0 00504 0H96C43 0 0 43 0 96v408a96 96 0 0028 68l424 424c37 37 98 37 136 0l408-408c37-37 37-98 0-136zM224 320c-53 0-96-43-96-96s43-96 96-96 96 43 96 96-43 96-96 96zm1028 268L844 996c-37 37-98 37-136 0l-1-1L1055 647c34-34 53-79 53-127s-19-93-53-127L663 0h97a96 96 0 0168 28l424 424c37 37 37 98 0 136z M765 118 629 239l-16 137-186 160 54 59 183-168 144 4 136-129 47-43-175-12L827 67zM489 404c-66 0-124 55-124 125s54 121 124 121c66 0 120-55 120-121H489l23-121c-8-4-16-4-23-4zM695 525c0 114-93 207-206 207s-206-94-206-207 93-207 206-207c16 0 27 0 43 4l43-207c-27-4-54-8-85-8-229 0-416 188-416 419s187 419 416 419c225 0 408-180 416-403v-12l-210-4z M144 112h736c18 0 32 14 32 32v736c0 18-14 32-32 32H144c-18 0-32-14-32-32V144c0-18 14-32 32-32zm112 211v72a9 9 0 003 7L386 509 259 615a9 9 0 00-3 7v72a9 9 0 0015 7L493 516a9 9 0 000-14l-222-186a9 9 0 00-15 7zM522 624a10 10 0 00-10 10v60a10 10 0 0010 10h237a10 10 0 0010-10v-60a10 10 0 00-10-10H522z diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 555954d9..be844e50 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -1165,7 +1165,7 @@ namespace SourceGit.ViewModels { var submenu = new MenuItem(); submenu.Header = tag.Name; - submenu.Icon = App.CreateMenuIcon("Icons.Tag"); + submenu.Icon = App.CreateMenuIcon(tag.IsLightweight ? "Icons.Tag" : "Icons.Tag.Annotated"); submenu.MinWidth = 200; FillTagVisibilityMenu(submenu, tag); diff --git a/src/Views/Archive.axaml b/src/Views/Archive.axaml index e9d0ad02..f1737e1c 100644 --- a/src/Views/Archive.axaml +++ b/src/Views/Archive.axaml @@ -37,7 +37,8 @@ - + + diff --git a/src/Views/CreateBranch.axaml b/src/Views/CreateBranch.axaml index e77f8751..9550182f 100644 --- a/src/Views/CreateBranch.axaml +++ b/src/Views/CreateBranch.axaml @@ -38,7 +38,8 @@ - + + diff --git a/src/Views/DeleteTag.axaml b/src/Views/DeleteTag.axaml index c5b4f507..02deb34b 100644 --- a/src/Views/DeleteTag.axaml +++ b/src/Views/DeleteTag.axaml @@ -17,7 +17,8 @@ Text="{DynamicResource Text.DeleteTag.Tag}"/> - + + diff --git a/src/Views/Merge.axaml b/src/Views/Merge.axaml index 33d07f02..ea4fc304 100644 --- a/src/Views/Merge.axaml +++ b/src/Views/Merge.axaml @@ -36,7 +36,8 @@ - + + diff --git a/src/Views/PushTag.axaml b/src/Views/PushTag.axaml index 1181e4e8..3f074108 100644 --- a/src/Views/PushTag.axaml +++ b/src/Views/PushTag.axaml @@ -18,7 +18,8 @@ Text="{DynamicResource Text.PushTag.Tag}"/> - + + diff --git a/src/Views/TagsView.axaml b/src/Views/TagsView.axaml index 53b325d3..b736c83b 100644 --- a/src/Views/TagsView.axaml +++ b/src/Views/TagsView.axaml @@ -72,10 +72,7 @@ - + NodeProperty = + AvaloniaProperty.Register(nameof(Node)); + + public Models.Tag Node + { + get => GetValue(NodeProperty); + set => SetValue(NodeProperty, value); + } + + static TagIcon() + { + NodeProperty.Changed.AddClassHandler((icon, _) => icon.UpdateContent()); + } + + private void UpdateContent() + { + var node = Node; + if (node == null) + { + Content = null; + return; + } + + CreateContent(new Thickness(8, 0, 0, 0), node.IsLightweight ? "Icons.Tag" : "Icons.Tag.Annotated"); + } + + private void CreateContent(Thickness margin, string iconKey) + { + var geo = this.FindResource(iconKey) as StreamGeometry; + if (geo == null) + return; + + Content = new Avalonia.Controls.Shapes.Path() + { + Width = 12, + Height = 12, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Center, + Margin = margin, + Data = geo, + }; + } + } + public partial class TagsView : UserControl { public static readonly StyledProperty ShowTagsAsTreeProperty =