Skip to content

Commit b7796f1

Browse files
committed
feature: show a checked icon when sha was copied
Signed-off-by: leo <longshuang@msn.cn>
1 parent c4c75c3 commit b7796f1

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/Views/CommitBaseInfo.axaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@
6262
<TextBlock Text="{Binding SHA}" Margin="12,0,4,0" VerticalAlignment="Center"/>
6363

6464
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnCopyCommitSHA" ToolTip.Tip="{DynamicResource Text.Copy}">
65-
<Path Width="12" Height="12" Data="{StaticResource Icons.Copy}"/>
65+
<Grid>
66+
<Path Width="12" Height="12" Data="{StaticResource Icons.Copy}" IsVisible="{Binding #ThisControl.IsSHACopied, Mode=OneWay, Converter={x:Static BoolConverters.Not}}"/>
67+
<Path Width="14" Height="14" Margin="0,2,0,0" Data="{StaticResource Icons.Check}" Fill="Green" IsVisible="{Binding #ThisControl.IsSHACopied, Mode=OneWay}"/>
68+
</Grid>
6669
</Button>
6770

6871
<Button Classes="icon_button" Width="24" Cursor="Hand" Click="OnOpenContainsIn" IsVisible="{Binding #ThisControl.SupportsContainsIn}" ToolTip.Tip="{DynamicResource Text.CommitDetail.Info.ContainsIn}">

src/Views/CommitBaseInfo.axaml.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Avalonia.Controls;
66
using Avalonia.Input;
77
using Avalonia.Interactivity;
8+
using Avalonia.Threading;
89

910
namespace SourceGit.Views
1011
{
@@ -55,16 +56,51 @@ public List<string> Children
5556
set => SetValue(ChildrenProperty, value);
5657
}
5758

59+
public static readonly StyledProperty<bool> IsSHACopiedProperty =
60+
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(IsSHACopied));
61+
62+
public bool IsSHACopied
63+
{
64+
get => GetValue(IsSHACopiedProperty);
65+
set => SetValue(IsSHACopiedProperty, value);
66+
}
67+
5868
public CommitBaseInfo()
5969
{
6070
InitializeComponent();
6171
}
6272

73+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
74+
{
75+
base.OnPropertyChanged(change);
76+
77+
if (change.Property == ContentProperty)
78+
{
79+
_iconResetTimer?.Dispose();
80+
SetCurrentValue(IsSHACopiedProperty, false);
81+
}
82+
}
83+
84+
protected override void OnUnloaded(RoutedEventArgs e)
85+
{
86+
base.OnUnloaded(e);
87+
_iconResetTimer?.Dispose();
88+
}
89+
6390
private async void OnCopyCommitSHA(object sender, RoutedEventArgs e)
6491
{
6592
if (sender is Button { DataContext: Models.Commit commit })
6693
await this.CopyTextAsync(commit.SHA);
6794

95+
_iconResetTimer = DispatcherTimer.RunOnce(() =>
96+
{
97+
if (IsSHACopied)
98+
IsSHACopied = false;
99+
100+
_iconResetTimer = null;
101+
}, TimeSpan.FromSeconds(3));
102+
103+
IsSHACopied = true;
68104
e.Handled = true;
69105
}
70106

@@ -190,5 +226,7 @@ private async void OnCopyAllCommitMessage(object sender, RoutedEventArgs e)
190226
await this.CopyTextAsync(detail.FullMessage.Message);
191227
e.Handled = true;
192228
}
229+
230+
private IDisposable _iconResetTimer;
193231
}
194232
}

src/Views/CommitTimeTextBlock.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,9 @@ private void StartTimer()
105105

106106
_refreshTimer = DispatcherTimer.Run(() =>
107107
{
108-
Dispatcher.UIThread.Invoke(() =>
109-
{
110-
var text = GetDisplayText();
111-
if (!text.Equals(Text, StringComparison.Ordinal))
112-
Text = text;
113-
});
114-
108+
var text = GetDisplayText();
109+
if (!text.Equals(Text, StringComparison.Ordinal))
110+
Text = text;
115111
return true;
116112
}, TimeSpan.FromSeconds(10));
117113
}

0 commit comments

Comments
 (0)