feature: add a button to switch tag sort method (creatordate/name asc/name des) (#865)

This commit is contained in:
leo 2025-01-06 16:16:27 +08:00
parent 84721a7258
commit 08a128cd87
No known key found for this signature in database
9 changed files with 112 additions and 6 deletions

View file

@ -231,7 +231,7 @@
<!-- Tags -->
<ToggleButton Grid.Row="4" Classes="group_expander" IsChecked="{Binding IsTagGroupExpanded, Mode=TwoWay}">
<Grid ColumnDefinitions="16,Auto,*,Auto,Auto">
<Grid ColumnDefinitions="16,Auto,*,Auto,Auto,Auto">
<Path Grid.Column="0" Width="11" Height="11" Margin="2,1,0,0" HorizontalAlignment="Left" Data="{StaticResource Icons.Tags}" Fill="{DynamicResource Brush.FG2}"/>
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Tags}"/>
<TextBlock Grid.Column="2" Text="{Binding Tags, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
@ -240,8 +240,16 @@
Width="14"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowTagsAsTree, Mode=TwoWay}"
ToolTip.Tip="{DynamicResource Text.Repository.ShowTagsAsTree}"/>
<Button Grid.Column="4"
Classes="icon_button"
<Button Grid.Column="4"
Classes="icon_button"
Width="14"
Margin="8,0,0,0"
Click="OnOpenSortTagMenu"
ToolTip.Tip="{DynamicResource Text.Repository.Tags.Sort}">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Order}"/>
</Button>
<Button Grid.Column="5"
Classes="icon_button"
Width="14"
Margin="8,0"
Command="{Binding CreateNewTag}"

View file

@ -453,6 +453,50 @@ namespace SourceGit.Views
e.Handled = true;
}
private void OnOpenSortTagMenu(object sender, RoutedEventArgs e)
{
if (sender is Button button && DataContext is ViewModels.Repository repo)
{
var byCreatorDate = new MenuItem();
byCreatorDate.Header = App.Text("Repository.Tags.OrderByCreatorDate");
if (repo.TagSortMode == Models.TagSortMode.CreatorDate)
byCreatorDate.Icon = App.CreateMenuIcon("Icons.Check");
byCreatorDate.Click += (_, ev) =>
{
repo.TagSortMode = Models.TagSortMode.CreatorDate;
ev.Handled = true;
};
var byNameAsc = new MenuItem();
byNameAsc.Header = App.Text("Repository.Tags.OrderByNameAsc");
if (repo.TagSortMode == Models.TagSortMode.NameInAscending)
byNameAsc.Icon = App.CreateMenuIcon("Icons.Check");
byNameAsc.Click += (_, ev) =>
{
repo.TagSortMode = Models.TagSortMode.NameInAscending;
ev.Handled = true;
};
var byNameDes = new MenuItem();
byNameDes.Header = App.Text("Repository.Tags.OrderByNameDes");
if (repo.TagSortMode == Models.TagSortMode.NameInDescending)
byNameDes.Icon = App.CreateMenuIcon("Icons.Check");
byNameDes.Click += (_, ev) =>
{
repo.TagSortMode = Models.TagSortMode.NameInDescending;
ev.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(byCreatorDate);
menu.Items.Add(byNameAsc);
menu.Items.Add(byNameDes);
menu.Open(button);
}
e.Handled = true;
}
private void OnSkipInProgress(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.Repository repo)