diff --git a/src/Commands/QueryTags.cs b/src/Commands/QueryTags.cs index 3aa20dc2..73f63d8b 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 --sort=-creatordate --format=\"{_boundary}%(refname)%00%(objectname)%00%(*objectname)%00%(contents:subject)%0a%0a%(contents:body)\""; + Args = $"tag -l --format=\"{_boundary}%(refname)%00%(objectname)%00%(*objectname)%00%(creatordate:unix)%00%(contents:subject)%0a%0a%(contents:body)\""; } public List Result() @@ -25,14 +25,15 @@ namespace SourceGit.Commands foreach (var record in records) { var subs = record.Split('\0', StringSplitOptions.None); - if (subs.Length != 4) + if (subs.Length != 5) continue; - var message = subs[3].Trim(); + var message = subs[4].Trim(); tags.Add(new Models.Tag() { Name = subs[0].Substring(10), SHA = string.IsNullOrEmpty(subs[2]) ? subs[1] : subs[2], + CreatorDate = ulong.Parse(subs[3]), Message = string.IsNullOrEmpty(message) ? null : message, }); } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 4ade5096..f63a19fc 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -38,6 +38,12 @@ namespace SourceGit.Models set; } = false; + public TagSortMode TagSortMode + { + get; + set; + } = TagSortMode.CreatorDate; + public bool IncludeUntrackedInLocalChanges { get; diff --git a/src/Models/Tag.cs b/src/Models/Tag.cs index 2e8f2c8e..51681d93 100644 --- a/src/Models/Tag.cs +++ b/src/Models/Tag.cs @@ -2,10 +2,18 @@ namespace SourceGit.Models { + public enum TagSortMode + { + CreatorDate = 0, + NameInAscending, + NameInDescending, + } + public class Tag : ObservableObject { public string Name { get; set; } = string.Empty; public string SHA { get; set; } = string.Empty; + public ulong CreatorDate { get; set; } = 0; public string Message { get; set; } = string.Empty; public FilterMode FilterMode diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 433716b4..81bbbaa6 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -590,6 +590,10 @@ UPDATE SUBMODULE TAGS NEW TAG + By Creator Date + By Name (Ascending) + By Name (Descending) + Sort Open in Terminal Use relative time in histories WORKTREES diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 51c48f9d..9f2927fe 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -594,6 +594,10 @@ 更新子模块 标签列表 新建标签 + 按创建时间 + 按名称(升序) + 按名称(降序) + 排序 在终端中打开 在提交列表中使用相对时间 工作树列表 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 420750ed..93b37257 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -593,6 +593,10 @@ 更新子模組 標籤列表 新增標籤 + 依建立時間 + 依名稱升序 + 依名稱降序 + 排序 在終端機中開啟 在提交清單中使用相對時間 工作區列表 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 862dfa94..5d84d979 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -141,6 +141,20 @@ namespace SourceGit.ViewModels } } + public Models.TagSortMode TagSortMode + { + get => _settings.TagSortMode; + set + { + if (value != _settings.TagSortMode) + { + _settings.TagSortMode = value; + OnPropertyChanged(); + VisibleTags = BuildVisibleTags(); + } + } + } + public string Filter { get => _filter; @@ -2131,6 +2145,19 @@ namespace SourceGit.ViewModels private List BuildVisibleTags() { + switch (_settings.TagSortMode) + { + case Models.TagSortMode.CreatorDate: + _tags.Sort((l, r) => r.CreatorDate.CompareTo(l.CreatorDate)); + break; + case Models.TagSortMode.NameInAscending: + _tags.Sort((l, r) => Models.NumericSort.Compare(l.Name, r.Name)); + break; + default: + _tags.Sort((l, r) => Models.NumericSort.Compare(r.Name, l.Name)); + break; + } + var visible = new List(); if (string.IsNullOrEmpty(_filter)) { diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 49f1034e..e3f5a9e0 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -231,7 +231,7 @@ - + @@ -240,8 +240,16 @@ Width="14" IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowTagsAsTree, Mode=TwoWay}" ToolTip.Tip="{DynamicResource Text.Repository.ShowTagsAsTree}"/> - +