Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion src/Views/CommitSubjectPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,36 @@
using System.Collections.Specialized;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;

namespace SourceGit.Views
{
public partial class CommitSubjectPresenter : Control
{
public static readonly StyledProperty<string> FullMessageProperty =
AvaloniaProperty.Register<CommitSubjectPresenter, string>(nameof(FullMessage));

public string FullMessage
{
get => GetValue(FullMessageProperty);
set => SetValue(FullMessageProperty, value);
}

public CommitSubjectPresenter()
{
ToolTip.SetShowDelay(this, 1000);
ToolTip.SetBetweenShowDelay(this, -1);
ToolTip.AddToolTipOpeningHandler(this, OnToolTipOpening);
}

public static readonly StyledProperty<FontFamily> FontFamilyProperty =
AvaloniaProperty.Register<CommitSubjectPresenter, FontFamily>(nameof(FontFamily));

Expand Down Expand Up @@ -175,6 +194,11 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
_needRebuildInlines = true;
GenerateInlineElements();
InvalidateVisual();
UpdateMessageToolTip();
}
else if (change.Property == FullMessageProperty)
{
UpdateMessageToolTip();
}
else if (change.Property == IssueTrackersProperty)
{
Expand Down Expand Up @@ -239,6 +263,45 @@ protected override void OnPointerExited(PointerEventArgs e)
ClearHoveredIssueLink();
}

protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);

ToolTip.SetIsOpen(this, false);
_fullMessageTask = null;
ClearHoveredIssueLink();
UpdateMessageToolTip();
}

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
ToolTip.SetIsOpen(this, false);
ClearHoveredIssueLink();
base.OnDetachedFromVisualTree(e);
}

private async void OnToolTipOpening(object sender, CancelRoutedEventArgs e)
{
if (e.Cancel || _lastHover != null || !string.IsNullOrEmpty(FullMessage))
return;

if (DataContext is not Models.Commit commit ||
this.FindAncestorOfType<Histories>()?.DataContext is not ViewModels.Histories histories)
return;

var task = _fullMessageTask ??= histories.GetCommitFullMessageAsync(commit);
var message = await task;
if (_fullMessageTask == task && !string.IsNullOrEmpty(message))
_messageToolTip.Text = message;
}

private void UpdateMessageToolTip()
{
_messageToolTip.Text = string.IsNullOrEmpty(FullMessage) ? Subject : FullMessage;
if (_lastHover == null)
ToolTip.SetTip(this, string.IsNullOrEmpty(Subject) ? null : _messageToolTip);
}

private void OnIssueTrackersChanged(object sender, NotifyCollectionChangedEventArgs e)
{
_needRebuildInlines = true;
Expand Down Expand Up @@ -401,10 +464,12 @@ private void ClearHoveredIssueLink()
{
if (_lastHover != null)
{
ToolTip.SetTip(this, null);
SetCurrentValue(CursorProperty, Cursor.Parse("Arrow"));
_lastHover = null;
}

if (!ReferenceEquals(ToolTip.GetTip(this), _messageToolTip))
UpdateMessageToolTip();
}

[GeneratedRegex(@"`.*?`")]
Expand All @@ -425,6 +490,8 @@ public Inline(double x, FormattedText text, Models.InlineElement elem)
}

private string _subject = string.Empty;
private readonly TextBlock _messageToolTip = new() { MaxWidth = 640, TextWrapping = TextWrapping.Wrap };
private Task<string> _fullMessageTask = null;
private AvaloniaList<Models.IssueTracker> _issueTrackers = null;
private Models.InlineElementCollector _elements = new();
private Models.InlineElement _lastHover = null;
Expand Down
1 change: 1 addition & 0 deletions src/Views/InteractiveRebase.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
Foreground="{DynamicResource Brush.FG1}"
LinkForeground="{DynamicResource Brush.Link}"
Subject="{Binding Subject}"
FullMessage="{Binding FullMessage}"
IssueTrackers="{Binding $parent[v:InteractiveRebase].((vm:InteractiveRebase)DataContext).IssueTrackers}"
FontWeight="Normal"
Opacity="{Binding Action, Mode=OneWay, Converter={x:Static c:InteractiveRebaseActionConverters.ToOpacity}}"
Expand Down