feature: add a button to see which branches and tags that contains selected commit (#388)

This commit is contained in:
leo 2024-08-23 16:52:55 +08:00
parent fcc8a41ad1
commit 6ab0900b20
No known key found for this signature in database
14 changed files with 171 additions and 18 deletions

View file

@ -57,12 +57,16 @@
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
<SelectableTextBlock Classes="primary"
Text="{Binding SHA}"
Margin="12,0,0,0"
Margin="12,0,4,0"
VerticalAlignment="Center"/>
<Button Classes="icon_button" Cursor="Hand" Click="OnOpenWebLink" IsVisible="{Binding #ThisControl.WebLinks, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnOpenWebLink" IsVisible="{Binding #ThisControl.WebLinks, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<Path Width="12" Height="12" Data="{StaticResource Icons.Link}" Fill="{DynamicResource Brush.Link}"/>
</Button>
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnOpenContainsIn" IsVisible="{Binding #ThisControl.SupportsContainsIn}" ToolTip.Tip="{DynamicResource Text.CommitDetail.Info.ContainsIn}">
<Path Width="12" Height="12" Data="{StaticResource Icons.Relation}"/>
</Button>
</StackPanel>
@ -98,7 +102,8 @@
LabelForeground="{DynamicResource Brush.DecoratorFG}"
FontFamily="{DynamicResource Fonts.Monospace}"
FontSize="10"
VerticalAlignment="Center"/>
VerticalAlignment="Center"
Refs="{Binding Decorators}"/>
</Border>
<!-- Messages -->

View file

@ -1,3 +1,5 @@
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
@ -17,6 +19,15 @@ namespace SourceGit.Views
set => SetValue(MessageProperty, value);
}
public static readonly StyledProperty<bool> SupportsContainsInProperty =
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(SupportsContainsIn));
public bool SupportsContainsIn
{
get => GetValue(SupportsContainsInProperty);
set => SetValue(SupportsContainsInProperty, value);
}
public static readonly StyledProperty<AvaloniaList<Models.CommitLink>> WebLinksProperty =
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.CommitLink>>(nameof(WebLinks));
@ -74,6 +85,19 @@ namespace SourceGit.Views
e.Handled = true;
}
private void OnOpenContainsIn(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail detail && sender is Button button)
{
var tracking = new CommitRelationTracking(detail);
var flyout = new Flyout();
flyout.Content = tracking;
flyout.ShowAt(button);
}
e.Handled = true;
}
private void OnParentSHAPressed(object sender, PointerPressedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha })

View file

@ -21,6 +21,7 @@
<!-- Base Information -->
<v:CommitBaseInfo Content="{Binding Commit}"
Message="{Binding FullMessage}"
SupportsContainsIn="True"
WebLinks="{Binding WebLinks}"
IssueTrackerRules="{Binding IssueTrackerRules}"/>

View file

@ -17,6 +17,15 @@ namespace SourceGit.Views
public bool IsTag { get; set; } = false;
}
public static readonly StyledProperty<List<Models.Decorator>> RefsProperty =
AvaloniaProperty.Register<CommitRefsPresenter, List<Models.Decorator>>(nameof(Refs));
public List<Models.Decorator> Refs
{
get => GetValue(RefsProperty);
set => SetValue(RefsProperty, value);
}
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
TextBlock.FontFamilyProperty.AddOwner<CommitRefsPresenter>();
@ -85,7 +94,8 @@ namespace SourceGit.Views
AffectsMeasure<CommitRefsPresenter>(
FontFamilyProperty,
FontSizeProperty,
LabelForegroundProperty);
LabelForegroundProperty,
RefsProperty);
AffectsRender<CommitRefsPresenter>(
IconBackgroundProperty,
@ -121,17 +131,12 @@ namespace SourceGit.Views
}
}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
InvalidateMeasure();
}
protected override Size MeasureOverride(Size availableSize)
{
_items.Clear();
if (DataContext is Models.Commit commit && commit.HasDecorators)
var refs = Refs;
if (refs != null && refs.Count > 0)
{
var typeface = new Typeface(FontFamily);
var typefaceBold = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
@ -139,7 +144,7 @@ namespace SourceGit.Views
var labelSize = FontSize;
var requiredWidth = 0.0;
foreach (var decorator in commit.Decorators)
foreach (var decorator in refs)
{
var isHead = decorator.Type == Models.DecoratorType.CurrentBranchHead ||
decorator.Type == Models.DecoratorType.CurrentCommitHead;

View file

@ -0,0 +1,36 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CommitRelationTracking">
<Grid RowDefinitions="Auto,Auto,Auto">
<TextBlock Grid.Row="0" Classes="info_label" Text="COMMIT CONTAINS IN" HorizontalAlignment="Center"/>
<Rectangle Grid.Row="1" Height="1" HorizontalAlignment="Stretch" Margin="0,8" Fill="{DynamicResource Brush.Border2}"/>
<ScrollViewer Grid.Row="2" MinWidth="300" MaxWidth="500" MaxHeight="200" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="Container">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="m:Decorator">
<Border Height="20" Margin="0,4,6,0" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" CornerRadius="12">
<StackPanel Orientation="Horizontal" Margin="8,0" VerticalAlignment="Center">
<Path Width="10" Height="10" Data="{StaticResource Icons.Branch}" IsVisible="{Binding !IsTag}"/>
<Path Width="10" Height="10" Data="{StaticResource Icons.Tag}" IsVisible="{Binding IsTag}"/>
<TextBlock Classes="primary" Text="{Binding Name}" Margin="2,0,0,0"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<v:LoadingIcon x:Name="LoadingIcon" Grid.Row="2" HorizontalAlignment="Center" Margin="0,16" Width="24" Height="24" IsVisible="False"/>
</Grid>
</UserControl>

View file

@ -0,0 +1,32 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
namespace SourceGit.Views
{
public partial class CommitRelationTracking : UserControl
{
public CommitRelationTracking()
{
InitializeComponent();
}
public CommitRelationTracking(ViewModels.CommitDetail detail)
{
InitializeComponent();
LoadingIcon.IsVisible = true;
Task.Run(() =>
{
var containsIn = detail.GetRefsContainsThisCommit();
Dispatcher.UIThread.Invoke(() =>
{
Container.ItemsSource = containsIn;
LoadingIcon.IsVisible = false;
});
});
}
}
}

View file

@ -67,15 +67,15 @@
BehindBrush="{DynamicResource Brush.FG1}"
VerticalAlignment="Center"/>
<v:CommitRefsPresenter IsVisible="{Binding HasDecorators}"
IconBackground="{DynamicResource Brush.DecoratorIconBG}"
<v:CommitRefsPresenter IconBackground="{DynamicResource Brush.DecoratorIconBG}"
IconForeground="{DynamicResource Brush.DecoratorIcon}"
BranchNameBackground="{DynamicResource Brush.DecoratorBranch}"
TagNameBackground="{DynamicResource Brush.DecoratorTag}"
LabelForeground="{DynamicResource Brush.DecoratorFG}"
FontFamily="{DynamicResource Fonts.Monospace}"
FontSize="10"
VerticalAlignment="Center"/>
VerticalAlignment="Center"
Refs="{Binding Decorators}"/>
<v:CommitSubjectPresenter Classes="primary"
Subject="{Binding Subject}"