feature: show a checked icon when sha was copied

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-04-13 18:04:08 +08:00
parent c4c75c32c7
commit b7796f19ef
3 changed files with 45 additions and 8 deletions

View File

@@ -62,7 +62,10 @@
<TextBlock Text="{Binding SHA}" Margin="12,0,4,0" VerticalAlignment="Center"/>
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnCopyCommitSHA" ToolTip.Tip="{DynamicResource Text.Copy}">
<Path Width="12" Height="12" Data="{StaticResource Icons.Copy}"/>
<Grid>
<Path Width="12" Height="12" Data="{StaticResource Icons.Copy}" IsVisible="{Binding #ThisControl.IsSHACopied, Mode=OneWay, Converter={x:Static BoolConverters.Not}}"/>
<Path Width="14" Height="14" Margin="0,2,0,0" Data="{StaticResource Icons.Check}" Fill="Green" IsVisible="{Binding #ThisControl.IsSHACopied, Mode=OneWay}"/>
</Grid>
</Button>
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnOpenContainsIn" IsVisible="{Binding #ThisControl.SupportsContainsIn}" ToolTip.Tip="{DynamicResource Text.CommitDetail.Info.ContainsIn}">

View File

@@ -5,6 +5,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Threading;
namespace SourceGit.Views
{
@@ -55,16 +56,51 @@ namespace SourceGit.Views
set => SetValue(ChildrenProperty, value);
}
public static readonly StyledProperty<bool> IsSHACopiedProperty =
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(IsSHACopied));
public bool IsSHACopied
{
get => GetValue(IsSHACopiedProperty);
set => SetValue(IsSHACopiedProperty, value);
}
public CommitBaseInfo()
{
InitializeComponent();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == ContentProperty)
{
_iconResetTimer?.Dispose();
SetCurrentValue(IsSHACopiedProperty, false);
}
}
protected override void OnUnloaded(RoutedEventArgs e)
{
base.OnUnloaded(e);
_iconResetTimer?.Dispose();
}
private async void OnCopyCommitSHA(object sender, RoutedEventArgs e)
{
if (sender is Button { DataContext: Models.Commit commit })
await this.CopyTextAsync(commit.SHA);
_iconResetTimer = DispatcherTimer.RunOnce(() =>
{
if (IsSHACopied)
IsSHACopied = false;
_iconResetTimer = null;
}, TimeSpan.FromSeconds(3));
IsSHACopied = true;
e.Handled = true;
}
@@ -190,5 +226,7 @@ namespace SourceGit.Views
await this.CopyTextAsync(detail.FullMessage.Message);
e.Handled = true;
}
private IDisposable _iconResetTimer;
}
}

View File

@@ -105,13 +105,9 @@ namespace SourceGit.Views
_refreshTimer = DispatcherTimer.Run(() =>
{
Dispatcher.UIThread.Invoke(() =>
{
var text = GetDisplayText();
if (!text.Equals(Text, StringComparison.Ordinal))
Text = text;
});
var text = GetDisplayText();
if (!text.Equals(Text, StringComparison.Ordinal))
Text = text;
return true;
}, TimeSpan.FromSeconds(10));
}