1+ using System ;
2+ using System . Threading . Tasks ;
13using Avalonia . Controls ;
24using Avalonia . Input ;
35using Avalonia . Interactivity ;
@@ -7,6 +9,9 @@ namespace McpServerManager.Android.Views;
79
810public partial class TabletMainView : UserControl
911{
12+ private const int StatusLongPressThresholdMilliseconds = 600 ;
13+ private DateTimeOffset ? _statusPointerPressedAt ;
14+
1015 public TabletMainView ( )
1116 {
1217 InitializeComponent ( ) ;
@@ -17,11 +22,54 @@ private void StatusMessageText_OnPointerPressed(object? sender, PointerPressedEv
1722 if ( DataContext is not MainWindowViewModel vm || string . IsNullOrWhiteSpace ( vm . StatusMessage ) )
1823 return ;
1924
20- StatusDialogText . Text = vm . StatusMessage ;
21- StatusDialogOverlay . IsVisible = true ;
25+ _statusPointerPressedAt = DateTimeOffset . UtcNow ;
26+ e . Handled = true ;
27+ }
28+
29+ private async void StatusMessageText_OnPointerReleased ( object ? sender , PointerReleasedEventArgs e )
30+ {
31+ if ( DataContext is not MainWindowViewModel vm || string . IsNullOrWhiteSpace ( vm . StatusMessage ) )
32+ {
33+ _statusPointerPressedAt = null ;
34+ return ;
35+ }
36+
37+ var pressedAt = _statusPointerPressedAt ;
38+ _statusPointerPressedAt = null ;
39+ if ( pressedAt is null )
40+ return ;
41+
42+ if ( ( DateTimeOffset . UtcNow - pressedAt . Value ) . TotalMilliseconds >= StatusLongPressThresholdMilliseconds )
43+ {
44+ await CopyStatusToClipboardAsync ( vm . StatusMessage ) ;
45+ e . Handled = true ;
46+ return ;
47+ }
48+
49+ ShowStatusDialog ( vm . StatusMessage ) ;
2250 e . Handled = true ;
2351 }
2452
53+ private void StatusMessageText_OnPointerCaptureLost ( object ? sender , PointerCaptureLostEventArgs e )
54+ {
55+ _statusPointerPressedAt = null ;
56+ }
57+
58+ private async Task CopyStatusToClipboardAsync ( string statusText )
59+ {
60+ var topLevel = TopLevel . GetTopLevel ( this ) ;
61+ if ( topLevel ? . Clipboard is null )
62+ return ;
63+
64+ await topLevel . Clipboard . SetTextAsync ( statusText ) ;
65+ }
66+
67+ private void ShowStatusDialog ( string statusText )
68+ {
69+ StatusDialogText . Text = statusText ;
70+ StatusDialogOverlay . IsVisible = true ;
71+ }
72+
2573 private void CloseStatusDialog_OnClick ( object ? sender , RoutedEventArgs e )
2674 {
2775 StatusDialogOverlay . IsVisible = false ;
0 commit comments