Skip to content

Commit 6e4f971

Browse files
committed
feature: show tooltip of parent commit when hover the parent SHA
Signed-off-by: leo <[email protected]>
1 parent 1f158ee commit 6e4f971

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/ViewModels/CommitDetail.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public void ClearSearchChangeFilter()
169169
SearchChangeFilter = string.Empty;
170170
}
171171

172+
public Models.Commit GetParent(string sha)
173+
{
174+
return new Commands.QuerySingleCommit(_repo.FullPath, sha).Result();
175+
}
176+
172177
public List<Models.Object> GetRevisionFilesUnderFolder(string parentFolder)
173178
{
174179
return new Commands.QueryRevisionObjects(_repo.FullPath, _commit.SHA, parentFolder).Result();

src/Views/CommitBaseInfo.axaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,28 @@
117117
TextDecorations="Underline"
118118
Cursor="Hand"
119119
Margin="0,0,16,0"
120-
PointerPressed="OnSHAPressed"/>
120+
PointerEntered="OnSHAPointerEntered"
121+
PointerPressed="OnSHAPressed">
122+
<TextBlock.Styles>
123+
<Style Selector="ToolTip">
124+
<Setter Property="MaxWidth" Value="800"/>
125+
</Style>
126+
</TextBlock.Styles>
127+
128+
<TextBlock.DataTemplates>
129+
<DataTemplate DataType="m:Commit">
130+
<StackPanel MinWidth="400" Orientation="Vertical">
131+
<Grid ColumnDefinitions="Auto,*,Auto">
132+
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
133+
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
134+
<TextBlock Grid.Column="2" Classes="primary" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
135+
</Grid>
136+
137+
<TextBlock Classes="primary" Margin="0,8,0,0" Text="{Binding Subject}" />
138+
</StackPanel>
139+
</DataTemplate>
140+
</TextBlock.DataTemplates>
141+
</TextBlock>
121142
</DataTemplate>
122143
</ItemsControl.ItemTemplate>
123144
</ItemsControl>

src/Views/CommitBaseInfo.axaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Threading.Tasks;
2+
13
using Avalonia;
24
using Avalonia.Collections;
35
using Avalonia.Controls;
@@ -113,6 +115,29 @@ private void OnOpenContainsIn(object sender, RoutedEventArgs e)
113115
e.Handled = true;
114116
}
115117

118+
private async void OnSHAPointerEntered(object sender, PointerEventArgs e)
119+
{
120+
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha } ctl)
121+
{
122+
var tooltip = ToolTip.GetTip(ctl);
123+
if (tooltip is Models.Commit commit && commit.SHA == sha)
124+
{
125+
ToolTip.SetIsOpen(ctl, true);
126+
}
127+
else
128+
{
129+
var c = await Task.Run(() => detail.GetParent(sha));
130+
if (c != null)
131+
{
132+
ToolTip.SetTip(ctl, c);
133+
ToolTip.SetIsOpen(ctl, true);
134+
}
135+
}
136+
}
137+
138+
e.Handled = true;
139+
}
140+
116141
private void OnSHAPressed(object sender, PointerPressedEventArgs e)
117142
{
118143
if (DataContext is ViewModels.CommitDetail detail && sender is Control { DataContext: string sha })

0 commit comments

Comments
 (0)