diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index 7af9d59b..67c1c7b6 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -62,7 +62,10 @@ - + + + + diff --git a/src/Views/CommitBaseInfo.axaml.cs b/src/Views/CommitBaseInfo.axaml.cs index 63395235..d827fbe7 100644 --- a/src/Views/CommitBaseInfo.axaml.cs +++ b/src/Views/CommitBaseInfo.axaml.cs @@ -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 IsSHACopiedProperty = + AvaloniaProperty.Register(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; } } diff --git a/src/Views/CommitTimeTextBlock.cs b/src/Views/CommitTimeTextBlock.cs index 0e32e3aa..dcd0dd28 100644 --- a/src/Views/CommitTimeTextBlock.cs +++ b/src/Views/CommitTimeTextBlock.cs @@ -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)); }