Enable tooltips for the commit hashes when handling conflicts

Now you cna hover over the commit hash to see a tooltip like you can
for the parent hash in the commit information window
This commit is contained in:
Sebastian Parborg 2025-03-06 14:18:12 +01:00
parent e3cc987682
commit 09309ce86a
3 changed files with 72 additions and 2 deletions

View file

@ -821,6 +821,11 @@ namespace SourceGit.ViewModels
}
}
public Models.Commit GetCommitInfo(string sha)
{
return new Commands.QuerySingleCommit(_fullpath, sha).Result();
}
public void NavigateToCurrentHead()
{
if (_currentBranch != null)

View file

@ -216,7 +216,23 @@
Foreground="DarkOrange"
TextDecorations="Underline"
Cursor="Hand"
PointerPressed="OnPressedSHA"/>
PointerPressed="OnPressedSHA"
PointerEntered="OnSHAPointerEntered"
ToolTip.ShowDelay="0">
<TextBlock.DataTemplates>
<DataTemplate DataType="m:Commit">
<StackPanel MinWidth="400" Orientation="Vertical">
<Grid ColumnDefinitions="Auto,*,Auto">
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" Classes="primary" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
</Grid>
<TextBlock Classes="primary" Margin="0,8,0,0" Text="{Binding Subject}" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</TextBlock.DataTemplates>
</TextBlock>
</StackPanel>
</DataTemplate>
@ -235,7 +251,23 @@
Foreground="DarkOrange"
TextDecorations="Underline"
Cursor="Hand"
PointerPressed="OnPressedSHA"/>
PointerPressed="OnPressedSHA"
PointerEntered="OnSHAPointerEntered"
ToolTip.ShowDelay="0">
<TextBlock.DataTemplates>
<DataTemplate DataType="m:Commit">
<StackPanel MinWidth="400" Orientation="Vertical">
<Grid ColumnDefinitions="Auto,*,Auto">
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" Classes="primary" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
</Grid>
<TextBlock Classes="primary" Margin="0,8,0,0" Text="{Binding Subject}" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</TextBlock.DataTemplates>
</TextBlock>
<TextBlock Margin="4,0,0,0" Text="{Binding Subject}"/>
</StackPanel>
</DataTemplate>

View file

@ -1,7 +1,10 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using Avalonia.Threading;
namespace SourceGit.Views
{
@ -123,6 +126,36 @@ namespace SourceGit.Views
e.Handled = true;
}
private void OnSHAPointerEntered(object sender, PointerEventArgs e)
{
var repoView = this.FindAncestorOfType<Repository>();
if (repoView is { DataContext: ViewModels.Repository repo } && sender is TextBlock text)
{
var commit = repo.GetCommitInfo(text.Text);
if (sender is Control control)
{
var tooltip = ToolTip.GetTip(control);
if (tooltip is Models.Commit tip_commit && tip_commit.SHA == commit.SHA)
return;
Task.Run(() =>
{
Dispatcher.UIThread.Invoke(() =>
{
if (control.IsEffectivelyVisible && control.IsPointerOver)
{
ToolTip.SetTip(control, commit);
ToolTip.SetIsOpen(control, true);
}
});
});
}
}
e.Handled = true;
}
private void OnUnstageSelectedButtonClicked(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.WorkingCopy vm)