initial work on allowing navigation by clicking on commits in the blame window

This commit is contained in:
Johan Wångsell 2025-06-05 11:04:20 +02:00
parent 06a77502bc
commit ab605f6e28
3 changed files with 109 additions and 11 deletions

View file

@ -42,8 +42,24 @@
</Grid>
<!-- File -->
<Border Grid.Row="1" Padding="8,0">
<TextBlock Text="{Binding Title}" VerticalAlignment="Center"/>
<Border Grid.Row="1" Padding="8,0" >
<Grid>
<TextBlock Text="{Binding Title}" VerticalAlignment="Center"/>
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
<Button Classes="icon_button"
IsEnabled="{Binding CanMoveBack}"
Width="28"
Click="HistoryBack">
<Path Width="12" Height="12" Stretch="Uniform" Data="{StaticResource Icons.TriangleLeft}"/>
</Button>
<Button Classes="icon_button"
IsEnabled="{Binding CanMoveForward}"
Width="28"
Click="HistoryForward">
<Path Width="12" Height="12" Stretch="Uniform" Data="{StaticResource Icons.TriangleRight}"/>
</Button>
</StackPanel>
</Grid>
</Border>
<!-- Body -->

View file

@ -61,6 +61,7 @@ namespace SourceGit.Views
typeface,
_editor.FontSize,
Brushes.DarkOrange);
context.DrawText(shaLink, new Point(x, y));
context.DrawLine(underlinePen, new Point(x, y + shaLink.Baseline + 2), new Point(x + shaLink.Width, y + shaLink.Baseline + 2));
x += shaLink.Width + 8;
@ -225,7 +226,7 @@ namespace SourceGit.Views
{
if (DataContext is ViewModels.Blame blame)
{
blame.NavigateToCommit(info.CommitSHA);
blame.NavigateToCommit(info.CommitSHA, true);
}
e.Handled = true;
@ -433,6 +434,8 @@ namespace SourceGit.Views
public Blame()
{
InitializeComponent();
AddHandler(PointerReleasedEvent, MouseUpHandler, handledEventsToo: true);
}
protected override void OnClosed(EventArgs e)
@ -440,5 +443,32 @@ namespace SourceGit.Views
base.OnClosed(e);
GC.Collect();
}
private void HistoryBack(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.Blame blame)
{
blame.Back();
}
}
private void HistoryForward(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.Blame blame)
{
blame.Forward();
}
}
private void MouseUpHandler(object sender, PointerReleasedEventArgs e)
{
if (e.InitialPressMouseButton == MouseButton.XButton1)
{
HistoryBack(null, null);
}
else if (e.InitialPressMouseButton == MouseButton.XButton2)
{
HistoryForward(null, null);
}
}
}
}