From 3ce06cc6b5133a5ecdd6b61eba0ca3f72d35de26 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 3 Oct 2024 19:01:49 +0800 Subject: [PATCH] ux: add tooltip for change status icon (#537) --- src/Views/ChangeStatusIcon.cs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Views/ChangeStatusIcon.cs b/src/Views/ChangeStatusIcon.cs index 06508638..d11a504a 100644 --- a/src/Views/ChangeStatusIcon.cs +++ b/src/Views/ChangeStatusIcon.cs @@ -62,6 +62,7 @@ namespace SourceGit.Views ]; private static readonly string[] INDICATOR = ["?", "±", "T", "+", "−", "➜", "❏", "U", "★"]; + private static readonly string[] TIPS = ["Unknown", "Modified", "Type Changed", "Added", "Deleted", "Renamed", "Copied", "Unmerged", "Untracked" ]; public static readonly StyledProperty IsUnstagedChangeProperty = AvaloniaProperty.Register(nameof(IsUnstagedChange)); @@ -81,11 +82,6 @@ namespace SourceGit.Views set => SetValue(ChangeProperty, value); } - static ChangeStatusIcon() - { - AffectsRender(IsUnstagedChangeProperty, ChangeProperty); - } - public override void Render(DrawingContext context) { if (Change == null || Bounds.Width <= 0) @@ -122,10 +118,33 @@ namespace SourceGit.Views Bounds.Width * 0.8, Brushes.White); - float corner = (float)Math.Max(2, Bounds.Width / 16); - Point textOrigin = new Point((Bounds.Width - txt.Width) * 0.5, (Bounds.Height - txt.Height) * 0.5); + var corner = (float)Math.Max(2, Bounds.Width / 16); + var textOrigin = new Point((Bounds.Width - txt.Width) * 0.5, (Bounds.Height - txt.Height) * 0.5); context.DrawRectangle(background, null, new Rect(0, 0, Bounds.Width, Bounds.Height), corner, corner); context.DrawText(txt, textOrigin); } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == IsUnstagedChangeProperty || change.Property == ChangeProperty) + { + var isUnstaged = IsUnstagedChange; + var c = Change; + if (c == null) + { + ToolTip.SetTip(this, null); + return; + } + + if (isUnstaged) + ToolTip.SetTip(this, c.IsConflit ? "Conflict" : TIPS[(int)c.WorkTree]); + else + ToolTip.SetTip(this, TIPS[(int)c.Index]); + + InvalidateVisual(); + } + } } }