mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34: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;
|
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 readonly string _repo;
|
||||||
private Models.BlameData _data = null;
|
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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:m="using:SourceGit.Models"
|
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
xmlns:v="using:SourceGit.Views"
|
xmlns:v="using:SourceGit.Views"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
@ -60,21 +59,7 @@
|
||||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||||
BlameData="{Binding Data}">
|
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>
|
|
||||||
|
|
||||||
<!-- Not supported mask (for binary files) -->
|
<!-- Not supported mask (for binary files) -->
|
||||||
<StackPanel Orientation="Vertical"
|
<StackPanel Orientation="Vertical"
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Threading;
|
|
||||||
using AvaloniaEdit;
|
using AvaloniaEdit;
|
||||||
using AvaloniaEdit.Document;
|
using AvaloniaEdit.Document;
|
||||||
using AvaloniaEdit.Editing;
|
using AvaloniaEdit.Editing;
|
||||||
|
@ -162,8 +162,7 @@ namespace SourceGit.Views
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var info = _editor.BlameData.LineInfos[lineNumber - 1];
|
var info = _editor.BlameData.LineInfos[lineNumber - 1];
|
||||||
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop)
|
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
|
||||||
- view.VerticalOffset;
|
|
||||||
var shaLink = new FormattedText(
|
var shaLink = new FormattedText(
|
||||||
info.CommitSHA,
|
info.CommitSHA,
|
||||||
CultureInfo.CurrentCulture,
|
CultureInfo.CurrentCulture,
|
||||||
|
@ -177,29 +176,12 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
Cursor = Cursor.Parse("Hand");
|
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)
|
if (DataContext is ViewModels.Blame blame)
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
var msg = blame.GetCommitMessage(info.CommitSHA);
|
||||||
{
|
ToolTip.SetTip(this, msg);
|
||||||
var commit = blame.GetCommitInfo(info.CommitSHA);
|
|
||||||
if (commit == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
|
||||||
{
|
|
||||||
if (IsEffectivelyVisible && IsPointerOver)
|
|
||||||
{
|
|
||||||
ToolTip.SetTip(this, commit);
|
|
||||||
ToolTip.SetIsOpen(this, true);
|
ToolTip.SetIsOpen(this, true);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue