From 779f062e35e2664a30d89ae76019c90de9344dfa Mon Sep 17 00:00:00 2001 From: JC-Chung <52159296+JC-Chung@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:00:57 +0800 Subject: [PATCH 1/3] enhance: extract reusable CopyButton control with copy feedback --- src/Views/CommitBaseInfo.axaml | 7 +- src/Views/CommitBaseInfo.axaml.cs | 63 --------------- src/Views/CopyButton.cs | 124 ++++++++++++++++++++++++++++++ src/Views/LauncherPage.axaml | 4 +- src/Views/LauncherPage.axaml.cs | 8 -- 5 files changed, 126 insertions(+), 80 deletions(-) create mode 100644 src/Views/CopyButton.cs diff --git a/src/Views/CommitBaseInfo.axaml b/src/Views/CommitBaseInfo.axaml index d848203cab..c8544db7f6 100644 --- a/src/Views/CommitBaseInfo.axaml +++ b/src/Views/CommitBaseInfo.axaml @@ -65,12 +65,7 @@ - + + diff --git a/src/Views/LauncherPage.axaml.cs b/src/Views/LauncherPage.axaml.cs index 88270a5ad3..8981a86c29 100644 --- a/src/Views/LauncherPage.axaml.cs +++ b/src/Views/LauncherPage.axaml.cs @@ -72,14 +72,6 @@ private void OnMaskClicked(object sender, PointerPressedEventArgs e) OnPopupCancel(sender, e); } - private async void OnCopyNotification(object sender, RoutedEventArgs e) - { - if (sender is Button { DataContext: Models.Notification notice }) - await this.CopyTextAsync(notice.Message); - - e.Handled = true; - } - private void OnDismissNotification(object sender, RoutedEventArgs e) { if (sender is Button { DataContext: Models.Notification notice } && From 5f464fb16c2bdb1dadca917c0e213d5bd136bc41 Mon Sep 17 00:00:00 2001 From: JC-Chung <52159296+JC-Chung@users.noreply.github.com> Date: Tue, 1 Sep 2026 12:28:38 +0800 Subject: [PATCH 2/3] fix: `CopyButton` should not show copied feedback when `CopyText` is empty --- src/Views/CopyButton.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Views/CopyButton.cs b/src/Views/CopyButton.cs index 996bcfb57d..9922005c2f 100644 --- a/src/Views/CopyButton.cs +++ b/src/Views/CopyButton.cs @@ -78,12 +78,8 @@ protected override void OnLoaded(RoutedEventArgs e) protected override void OnUnloaded(RoutedEventArgs e) { - if (_resetTimer != null) - { - _resetTimer.Tag = null; - _resetTimer.IsEnabled = false; - } - + _resetTimer.Tag = null; + _resetTimer.IsEnabled = false; base.OnUnloaded(e); } @@ -109,9 +105,10 @@ protected override async void OnClick() base.OnClick(); var text = CopyText; - if (!string.IsNullOrEmpty(text)) - await this.CopyTextAsync(text); + if (string.IsNullOrEmpty(text)) + return; + await this.CopyTextAsync(text); IsCopied = true; _resetTimer?.Start(); } From 3ec0672cc75252a6016ba2fde5ffe415580b974b Mon Sep 17 00:00:00 2001 From: JC-Chung <52159296+JC-Chung@users.noreply.github.com> Date: Tue, 1 Sep 2026 12:29:33 +0800 Subject: [PATCH 3/3] code_style: use `DirectProperty` for `CopyText` in `CopyButton` --- src/Views/CopyButton.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Views/CopyButton.cs b/src/Views/CopyButton.cs index 9922005c2f..0ce7908491 100644 --- a/src/Views/CopyButton.cs +++ b/src/Views/CopyButton.cs @@ -13,13 +13,16 @@ public class CopyButton : Button { protected override Type StyleKeyOverride => typeof(Button); - public static readonly StyledProperty CopyTextProperty = - AvaloniaProperty.Register(nameof(CopyText), string.Empty); + public static readonly DirectProperty CopyTextProperty = + AvaloniaProperty.RegisterDirect( + nameof(CopyText), + static o => o.CopyText, + static (o, v) => o.CopyText = v); public string CopyText { - get => GetValue(CopyTextProperty); - set => SetValue(CopyTextProperty, value); + get => _copyText; + set => SetAndRaise(CopyTextProperty, ref _copyText, value); } public static readonly DirectProperty IsCopiedProperty = @@ -115,6 +118,7 @@ protected override async void OnClick() private readonly Path _copyIcon; private readonly Path _checkIcon; + private string _copyText = string.Empty; private bool _isCopied = false; private DispatcherTimer _resetTimer = null; }