Skip to content

Commit 6b9c24e

Browse files
committed
ux: show copy feedback icon when copying notification message
1 parent ce07209 commit 6b9c24e

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/Models/Notification.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
using System;
22

3+
using CommunityToolkit.Mvvm.ComponentModel;
4+
35
namespace SourceGit.Models
46
{
5-
public class Notification
7+
public class Notification : ObservableObject
68
{
79
public static event Action<Notification> Raised;
810

911
public string Group { get; set; }
1012
public string Message { get; set; }
1113
public bool IsError { get; set; }
1214

15+
public bool IsCopied
16+
{
17+
get => _isCopied;
18+
set => SetProperty(ref _isCopied, value);
19+
}
20+
1321
public static void Send(string group, string message, bool isError = false)
1422
{
1523
Raised?.Invoke(new Notification
@@ -19,5 +27,7 @@ public static void Send(string group, string message, bool isError = false)
1927
IsError = isError
2028
});
2129
}
30+
31+
private bool _isCopied = false;
2232
}
2333
}

src/Views/LauncherPage.axaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,11 @@
166166
<Path Grid.Column="0" Width="14" Height="14" Data="{StaticResource Icons.Info}" Fill="Green" IsVisible="{Binding !IsError}"/>
167167
<TextBlock Grid.Column="1" Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.Launcher.Error}" IsVisible="{Binding IsError}"/>
168168
<TextBlock Grid.Column="1" Margin="8,0,0,0" FontWeight="Bold" FontSize="14" Text="{DynamicResource Text.Launcher.Info}" IsVisible="{Binding !IsError}"/>
169-
<Button Grid.Column="2" Classes="icon_button" Width="16" Height="16" Click="OnCopyNotification">
170-
<Path Width="12" Height="12" Data="{StaticResource Icons.Copy}"/>
169+
<Button Grid.Column="2" Classes="icon_button" Width="16" Height="16" Click="OnCopyNotification" ToolTip.Tip="{DynamicResource Text.Copy}">
170+
<Grid>
171+
<Path Width="12" Height="12" Data="{StaticResource Icons.Copy}" IsVisible="{Binding IsCopied, Converter={x:Static BoolConverters.Not}}"/>
172+
<Path Width="14" Height="14" Margin="0,1,0,0" Data="{StaticResource Icons.Check}" Fill="Green" IsVisible="{Binding IsCopied}"/>
173+
</Grid>
171174
</Button>
172175
<Button Grid.Column="3" Classes="icon_button" Width="16" Height="16" Margin="8,0,0,0" Click="OnDismissNotification">
173176
<Path Width="10" Height="10" Data="{StaticResource Icons.Close}"/>

src/Views/LauncherPage.axaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
using System;
2+
13
using Avalonia.Controls;
24
using Avalonia.Input;
35
using Avalonia.Interactivity;
46
using Avalonia.LogicalTree;
7+
using Avalonia.Threading;
58
using Avalonia.VisualTree;
69

710
namespace SourceGit.Views
@@ -11,6 +14,19 @@ public partial class LauncherPage : UserControl
1114
public LauncherPage()
1215
{
1316
InitializeComponent();
17+
18+
_copyIconResetTimer = new DispatcherTimer();
19+
_copyIconResetTimer.Interval = TimeSpan.FromSeconds(1);
20+
_copyIconResetTimer.Tick += static (o, _) =>
21+
{
22+
if (o is DispatcherTimer { Tag: Models.Notification notice } timer)
23+
{
24+
notice.IsCopied = false;
25+
timer.Tag = null;
26+
timer.IsEnabled = false;
27+
}
28+
};
29+
_copyIconResetTimer.IsEnabled = false;
1430
}
1531

1632
private async void OnPopupSureByHotKey(object sender, RoutedEventArgs e)
@@ -75,8 +91,15 @@ private void OnMaskClicked(object sender, PointerPressedEventArgs e)
7591
private async void OnCopyNotification(object sender, RoutedEventArgs e)
7692
{
7793
if (sender is Button { DataContext: Models.Notification notice })
94+
{
7895
await this.CopyTextAsync(notice.Message);
7996

97+
_copyIconResetTimer.Stop();
98+
_copyIconResetTimer.Tag = notice;
99+
notice.IsCopied = true;
100+
_copyIconResetTimer.Start();
101+
}
102+
80103
e.Handled = true;
81104
}
82105

@@ -93,5 +116,7 @@ private void OnToolBarPointerPressed(object sender, PointerPressedEventArgs e)
93116
{
94117
this.FindAncestorOfType<ChromelessWindow>()?.BeginMoveWindow(sender, e);
95118
}
119+
120+
private DispatcherTimer _copyIconResetTimer = null;
96121
}
97122
}

0 commit comments

Comments
 (0)