mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
code_review: PR #1055
- since the author and time are already shown in the blame view, use the full message as tooltip is better. - cache the commit message in `ViewModels.Blame` since the `Tooltip` of control may change. - querying commit message synchronously (it's very fast) to avoid similar issues in commit details panel. Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
269903503f
commit
fb8d4a2542
3 changed files with 17 additions and 43 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Threading;
|
||||
|
||||
|
@ -57,12 +58,18 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public Models.Commit GetCommitInfo(string commitSHA)
|
||||
public string GetCommitMessage(string sha)
|
||||
{
|
||||
return new Commands.QuerySingleCommit(_repo, commitSHA).Result();
|
||||
if (_commitMessages.TryGetValue(sha, out var msg))
|
||||
return msg;
|
||||
|
||||
msg = new Commands.QueryCommitFullMessage(_repo, sha).Result();
|
||||
_commitMessages[sha] = msg;
|
||||
return msg;
|
||||
}
|
||||
|
||||
private readonly string _repo;
|
||||
private Models.BlameData _data = null;
|
||||
private Dictionary<string, string> _commitMessages = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
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:vm="using:SourceGit.ViewModels"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
|
@ -60,21 +59,7 @@
|
|||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
BlameData="{Binding Data}">
|
||||
<v:BlameTextEditor.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>
|
||||
</v:BlameTextEditor.DataTemplates>
|
||||
</v:BlameTextEditor>
|
||||
BlameData="{Binding Data}"/>
|
||||
|
||||
<!-- Not supported mask (for binary files) -->
|
||||
<StackPanel Orientation="Vertical"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
|
||||
using AvaloniaEdit;
|
||||
using AvaloniaEdit.Document;
|
||||
using AvaloniaEdit.Editing;
|
||||
|
@ -162,8 +162,7 @@ namespace SourceGit.Views
|
|||
break;
|
||||
|
||||
var info = _editor.BlameData.LineInfos[lineNumber - 1];
|
||||
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop)
|
||||
- view.VerticalOffset;
|
||||
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
|
||||
var shaLink = new FormattedText(
|
||||
info.CommitSHA,
|
||||
CultureInfo.CurrentCulture,
|
||||
|
@ -177,28 +176,11 @@ namespace SourceGit.Views
|
|||
{
|
||||
Cursor = Cursor.Parse("Hand");
|
||||
|
||||
// check if the tooltip is already set
|
||||
var tooltip = ToolTip.GetTip(this);
|
||||
if (tooltip is Models.Commit existedCommit && existedCommit.SHA == info.CommitSHA)
|
||||
return;
|
||||
|
||||
if (DataContext is ViewModels.Blame blame)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var commit = blame.GetCommitInfo(info.CommitSHA);
|
||||
if (commit == null)
|
||||
return;
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
if (IsEffectivelyVisible && IsPointerOver)
|
||||
{
|
||||
ToolTip.SetTip(this, commit);
|
||||
ToolTip.SetIsOpen(this, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
var msg = blame.GetCommitMessage(info.CommitSHA);
|
||||
ToolTip.SetTip(this, msg);
|
||||
ToolTip.SetIsOpen(this, true);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue